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

fix: return nested value from dag.get #3966

Merged
merged 2 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/interface-ipfs-core/src/block/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export function testRm (factory, options) {

expect(result).to.have.lengthOf(3)

result.forEach((res, index) => {
expect(res.cid.toString()).to.equal(cids[index].toString())
result.forEach((res) => {
expect(cids.map(cid => cid.toString())).to.include(res.cid.toString())
expect(res).to.not.have.property('error')
})
})
Expand Down
22 changes: 22 additions & 0 deletions packages/interface-ipfs-core/src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,27 @@ export function testGet (factory, options) {
return expect(ipfs.dag.get(uint8ArrayFromString('INVALID CID')))
.to.eventually.be.rejected()
})

it('should return nested content when getting a CID with a path', async () => {
const regularContent = { test: '123' }
const cid1 = await ipfs.dag.put(regularContent)
const linkedContent = { link: cid1 }
const cid2 = await ipfs.dag.put(linkedContent)

const atPath = await ipfs.dag.get(cid2, { path: '/link' })

expect(atPath).to.have.deep.property('value', regularContent)
})

it('should not return nested content when getting a CID with a path and localResolve is true', async () => {
const regularContent = { test: '123' }
const cid1 = await ipfs.dag.put(regularContent)
const linkedContent = { link: cid1 }
const cid2 = await ipfs.dag.put(linkedContent)

const atPath = await ipfs.dag.get(cid2, { path: '/link', localResolve: true })

expect(atPath).to.have.deep.property('value').that.is.an.instanceOf(CID)
})
})
}
12 changes: 5 additions & 7 deletions packages/ipfs-core/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ export const resolve = async function * (cid, path, codecs, repo, options) {
let value = await load(cid)
let lastCid = cid

if (!parts.length) {
yield {
value,
remainderPath: ''
}
}

// End iteration if there isn't a CID to follow any more
while (parts.length) {
const key = parts.shift()
Expand Down Expand Up @@ -248,4 +241,9 @@ export const resolve = async function * (cid, path, codecs, repo, options) {
value = await load(value)
}
}

yield {
value,
remainderPath: ''
}
}
12 changes: 5 additions & 7 deletions packages/ipfs-http-client/src/lib/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ export async function * resolve (cid, path, codecs, getBlock, options) {
let value = await load(cid)
let lastCid = cid

if (!parts.length) {
yield {
value,
remainderPath: ''
}
}

// End iteration if there isn't a CID to follow any more
while (parts.length) {
const key = parts.shift()
Expand All @@ -62,4 +55,9 @@ export async function * resolve (cid, path, codecs, getBlock, options) {
value = await load(value)
}
}

yield {
value,
remainderPath: ''
}
}