@helia/interop 3.0.0 → 3.0.1-19bf9ce
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/.aegir.js +46 -0
- package/README.md +11 -0
- package/dist/src/bin.d.ts +3 -0
- package/dist/src/bin.d.ts.map +1 -0
- package/dist/src/bin.js +20 -0
- package/dist/src/bin.js.map +1 -0
- package/dist/src/car.spec.d.ts +2 -0
- package/dist/src/car.spec.d.ts.map +1 -0
- package/dist/src/car.spec.js +77 -0
- package/dist/src/car.spec.js.map +1 -0
- package/dist/src/dag-cbor.spec.d.ts +2 -0
- package/dist/src/dag-cbor.spec.d.ts.map +1 -0
- package/dist/src/dag-cbor.spec.js +49 -0
- package/dist/src/dag-cbor.spec.js.map +1 -0
- package/dist/src/dag-json.spec.d.ts +2 -0
- package/dist/src/dag-json.spec.d.ts.map +1 -0
- package/dist/src/dag-json.spec.js +49 -0
- package/dist/src/dag-json.spec.js.map +1 -0
- package/dist/src/fixtures/connect.d.ts +7 -0
- package/dist/src/fixtures/connect.d.ts.map +1 -0
- package/dist/src/fixtures/connect.js +17 -0
- package/dist/src/fixtures/connect.js.map +1 -0
- package/dist/src/fixtures/create-helia.browser.d.ts +4 -0
- package/dist/src/fixtures/create-helia.browser.d.ts.map +1 -0
- package/dist/src/fixtures/create-helia.browser.js +55 -0
- package/dist/src/fixtures/create-helia.browser.js.map +1 -0
- package/dist/src/fixtures/create-helia.d.ts +4 -0
- package/dist/src/fixtures/create-helia.d.ts.map +1 -0
- package/dist/src/fixtures/create-helia.js +45 -0
- package/dist/src/fixtures/create-helia.js.map +1 -0
- package/dist/src/fixtures/create-kubo.browser.d.ts +3 -0
- package/dist/src/fixtures/create-kubo.browser.d.ts.map +1 -0
- package/dist/src/fixtures/create-kubo.browser.js +21 -0
- package/dist/src/fixtures/create-kubo.browser.js.map +1 -0
- package/dist/src/fixtures/create-kubo.d.ts +3 -0
- package/dist/src/fixtures/create-kubo.d.ts.map +1 -0
- package/dist/src/fixtures/create-kubo.js +23 -0
- package/dist/src/fixtures/create-kubo.js.map +1 -0
- package/dist/src/fixtures/create-peer-ids.d.ts +14 -0
- package/dist/src/fixtures/create-peer-ids.d.ts.map +1 -0
- package/dist/src/fixtures/create-peer-ids.js +37 -0
- package/dist/src/fixtures/create-peer-ids.js.map +1 -0
- package/dist/src/fixtures/key-types.d.ts +3 -0
- package/dist/src/fixtures/key-types.d.ts.map +1 -0
- package/dist/src/fixtures/key-types.js +6 -0
- package/dist/src/fixtures/key-types.js.map +1 -0
- package/dist/src/fixtures/memory-car.d.ts +7 -0
- package/dist/src/fixtures/memory-car.d.ts.map +1 -0
- package/dist/src/fixtures/memory-car.js +26 -0
- package/dist/src/fixtures/memory-car.js.map +1 -0
- package/dist/src/fixtures/wait-for.d.ts +7 -0
- package/dist/src/fixtures/wait-for.d.ts.map +1 -0
- package/dist/src/fixtures/wait-for.js +17 -0
- package/dist/src/fixtures/wait-for.js.map +1 -0
- package/dist/src/helia-blockstore.spec.d.ts +2 -0
- package/dist/src/helia-blockstore.spec.d.ts.map +1 -0
- package/dist/src/helia-blockstore.spec.js +48 -0
- package/dist/src/helia-blockstore.spec.js.map +1 -0
- package/dist/src/helia-hashes.spec.d.ts +2 -0
- package/dist/src/helia-hashes.spec.d.ts.map +1 -0
- package/dist/src/helia-hashes.spec.js +50 -0
- package/dist/src/helia-hashes.spec.js.map +1 -0
- package/dist/src/helia-pins.spec.d.ts +2 -0
- package/dist/src/helia-pins.spec.d.ts.map +1 -0
- package/dist/src/helia-pins.spec.js +48 -0
- package/dist/src/helia-pins.spec.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/ipns-pubsub.spec.d.ts +2 -0
- package/dist/src/ipns-pubsub.spec.d.ts.map +1 -0
- package/dist/src/ipns-pubsub.spec.js +146 -0
- package/dist/src/ipns-pubsub.spec.js.map +1 -0
- package/dist/src/ipns.spec.d.ts +2 -0
- package/dist/src/ipns.spec.d.ts.map +1 -0
- package/dist/src/ipns.spec.js +146 -0
- package/dist/src/ipns.spec.js.map +1 -0
- package/dist/src/json.spec.d.ts +2 -0
- package/dist/src/json.spec.d.ts.map +1 -0
- package/dist/src/json.spec.js +49 -0
- package/dist/src/json.spec.js.map +1 -0
- package/dist/src/mfs.spec.d.ts +2 -0
- package/dist/src/mfs.spec.d.ts.map +1 -0
- package/dist/src/mfs.spec.js +85 -0
- package/dist/src/mfs.spec.js.map +1 -0
- package/dist/src/strings.spec.d.ts +2 -0
- package/dist/src/strings.spec.d.ts.map +1 -0
- package/dist/src/strings.spec.js +51 -0
- package/dist/src/strings.spec.js.map +1 -0
- package/dist/src/unixfs-bitswap.spec.d.ts +2 -0
- package/dist/src/unixfs-bitswap.spec.d.ts.map +1 -0
- package/dist/src/unixfs-bitswap.spec.js +65 -0
- package/dist/src/unixfs-bitswap.spec.js.map +1 -0
- package/dist/src/unixfs-files.spec.d.ts +2 -0
- package/dist/src/unixfs-files.spec.d.ts.map +1 -0
- package/dist/src/unixfs-files.spec.js +69 -0
- package/dist/src/unixfs-files.spec.js.map +1 -0
- package/package.json +22 -19
- package/src/bin.ts +25 -0
- package/src/car.spec.ts +102 -0
- package/src/dag-cbor.spec.ts +65 -0
- package/src/dag-json.spec.ts +65 -0
- package/src/fixtures/connect.ts +19 -0
- package/src/fixtures/create-helia.browser.ts +64 -0
- package/src/fixtures/create-helia.ts +51 -0
- package/src/fixtures/create-kubo.browser.ts +21 -0
- package/src/fixtures/create-kubo.ts +23 -0
- package/src/fixtures/create-peer-ids.ts +46 -0
- package/src/fixtures/key-types.ts +7 -0
- package/src/fixtures/memory-car.ts +33 -0
- package/src/fixtures/wait-for.ts +26 -0
- package/src/helia-blockstore.spec.ts +59 -0
- package/src/helia-hashes.spec.ts +61 -0
- package/src/helia-pins.spec.ts +64 -0
- package/src/index.ts +13 -0
- package/src/ipns-pubsub.spec.ts +180 -0
- package/src/ipns.spec.ts +183 -0
- package/src/json.spec.ts +65 -0
- package/src/mfs.spec.ts +105 -0
- package/src/strings.spec.ts +67 -0
- package/src/unixfs-bitswap.spec.ts +86 -0
- package/src/unixfs-files.spec.ts +89 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import { type UnixFS, unixfs } from '@helia/unixfs'
|
|
4
|
+
import { expect } from 'aegir/chai'
|
|
5
|
+
import toBuffer from 'it-to-buffer'
|
|
6
|
+
import { CID } from 'multiformats/cid'
|
|
7
|
+
import { createHeliaNode } from './fixtures/create-helia.js'
|
|
8
|
+
import { createKuboNode } from './fixtures/create-kubo.js'
|
|
9
|
+
import type { HeliaLibp2p } from 'helia'
|
|
10
|
+
import type { FileCandidate } from 'ipfs-unixfs-importer'
|
|
11
|
+
import type { Controller } from 'ipfsd-ctl'
|
|
12
|
+
|
|
13
|
+
describe('@helia/unixfs - bitswap', () => {
|
|
14
|
+
let helia: HeliaLibp2p
|
|
15
|
+
let unixFs: UnixFS
|
|
16
|
+
let kubo: Controller
|
|
17
|
+
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
helia = await createHeliaNode()
|
|
20
|
+
unixFs = unixfs(helia)
|
|
21
|
+
kubo = await createKuboNode()
|
|
22
|
+
|
|
23
|
+
// connect helia to kubo
|
|
24
|
+
await helia.libp2p.dial(kubo.peer.addresses)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
afterEach(async () => {
|
|
28
|
+
if (helia != null) {
|
|
29
|
+
await helia.stop()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (kubo != null) {
|
|
33
|
+
await kubo.stop()
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should add a large file to helia and fetch it from kubo', async () => {
|
|
38
|
+
const chunkSize = 1024 * 1024
|
|
39
|
+
const size = chunkSize * 10
|
|
40
|
+
const input: Uint8Array[] = []
|
|
41
|
+
|
|
42
|
+
const candidate: FileCandidate = {
|
|
43
|
+
content: (async function * () {
|
|
44
|
+
for (let i = 0; i < size; i += chunkSize) {
|
|
45
|
+
const buf = new Uint8Array(chunkSize)
|
|
46
|
+
input.push(buf)
|
|
47
|
+
|
|
48
|
+
yield buf
|
|
49
|
+
}
|
|
50
|
+
}())
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const cid = await unixFs.addFile(candidate)
|
|
54
|
+
|
|
55
|
+
const output: Uint8Array[] = []
|
|
56
|
+
|
|
57
|
+
for await (const b of kubo.api.cat(cid)) {
|
|
58
|
+
output.push(b)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
expect(toBuffer(output)).to.equalBytes(toBuffer(input))
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('should add a large file to kubo and fetch it from helia', async () => {
|
|
65
|
+
const chunkSize = 1024 * 1024
|
|
66
|
+
const size = chunkSize * 10
|
|
67
|
+
const input: Uint8Array[] = []
|
|
68
|
+
|
|
69
|
+
const candidate: FileCandidate = {
|
|
70
|
+
content: (async function * () {
|
|
71
|
+
for (let i = 0; i < size; i += chunkSize) {
|
|
72
|
+
const buf = new Uint8Array(chunkSize)
|
|
73
|
+
input.push(buf)
|
|
74
|
+
|
|
75
|
+
yield buf
|
|
76
|
+
}
|
|
77
|
+
}())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const { cid } = await kubo.api.add(candidate.content)
|
|
81
|
+
|
|
82
|
+
const bytes = await toBuffer(unixFs.cat(CID.parse(cid.toString())))
|
|
83
|
+
|
|
84
|
+
expect(bytes).to.equalBytes(toBuffer(input))
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import { type AddOptions, type UnixFS, unixfs } from '@helia/unixfs'
|
|
4
|
+
import { expect } from 'aegir/chai'
|
|
5
|
+
import { fixedSize } from 'ipfs-unixfs-importer/chunker'
|
|
6
|
+
import { balanced } from 'ipfs-unixfs-importer/layout'
|
|
7
|
+
import { CID } from 'multiformats/cid'
|
|
8
|
+
import { createHeliaNode } from './fixtures/create-helia.js'
|
|
9
|
+
import { createKuboNode } from './fixtures/create-kubo.js'
|
|
10
|
+
import type { HeliaLibp2p } from 'helia'
|
|
11
|
+
import type { AddOptions as KuboAddOptions } from 'ipfs-core-types/src/root.js'
|
|
12
|
+
import type { FileCandidate } from 'ipfs-unixfs-importer'
|
|
13
|
+
import type { Controller } from 'ipfsd-ctl'
|
|
14
|
+
|
|
15
|
+
describe('@helia/unixfs - files', () => {
|
|
16
|
+
let helia: HeliaLibp2p
|
|
17
|
+
let unixFs: UnixFS
|
|
18
|
+
let kubo: Controller
|
|
19
|
+
|
|
20
|
+
async function importToHelia (data: FileCandidate, opts?: Partial<AddOptions>): Promise<CID> {
|
|
21
|
+
const cid = await unixFs.addFile(data, opts)
|
|
22
|
+
|
|
23
|
+
return cid
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function importToKubo (data: FileCandidate, opts?: KuboAddOptions): Promise<CID> {
|
|
27
|
+
const result = await kubo.api.add(data.content, opts)
|
|
28
|
+
|
|
29
|
+
return CID.parse(result.cid.toString())
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function expectSameCid (data: () => FileCandidate, heliaOpts: Partial<AddOptions> = {}, kuboOpts: KuboAddOptions = {}): Promise<void> {
|
|
33
|
+
const heliaCid = await importToHelia(data(), {
|
|
34
|
+
// these are the default kubo options
|
|
35
|
+
cidVersion: 0,
|
|
36
|
+
rawLeaves: false,
|
|
37
|
+
layout: balanced({
|
|
38
|
+
maxChildrenPerNode: 174
|
|
39
|
+
}),
|
|
40
|
+
chunker: fixedSize({
|
|
41
|
+
chunkSize: 262144
|
|
42
|
+
}),
|
|
43
|
+
|
|
44
|
+
...heliaOpts
|
|
45
|
+
})
|
|
46
|
+
const kuboCid = await importToKubo(data(), kuboOpts)
|
|
47
|
+
|
|
48
|
+
expect(heliaCid.toString()).to.equal(kuboCid.toString())
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
beforeEach(async () => {
|
|
52
|
+
helia = await createHeliaNode()
|
|
53
|
+
unixFs = unixfs(helia)
|
|
54
|
+
kubo = await createKuboNode()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
afterEach(async () => {
|
|
58
|
+
if (helia != null) {
|
|
59
|
+
await helia.stop()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (kubo != null) {
|
|
63
|
+
await kubo.stop()
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('should create the same CID for a small file', async () => {
|
|
68
|
+
const candidate = (): FileCandidate => ({
|
|
69
|
+
content: Uint8Array.from([0, 1, 2, 3, 4])
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
await expectSameCid(candidate)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should create the same CID for a large file', async () => {
|
|
76
|
+
const chunkSize = 1024 * 1024
|
|
77
|
+
const size = chunkSize * 10
|
|
78
|
+
|
|
79
|
+
const candidate = (): FileCandidate => ({
|
|
80
|
+
content: (async function * () {
|
|
81
|
+
for (let i = 0; i < size; i += chunkSize) {
|
|
82
|
+
yield new Uint8Array(chunkSize)
|
|
83
|
+
}
|
|
84
|
+
}())
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
await expectSameCid(candidate)
|
|
88
|
+
})
|
|
89
|
+
})
|