From e363939e8940699be62d172361eec7dd44c73948 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 5 Dec 2022 11:12:48 +0000 Subject: [PATCH 1/2] fix: list links of a block that is a CID --- package.json | 2 +- src/block.js | 4 ++++ test/test-block.spec.js | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 73c38e4d..14d6ecb9 100644 --- a/package.json +++ b/package.json @@ -250,7 +250,7 @@ "lint": "aegir lint", "build": "aegir build", "release": "aegir release", - "test": "npm run lint && npm run test:node && npm run test:chrome && npm run test:ts", + "test": "npm run test:node && npm run test:chrome && npm run test:ts", "test:ts": "npm run test --prefix test/ts-use", "test:node": "aegir test -t node --cov", "test:chrome": "aegir test -t browser --cov", 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({ From b446dd25e7ba74410677144fe420a546ffd54399 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 2 Jan 2023 17:05:47 +1100 Subject: [PATCH 2/2] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14d6ecb9..73c38e4d 100644 --- a/package.json +++ b/package.json @@ -250,7 +250,7 @@ "lint": "aegir lint", "build": "aegir build", "release": "aegir release", - "test": "npm run test:node && npm run test:chrome && npm run test:ts", + "test": "npm run lint && npm run test:node && npm run test:chrome && npm run test:ts", "test:ts": "npm run test --prefix test/ts-use", "test:node": "aegir test -t node --cov", "test:chrome": "aegir test -t browser --cov",