diff --git a/src/block.js b/src/block.js index 2e1a7dbf..16adbec5 100644 --- a/src/block.js +++ b/src/block.js @@ -45,6 +45,10 @@ function * links (source, base) { if (source == null || source instanceof Uint8Array) { return } + const cid = CID.asCID(source) + if (cid) { + yield [base.join('/'), cid] + } for (const [key, value] of Object.entries(source)) { const path = /** @type {[string|number, string]} */ ([...base, key]) yield * linksWithin(path, value) diff --git a/test/test-block.spec.js b/test/test-block.spec.js index 112556f9..4fdf8f54 100644 --- a/test/test-block.spec.js +++ b/test/test-block.spec.js @@ -83,6 +83,17 @@ describe('block', () => { }) }) + it('links of a block that is a CID', async () => { + const block = await main.encode({ value: link, codec, hasher }) + const links = [] + for (const link of block.links()) { + links.push(link) + } + assert.equal(links.length, 1) + assert.equal(links[0][0], '') + assert.equal(links[0][1].toString(), link.toString()) + }) + it('kitchen sink', () => { const sink = { one: { two: { arr: [true, false, null], three: 3, buff, link } } } const block = main.createUnsafe({