@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.
Files changed (123) hide show
  1. package/.aegir.js +46 -0
  2. package/README.md +11 -0
  3. package/dist/src/bin.d.ts +3 -0
  4. package/dist/src/bin.d.ts.map +1 -0
  5. package/dist/src/bin.js +20 -0
  6. package/dist/src/bin.js.map +1 -0
  7. package/dist/src/car.spec.d.ts +2 -0
  8. package/dist/src/car.spec.d.ts.map +1 -0
  9. package/dist/src/car.spec.js +77 -0
  10. package/dist/src/car.spec.js.map +1 -0
  11. package/dist/src/dag-cbor.spec.d.ts +2 -0
  12. package/dist/src/dag-cbor.spec.d.ts.map +1 -0
  13. package/dist/src/dag-cbor.spec.js +49 -0
  14. package/dist/src/dag-cbor.spec.js.map +1 -0
  15. package/dist/src/dag-json.spec.d.ts +2 -0
  16. package/dist/src/dag-json.spec.d.ts.map +1 -0
  17. package/dist/src/dag-json.spec.js +49 -0
  18. package/dist/src/dag-json.spec.js.map +1 -0
  19. package/dist/src/fixtures/connect.d.ts +7 -0
  20. package/dist/src/fixtures/connect.d.ts.map +1 -0
  21. package/dist/src/fixtures/connect.js +17 -0
  22. package/dist/src/fixtures/connect.js.map +1 -0
  23. package/dist/src/fixtures/create-helia.browser.d.ts +4 -0
  24. package/dist/src/fixtures/create-helia.browser.d.ts.map +1 -0
  25. package/dist/src/fixtures/create-helia.browser.js +55 -0
  26. package/dist/src/fixtures/create-helia.browser.js.map +1 -0
  27. package/dist/src/fixtures/create-helia.d.ts +4 -0
  28. package/dist/src/fixtures/create-helia.d.ts.map +1 -0
  29. package/dist/src/fixtures/create-helia.js +45 -0
  30. package/dist/src/fixtures/create-helia.js.map +1 -0
  31. package/dist/src/fixtures/create-kubo.browser.d.ts +3 -0
  32. package/dist/src/fixtures/create-kubo.browser.d.ts.map +1 -0
  33. package/dist/src/fixtures/create-kubo.browser.js +21 -0
  34. package/dist/src/fixtures/create-kubo.browser.js.map +1 -0
  35. package/dist/src/fixtures/create-kubo.d.ts +3 -0
  36. package/dist/src/fixtures/create-kubo.d.ts.map +1 -0
  37. package/dist/src/fixtures/create-kubo.js +23 -0
  38. package/dist/src/fixtures/create-kubo.js.map +1 -0
  39. package/dist/src/fixtures/create-peer-ids.d.ts +14 -0
  40. package/dist/src/fixtures/create-peer-ids.d.ts.map +1 -0
  41. package/dist/src/fixtures/create-peer-ids.js +37 -0
  42. package/dist/src/fixtures/create-peer-ids.js.map +1 -0
  43. package/dist/src/fixtures/key-types.d.ts +3 -0
  44. package/dist/src/fixtures/key-types.d.ts.map +1 -0
  45. package/dist/src/fixtures/key-types.js +6 -0
  46. package/dist/src/fixtures/key-types.js.map +1 -0
  47. package/dist/src/fixtures/memory-car.d.ts +7 -0
  48. package/dist/src/fixtures/memory-car.d.ts.map +1 -0
  49. package/dist/src/fixtures/memory-car.js +26 -0
  50. package/dist/src/fixtures/memory-car.js.map +1 -0
  51. package/dist/src/fixtures/wait-for.d.ts +7 -0
  52. package/dist/src/fixtures/wait-for.d.ts.map +1 -0
  53. package/dist/src/fixtures/wait-for.js +17 -0
  54. package/dist/src/fixtures/wait-for.js.map +1 -0
  55. package/dist/src/helia-blockstore.spec.d.ts +2 -0
  56. package/dist/src/helia-blockstore.spec.d.ts.map +1 -0
  57. package/dist/src/helia-blockstore.spec.js +48 -0
  58. package/dist/src/helia-blockstore.spec.js.map +1 -0
  59. package/dist/src/helia-hashes.spec.d.ts +2 -0
  60. package/dist/src/helia-hashes.spec.d.ts.map +1 -0
  61. package/dist/src/helia-hashes.spec.js +50 -0
  62. package/dist/src/helia-hashes.spec.js.map +1 -0
  63. package/dist/src/helia-pins.spec.d.ts +2 -0
  64. package/dist/src/helia-pins.spec.d.ts.map +1 -0
  65. package/dist/src/helia-pins.spec.js +48 -0
  66. package/dist/src/helia-pins.spec.js.map +1 -0
  67. package/dist/src/index.d.ts +12 -0
  68. package/dist/src/index.d.ts.map +1 -1
  69. package/dist/src/index.js +12 -0
  70. package/dist/src/index.js.map +1 -1
  71. package/dist/src/ipns-pubsub.spec.d.ts +2 -0
  72. package/dist/src/ipns-pubsub.spec.d.ts.map +1 -0
  73. package/dist/src/ipns-pubsub.spec.js +146 -0
  74. package/dist/src/ipns-pubsub.spec.js.map +1 -0
  75. package/dist/src/ipns.spec.d.ts +2 -0
  76. package/dist/src/ipns.spec.d.ts.map +1 -0
  77. package/dist/src/ipns.spec.js +146 -0
  78. package/dist/src/ipns.spec.js.map +1 -0
  79. package/dist/src/json.spec.d.ts +2 -0
  80. package/dist/src/json.spec.d.ts.map +1 -0
  81. package/dist/src/json.spec.js +49 -0
  82. package/dist/src/json.spec.js.map +1 -0
  83. package/dist/src/mfs.spec.d.ts +2 -0
  84. package/dist/src/mfs.spec.d.ts.map +1 -0
  85. package/dist/src/mfs.spec.js +85 -0
  86. package/dist/src/mfs.spec.js.map +1 -0
  87. package/dist/src/strings.spec.d.ts +2 -0
  88. package/dist/src/strings.spec.d.ts.map +1 -0
  89. package/dist/src/strings.spec.js +51 -0
  90. package/dist/src/strings.spec.js.map +1 -0
  91. package/dist/src/unixfs-bitswap.spec.d.ts +2 -0
  92. package/dist/src/unixfs-bitswap.spec.d.ts.map +1 -0
  93. package/dist/src/unixfs-bitswap.spec.js +65 -0
  94. package/dist/src/unixfs-bitswap.spec.js.map +1 -0
  95. package/dist/src/unixfs-files.spec.d.ts +2 -0
  96. package/dist/src/unixfs-files.spec.d.ts.map +1 -0
  97. package/dist/src/unixfs-files.spec.js +69 -0
  98. package/dist/src/unixfs-files.spec.js.map +1 -0
  99. package/package.json +22 -19
  100. package/src/bin.ts +25 -0
  101. package/src/car.spec.ts +102 -0
  102. package/src/dag-cbor.spec.ts +65 -0
  103. package/src/dag-json.spec.ts +65 -0
  104. package/src/fixtures/connect.ts +19 -0
  105. package/src/fixtures/create-helia.browser.ts +64 -0
  106. package/src/fixtures/create-helia.ts +51 -0
  107. package/src/fixtures/create-kubo.browser.ts +21 -0
  108. package/src/fixtures/create-kubo.ts +23 -0
  109. package/src/fixtures/create-peer-ids.ts +46 -0
  110. package/src/fixtures/key-types.ts +7 -0
  111. package/src/fixtures/memory-car.ts +33 -0
  112. package/src/fixtures/wait-for.ts +26 -0
  113. package/src/helia-blockstore.spec.ts +59 -0
  114. package/src/helia-hashes.spec.ts +61 -0
  115. package/src/helia-pins.spec.ts +64 -0
  116. package/src/index.ts +13 -0
  117. package/src/ipns-pubsub.spec.ts +180 -0
  118. package/src/ipns.spec.ts +183 -0
  119. package/src/json.spec.ts +65 -0
  120. package/src/mfs.spec.ts +105 -0
  121. package/src/strings.spec.ts +67 -0
  122. package/src/unixfs-bitswap.spec.ts +86 -0
  123. 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
+ })