@helia/interop 8.2.0 → 8.3.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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=providers.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.spec.d.ts","sourceRoot":"","sources":["../../src/providers.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,192 @@
1
+ /* eslint-env mocha */
2
+ import { car } from '@helia/car';
3
+ import { dagCbor } from '@helia/dag-cbor';
4
+ import { dagJson } from '@helia/dag-json';
5
+ import { mfs } from '@helia/mfs';
6
+ import { strings } from '@helia/strings';
7
+ import { unixfs } from '@helia/unixfs';
8
+ import { peerIdFromString } from '@libp2p/peer-id';
9
+ import { createScalableCuckooFilter } from '@libp2p/utils/filters';
10
+ import { expect } from 'aegir/chai';
11
+ import toBuffer from 'it-to-buffer';
12
+ import { multiaddr } from 'kubo-rpc-client';
13
+ import { CID } from 'multiformats/cid';
14
+ import { createHeliaNode } from './fixtures/create-helia.js';
15
+ import { createKuboNode } from './fixtures/create-kubo.js';
16
+ describe('providers', () => {
17
+ let helia;
18
+ let kubo;
19
+ let cid;
20
+ let kuboInfo;
21
+ let input;
22
+ beforeEach(async () => {
23
+ // helia and kubo are not connected together before the test
24
+ helia = await createHeliaNode();
25
+ kubo = await createKuboNode();
26
+ const chunkSize = 1024 * 1024;
27
+ const size = chunkSize * 10;
28
+ input = [];
29
+ const candidate = {
30
+ content: (async function* () {
31
+ for (let i = 0; i < size; i += chunkSize) {
32
+ const buf = new Uint8Array(chunkSize);
33
+ input.push(buf);
34
+ yield buf;
35
+ }
36
+ }())
37
+ };
38
+ const importResult = await kubo.api.add(candidate.content);
39
+ cid = CID.parse(importResult.cid.toString());
40
+ kuboInfo = await kubo.info();
41
+ });
42
+ afterEach(async () => {
43
+ if (helia != null) {
44
+ await helia.stop();
45
+ }
46
+ if (kubo != null) {
47
+ await kubo.stop();
48
+ }
49
+ });
50
+ it('should fail to fetch without using a provider', async () => {
51
+ await expect(helia.blockstore.get(cid, {
52
+ signal: AbortSignal.timeout(100)
53
+ })).to.eventually.be.rejected()
54
+ .with.nested.property('errors[0].name', 'AbortError');
55
+ });
56
+ it('should fetch raw using a provider', async () => {
57
+ let sender;
58
+ const buf = await helia.blockstore.get(cid, {
59
+ providers: [
60
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
61
+ ],
62
+ onProgress(evt) {
63
+ // @ts-expect-error cannot derive config-based progress event types
64
+ if (evt.type === 'bitswap:want-block:received') {
65
+ // @ts-expect-error cannot derive config-based progress event types
66
+ sender = evt.detail.sender;
67
+ }
68
+ }
69
+ });
70
+ expect(buf).to.have.lengthOf(1930);
71
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''));
72
+ });
73
+ it('should fetch dag-cbor using a provider', async () => {
74
+ let sender;
75
+ const obj = { hello: 'world' };
76
+ const cid = await kubo.api.dag.put(obj, {
77
+ storeCodec: 'dag-cbor'
78
+ });
79
+ const d = dagCbor(helia);
80
+ await expect(d.get(cid, {
81
+ providers: [
82
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
83
+ ],
84
+ onProgress(evt) {
85
+ // @ts-expect-error cannot derive config-based progress event types
86
+ if (evt.type === 'bitswap:want-block:received') {
87
+ // @ts-expect-error cannot derive config-based progress event types
88
+ sender = evt.detail.sender;
89
+ }
90
+ }
91
+ })).to.eventually.deep.equal(obj);
92
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''));
93
+ });
94
+ it('should fetch dag-json using a provider', async () => {
95
+ let sender;
96
+ const obj = { hello: 'world' };
97
+ const cid = await kubo.api.dag.put(obj, {
98
+ storeCodec: 'dag-json'
99
+ });
100
+ const d = dagJson(helia);
101
+ await expect(d.get(cid, {
102
+ providers: [
103
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
104
+ ],
105
+ onProgress(evt) {
106
+ // @ts-expect-error cannot derive config-based progress event types
107
+ if (evt.type === 'bitswap:want-block:received') {
108
+ // @ts-expect-error cannot derive config-based progress event types
109
+ sender = evt.detail.sender;
110
+ }
111
+ }
112
+ })).to.eventually.deep.equal(obj);
113
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''));
114
+ });
115
+ it('should fetch string using a provider', async () => {
116
+ let sender;
117
+ const obj = 'hello world';
118
+ const cid = await kubo.api.dag.put(obj, {
119
+ storeCodec: 'dag-json'
120
+ });
121
+ const s = strings(helia);
122
+ await expect(s.get(cid, {
123
+ providers: [
124
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
125
+ ],
126
+ onProgress(evt) {
127
+ // @ts-expect-error cannot derive config-based progress event types
128
+ if (evt.type === 'bitswap:want-block:received') {
129
+ // @ts-expect-error cannot derive config-based progress event types
130
+ sender = evt.detail.sender;
131
+ }
132
+ }
133
+ })).to.eventually.equal(JSON.stringify(obj));
134
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''));
135
+ });
136
+ it('should fetch via unixfs using a provider', async () => {
137
+ let sender;
138
+ const fs = unixfs(helia);
139
+ const bytes = await toBuffer(fs.cat(cid, {
140
+ providers: [
141
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
142
+ ],
143
+ onProgress(evt) {
144
+ // @ts-expect-error cannot derive config-based progress event types
145
+ if (evt.type === 'bitswap:want-block:received') {
146
+ // @ts-expect-error cannot derive config-based progress event types
147
+ sender = evt.detail.sender;
148
+ }
149
+ }
150
+ }));
151
+ expect(bytes).to.equalBytes(toBuffer(input));
152
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''));
153
+ });
154
+ it('should fetch via mfs using a provider', async () => {
155
+ let sender;
156
+ const fs = mfs(helia);
157
+ await fs.cp(cid, '/file.txt', {
158
+ providers: [
159
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
160
+ ],
161
+ onProgress(evt) {
162
+ // @ts-expect-error cannot derive config-based progress event types
163
+ if (evt.type === 'bitswap:want-block:received') {
164
+ // @ts-expect-error cannot derive config-based progress event types
165
+ sender = evt.detail.sender;
166
+ }
167
+ }
168
+ });
169
+ const bytes = await toBuffer(fs.cat('/file.txt'));
170
+ expect(bytes).to.equalBytes(toBuffer(input));
171
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''));
172
+ });
173
+ it('should fetch via car using a provider', async () => {
174
+ let sender;
175
+ const c = car(helia);
176
+ expect(await toBuffer(c.stream(cid, {
177
+ providers: [
178
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
179
+ ],
180
+ blockFilter: createScalableCuckooFilter(10),
181
+ onProgress(evt) {
182
+ // @ts-expect-error cannot derive config-based progress event types
183
+ if (evt.type === 'bitswap:want-block:received') {
184
+ // @ts-expect-error cannot derive config-based progress event types
185
+ sender = evt.detail.sender;
186
+ }
187
+ }
188
+ }))).to.equalBytes(await toBuffer(kubo.api.dag.export(cid)));
189
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''));
190
+ });
191
+ });
192
+ //# sourceMappingURL=providers.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.spec.js","sourceRoot":"","sources":["../../src/providers.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,0BAA0B,EAAE,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EAAE;QACrD,IAAI,MAA0B,CAAA;QAC9B,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;QAEpB,MAAM,CAAC,MAAM,QAAQ,CACnB,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE;YACZ,SAAS,EAAE;gBACT,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;aAC7C;YACD,WAAW,EAAE,0BAA0B,CAAC,EAAE,CAAC;YAC3C,UAAU,CAAE,GAAG;gBACb,mEAAmE;gBACnE,IAAI,GAAG,CAAC,IAAI,KAAK,6BAA6B,EAAE,CAAC;oBAC/C,mEAAmE;oBACnE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAA;gBAC5B,CAAC;YACH,CAAC;SACF,CAAC,CAAC,CACJ,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,QAAQ,CAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CACzB,CAAC,CAAA;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACnF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interop",
3
- "version": "8.2.0",
3
+ "version": "8.3.0",
4
4
  "description": "Interop tests for Helia",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/interop#readme",
@@ -59,18 +59,18 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@chainsafe/libp2p-gossipsub": "^14.1.0",
62
- "@helia/block-brokers": "^4.2.3",
63
- "@helia/car": "^4.1.3",
64
- "@helia/dag-cbor": "^4.0.7",
65
- "@helia/dag-json": "^4.0.7",
66
- "@helia/http": "^2.2.0",
62
+ "@helia/block-brokers": "^4.2.4",
63
+ "@helia/car": "^4.2.0",
64
+ "@helia/dag-cbor": "^4.1.0",
65
+ "@helia/dag-json": "^4.1.0",
66
+ "@helia/http": "^2.2.1",
67
67
  "@helia/interface": "^5.4.0",
68
68
  "@helia/ipns": "^8.2.4",
69
69
  "@helia/json": "^4.0.7",
70
- "@helia/mfs": "^5.0.4",
70
+ "@helia/mfs": "^5.1.0",
71
71
  "@helia/routers": "^3.1.3",
72
- "@helia/strings": "^4.0.7",
73
- "@helia/unixfs": "^5.0.4",
72
+ "@helia/strings": "^4.1.0",
73
+ "@helia/unixfs": "^5.1.0",
74
74
  "@ipld/car": "^5.3.3",
75
75
  "@ipld/dag-cbor": "^9.2.2",
76
76
  "@ipld/dag-pb": "^4.1.3",
@@ -79,11 +79,12 @@
79
79
  "@libp2p/kad-dht": "^15.0.2",
80
80
  "@libp2p/keychain": "^5.0.10",
81
81
  "@libp2p/peer-id": "^5.0.8",
82
+ "@libp2p/utils": "^6.7.1",
82
83
  "@libp2p/websockets": "^9.0.13",
83
84
  "@multiformats/multiaddr": "^12.4.0",
84
85
  "@multiformats/sha3": "^3.0.2",
85
86
  "aegir": "^47.0.7",
86
- "helia": "^5.5.0",
87
+ "helia": "^5.5.1",
87
88
  "ipfs-unixfs-importer": "^15.3.1",
88
89
  "ipfsd-ctl": "^15.0.2",
89
90
  "ipns": "^10.0.0",
@@ -0,0 +1,230 @@
1
+ /* eslint-env mocha */
2
+
3
+ import { car } from '@helia/car'
4
+ import { dagCbor } from '@helia/dag-cbor'
5
+ import { dagJson } from '@helia/dag-json'
6
+ import { mfs } from '@helia/mfs'
7
+ import { strings } from '@helia/strings'
8
+ import { unixfs } from '@helia/unixfs'
9
+ import { peerIdFromString } from '@libp2p/peer-id'
10
+ import { createScalableCuckooFilter } from '@libp2p/utils/filters'
11
+ import { expect } from 'aegir/chai'
12
+ import toBuffer from 'it-to-buffer'
13
+ import { multiaddr } from 'kubo-rpc-client'
14
+ import { CID } from 'multiformats/cid'
15
+ import { createHeliaNode } from './fixtures/create-helia.js'
16
+ import { createKuboNode } from './fixtures/create-kubo.js'
17
+ import type { PeerId } from '@libp2p/interface'
18
+ import type { Helia } from 'helia'
19
+ import type { FileCandidate } from 'ipfs-unixfs-importer'
20
+ import type { KuboInfo, KuboNode } from 'ipfsd-ctl'
21
+
22
+ describe('providers', () => {
23
+ let helia: Helia
24
+ let kubo: KuboNode
25
+ let cid: CID
26
+ let kuboInfo: KuboInfo
27
+ let input: Uint8Array[]
28
+
29
+ beforeEach(async () => {
30
+ // helia and kubo are not connected together before the test
31
+ helia = await createHeliaNode()
32
+ kubo = await createKuboNode()
33
+
34
+ const chunkSize = 1024 * 1024
35
+ const size = chunkSize * 10
36
+ input = []
37
+
38
+ const candidate: FileCandidate = {
39
+ content: (async function * () {
40
+ for (let i = 0; i < size; i += chunkSize) {
41
+ const buf = new Uint8Array(chunkSize)
42
+ input.push(buf)
43
+
44
+ yield buf
45
+ }
46
+ }())
47
+ }
48
+
49
+ const importResult = await kubo.api.add(candidate.content)
50
+ cid = CID.parse(importResult.cid.toString())
51
+ kuboInfo = await kubo.info()
52
+ })
53
+
54
+ afterEach(async () => {
55
+ if (helia != null) {
56
+ await helia.stop()
57
+ }
58
+
59
+ if (kubo != null) {
60
+ await kubo.stop()
61
+ }
62
+ })
63
+
64
+ it('should fail to fetch without using a provider', async () => {
65
+ await expect(helia.blockstore.get(cid, {
66
+ signal: AbortSignal.timeout(100)
67
+ })).to.eventually.be.rejected()
68
+ .with.nested.property('errors[0].name', 'AbortError')
69
+ })
70
+
71
+ it('should fetch raw using a provider', async () => {
72
+ let sender: PeerId | undefined
73
+
74
+ const buf = await helia.blockstore.get(cid, {
75
+ providers: [
76
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
77
+ ],
78
+ onProgress (evt) {
79
+ // @ts-expect-error cannot derive config-based progress event types
80
+ if (evt.type === 'bitswap:want-block:received') {
81
+ // @ts-expect-error cannot derive config-based progress event types
82
+ sender = evt.detail.sender
83
+ }
84
+ }
85
+ })
86
+
87
+ expect(buf).to.have.lengthOf(1930)
88
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
89
+ })
90
+
91
+ it('should fetch dag-cbor using a provider', async () => {
92
+ let sender: PeerId | undefined
93
+ const obj = { hello: 'world' }
94
+ const cid = await kubo.api.dag.put(obj, {
95
+ storeCodec: 'dag-cbor'
96
+ })
97
+
98
+ const d = dagCbor(helia)
99
+
100
+ await expect(d.get(cid, {
101
+ providers: [
102
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
103
+ ],
104
+ onProgress (evt) {
105
+ // @ts-expect-error cannot derive config-based progress event types
106
+ if (evt.type === 'bitswap:want-block:received') {
107
+ // @ts-expect-error cannot derive config-based progress event types
108
+ sender = evt.detail.sender
109
+ }
110
+ }
111
+ })).to.eventually.deep.equal(obj)
112
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
113
+ })
114
+
115
+ it('should fetch dag-json using a provider', async () => {
116
+ let sender: PeerId | undefined
117
+ const obj = { hello: 'world' }
118
+ const cid = await kubo.api.dag.put(obj, {
119
+ storeCodec: 'dag-json'
120
+ })
121
+
122
+ const d = dagJson(helia)
123
+
124
+ await expect(d.get(cid, {
125
+ providers: [
126
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
127
+ ],
128
+ onProgress (evt) {
129
+ // @ts-expect-error cannot derive config-based progress event types
130
+ if (evt.type === 'bitswap:want-block:received') {
131
+ // @ts-expect-error cannot derive config-based progress event types
132
+ sender = evt.detail.sender
133
+ }
134
+ }
135
+ })).to.eventually.deep.equal(obj)
136
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
137
+ })
138
+
139
+ it('should fetch string using a provider', async () => {
140
+ let sender: PeerId | undefined
141
+ const obj = 'hello world'
142
+ const cid = await kubo.api.dag.put(obj, {
143
+ storeCodec: 'dag-json'
144
+ })
145
+
146
+ const s = strings(helia)
147
+
148
+ await expect(s.get(cid, {
149
+ providers: [
150
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
151
+ ],
152
+ onProgress (evt) {
153
+ // @ts-expect-error cannot derive config-based progress event types
154
+ if (evt.type === 'bitswap:want-block:received') {
155
+ // @ts-expect-error cannot derive config-based progress event types
156
+ sender = evt.detail.sender
157
+ }
158
+ }
159
+ })).to.eventually.equal(JSON.stringify(obj))
160
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
161
+ })
162
+
163
+ it('should fetch via unixfs using a provider', async () => {
164
+ let sender: PeerId | undefined
165
+ const fs = unixfs(helia)
166
+
167
+ const bytes = await toBuffer(fs.cat(cid, {
168
+ providers: [
169
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
170
+ ],
171
+ onProgress (evt) {
172
+ // @ts-expect-error cannot derive config-based progress event types
173
+ if (evt.type === 'bitswap:want-block:received') {
174
+ // @ts-expect-error cannot derive config-based progress event types
175
+ sender = evt.detail.sender
176
+ }
177
+ }
178
+ }))
179
+
180
+ expect(bytes).to.equalBytes(toBuffer(input))
181
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
182
+ })
183
+
184
+ it('should fetch via mfs using a provider', async () => {
185
+ let sender: PeerId | undefined
186
+ const fs = mfs(helia)
187
+
188
+ await fs.cp(cid, '/file.txt', {
189
+ providers: [
190
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
191
+ ],
192
+ onProgress (evt) {
193
+ // @ts-expect-error cannot derive config-based progress event types
194
+ if (evt.type === 'bitswap:want-block:received') {
195
+ // @ts-expect-error cannot derive config-based progress event types
196
+ sender = evt.detail.sender
197
+ }
198
+ }
199
+ })
200
+
201
+ const bytes = await toBuffer(fs.cat('/file.txt'))
202
+
203
+ expect(bytes).to.equalBytes(toBuffer(input))
204
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
205
+ })
206
+
207
+ it('should fetch via car using a provider', async () => {
208
+ let sender: PeerId | undefined
209
+ const c = car(helia)
210
+
211
+ expect(await toBuffer(
212
+ c.stream(cid, {
213
+ providers: [
214
+ kuboInfo.multiaddrs.map(ma => multiaddr(ma))
215
+ ],
216
+ blockFilter: createScalableCuckooFilter(10),
217
+ onProgress (evt) {
218
+ // @ts-expect-error cannot derive config-based progress event types
219
+ if (evt.type === 'bitswap:want-block:received') {
220
+ // @ts-expect-error cannot derive config-based progress event types
221
+ sender = evt.detail.sender
222
+ }
223
+ }
224
+ }))
225
+ ).to.equalBytes(await toBuffer(
226
+ kubo.api.dag.export(cid)
227
+ ))
228
+ expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
229
+ })
230
+ })