Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 82b9e08

Browse files
authored
chore: move mfs and multipart files into core (#2811)
BREAKING CHANGE: When the path passed to `ipfs.files.stat(path)` was a hamt sharded dir, the resovled value returned by js-ipfs previously had a `type` property of with a value of `'hamt-sharded-directory'`. To bring it in line with go-ipfs this value is now `'directory'`.
1 parent bfba767 commit 82b9e08

File tree

250 files changed

+3932
-6311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+3932
-6311
lines changed

examples/circuit-relaying/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"ipfs-pubsub-room": "^2.0.1"
2020
},
2121
"devDependencies": {
22-
"aegir": "^21.3.0",
22+
"aegir": "21.3.0",
2323
"execa": "^3.2.0",
2424
"ipfs-css": "^0.13.1",
2525
"ipfs-http-client": "^42.0.0",

examples/running-multiple-nodes/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const IPFS = require('ipfs')
55
const execa = require('execa')
66
const os = require('os')
77
const path = require('path')
8-
const hat = require('hat')
8+
const nanoid = require('nanoid')
99
const {
1010
waitForOutput
1111
} = require('test-ipfs-example/utils')
@@ -18,7 +18,7 @@ async function testCli () {
1818
}
1919

2020
async function startCliNode () {
21-
const repoDir = path.join(os.tmpdir(), `repo-${hat()}`)
21+
const repoDir = path.join(os.tmpdir(), `repo-${nanoid()}`)
2222
const opts = {
2323
env: {
2424
...process.env,
@@ -43,7 +43,7 @@ async function testProgramatically () {
4343
}
4444

4545
async function startProgramaticNode () {
46-
const repoDir = path.join(os.tmpdir(), `repo-${hat()}`)
46+
const repoDir = path.join(os.tmpdir(), `repo-${nanoid()}`)
4747
const node = await IPFS.create({
4848
repo: repoDir,
4949
config: {

packages/interface-ipfs-core/package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
"dependencies": {
3333
"chai": "^4.2.0",
3434
"chai-as-promised": "^7.1.1",
35-
"chai-things": "^0.2.0",
35+
"chai-subset": "^1.6.0",
3636
"cids": "^0.7.3",
3737
"delay": "^4.3.0",
3838
"dirty-chai": "^2.0.1",
39-
"hat": "0.0.3",
4039
"ipfs-block": "^0.8.1",
4140
"ipfs-unixfs": "^1.0.0",
4241
"ipfs-utils": "^0.7.2",
4342
"ipld-dag-cbor": "^0.15.1",
4443
"ipld-dag-pb": "^0.18.3",
4544
"is-ipfs": "^0.6.1",
45+
"iso-random-stream": "^1.1.1",
4646
"it-all": "^1.0.1",
4747
"it-concat": "^1.0.0",
4848
"it-last": "^1.0.1",
@@ -51,11 +51,13 @@
5151
"multibase": "^0.6.0",
5252
"multihashes": "^0.4.14",
5353
"multihashing-async": "^0.8.0",
54+
"nanoid": "^2.1.11",
5455
"peer-id": "^0.13.5",
55-
"readable-stream": "^3.4.0"
56+
"readable-stream": "^3.4.0",
57+
"temp-write": "^4.0.0"
5658
},
5759
"devDependencies": {
58-
"aegir": "^21.3.0",
60+
"aegir": "21.3.0",
5961
"ipfsd-ctl": "^3.0.0"
6062
},
6163
"contributors": [

packages/interface-ipfs-core/src/add.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const { fixtures } = require('./utils')
55
const { Readable } = require('readable-stream')
66
const all = require('it-all')
7+
const last = require('it-last')
78
const fs = require('fs')
89
const os = require('os')
910
const path = require('path')
@@ -13,7 +14,6 @@ const urlSource = require('ipfs-utils/src/files/url-source')
1314
const { isNode } = require('ipfs-utils/src/env')
1415
const { getDescribe, getIt, expect } = require('./utils/mocha')
1516
const { echoUrl, redirectUrl } = require('./utils/echo-http-server')
16-
1717
const fixturesPath = path.join(__dirname, '..', 'test', 'fixtures')
1818

1919
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
@@ -221,9 +221,8 @@ module.exports = (common, options) => {
221221
emptyDir('files/empty')
222222
]
223223

224-
const res = await all(ipfs.add(dirs))
224+
const root = await last(ipfs.add(dirs))
225225

226-
const root = res[res.length - 1]
227226
expect(root.path).to.equal('test-folder')
228227
expect(root.cid.toString()).to.equal(fixtures.directory.cid)
229228
})
@@ -258,9 +257,7 @@ module.exports = (common, options) => {
258257
accumProgress += p
259258
}
260259

261-
const filesAdded = await all(ipfs.add(dirs, { progress: handler }))
262-
263-
const root = filesAdded[filesAdded.length - 1]
260+
const root = await last(ipfs.add(dirs, { progress: handler }))
264261
expect(progCalled).to.be.true()
265262
expect(accumProgress).to.be.at.least(total)
266263
expect(root.path).to.equal('test-folder')
@@ -289,10 +286,10 @@ module.exports = (common, options) => {
289286
expect(nonSeqDirFilePaths.every(p => filesAddedPaths.includes(p))).to.be.true()
290287
})
291288

292-
it('should fail when passed invalid input', () => {
289+
it('should fail when passed invalid input', async () => {
293290
const nonValid = 138
294291

295-
return expect(all(ipfs.add(nonValid))).to.eventually.be.rejected()
292+
await expect(all(ipfs.add(nonValid))).to.eventually.be.rejected()
296293
})
297294

298295
it('should wrap content in a directory', async () => {

packages/interface-ipfs-core/src/block/rm.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict'
33

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
5-
const hat = require('hat')
5+
const nanoid = require('nanoid')
66
const all = require('it-all')
77

88
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
@@ -22,7 +22,7 @@ module.exports = (common, options) => {
2222
after(() => common.clean())
2323

2424
it('should remove by CID object', async () => {
25-
const cid = await ipfs.dag.put(Buffer.from(hat()), {
25+
const cid = await ipfs.dag.put(Buffer.from(nanoid()), {
2626
format: 'raw',
2727
hashAlg: 'sha2-256'
2828
})
@@ -44,7 +44,7 @@ module.exports = (common, options) => {
4444
})
4545

4646
it('should remove by CID in string', async () => {
47-
const cid = await ipfs.dag.put(Buffer.from(hat()), {
47+
const cid = await ipfs.dag.put(Buffer.from(nanoid()), {
4848
format: 'raw',
4949
hashAlg: 'sha2-256'
5050
})
@@ -56,7 +56,7 @@ module.exports = (common, options) => {
5656
})
5757

5858
it('should remove by CID in buffer', async () => {
59-
const cid = await ipfs.dag.put(Buffer.from(hat()), {
59+
const cid = await ipfs.dag.put(Buffer.from(nanoid()), {
6060
format: 'raw',
6161
hashAlg: 'sha2-256'
6262
})
@@ -69,15 +69,15 @@ module.exports = (common, options) => {
6969

7070
it('should remove multiple CIDs', async () => {
7171
const cids = [
72-
await ipfs.dag.put(Buffer.from(hat()), {
72+
await ipfs.dag.put(Buffer.from(nanoid()), {
7373
format: 'raw',
7474
hashAlg: 'sha2-256'
7575
}),
76-
await ipfs.dag.put(Buffer.from(hat()), {
76+
await ipfs.dag.put(Buffer.from(nanoid()), {
7777
format: 'raw',
7878
hashAlg: 'sha2-256'
7979
}),
80-
await ipfs.dag.put(Buffer.from(hat()), {
80+
await ipfs.dag.put(Buffer.from(nanoid()), {
8181
format: 'raw',
8282
hashAlg: 'sha2-256'
8383
})
@@ -94,7 +94,7 @@ module.exports = (common, options) => {
9494
})
9595

9696
it('should error when removing non-existent blocks', async () => {
97-
const cid = await ipfs.dag.put(Buffer.from(hat()), {
97+
const cid = await ipfs.dag.put(Buffer.from(nanoid()), {
9898
format: 'raw',
9999
hashAlg: 'sha2-256'
100100
})
@@ -111,7 +111,7 @@ module.exports = (common, options) => {
111111
})
112112

113113
it('should not error when force removing non-existent blocks', async () => {
114-
const cid = await ipfs.dag.put(Buffer.from(hat()), {
114+
const cid = await ipfs.dag.put(Buffer.from(nanoid()), {
115115
format: 'raw',
116116
hashAlg: 'sha2-256'
117117
})
@@ -128,7 +128,7 @@ module.exports = (common, options) => {
128128
})
129129

130130
it('should return empty output when removing blocks quietly', async () => {
131-
const cid = await ipfs.dag.put(Buffer.from(hat()), {
131+
const cid = await ipfs.dag.put(Buffer.from(nanoid()), {
132132
format: 'raw',
133133
hashAlg: 'sha2-256'
134134
})
@@ -138,7 +138,7 @@ module.exports = (common, options) => {
138138
})
139139

140140
it('should error when removing pinned blocks', async () => {
141-
const cid = await ipfs.dag.put(Buffer.from(hat()), {
141+
const cid = await ipfs.dag.put(Buffer.from(nanoid()), {
142142
format: 'raw',
143143
hashAlg: 'sha2-256'
144144
})

packages/interface-ipfs-core/src/dht/get.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const hat = require('hat')
4+
const nanoid = require('nanoid')
55
const { getDescribe, getIt, expect } = require('../utils/mocha')
66

77
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
@@ -36,8 +36,8 @@ module.exports = (common, options) => {
3636
// "invalid record keytype" - it needs to put a valid key and value for it to
3737
// be a useful test.
3838
it.skip('should get a value after it was put on another node', async () => {
39-
const key = Buffer.from(hat())
40-
const value = Buffer.from(hat())
39+
const key = Buffer.from(nanoid())
40+
const value = Buffer.from(nanoid())
4141

4242
await nodeB.dht.put(key, value)
4343
const result = await nodeA.dht.get(key)

0 commit comments

Comments
 (0)