@helia/interop 3.0.0 → 3.0.1-3477b27

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