Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix: reinstate DAGLink.multihash property with deprecation notice
Browse files Browse the repository at this point in the history
Just having a slight wobble about removing the `.multihash`
property from the DAGLink class as part of #99.  It's the right
thing to do but it will cause a lot of disruption.
  • Loading branch information
achingbrain committed Nov 12, 2018
1 parent d56ed9a commit 66dde2a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- [`link.name`](#linkname)
- [`link.size`](#linksize)
- [`link.cid`](#linkcid)
- [`link.multihash`](#linkmultihash)
- [`link.toJSON()`](#linktojson)
- [`link.toString()`](#linktostring)
- [[IPLD Format Specifics](https://github.com/ipld/interface-ipld-format) - Local (node/block scope) resolver](#ipld-format-specificshttpsgithubcomipldinterface-ipld-format---local-nodeblock-scope-resolver)
Expand Down Expand Up @@ -263,6 +264,12 @@ const link = new DAGLink(name, size, cid)

#### `link.cid`



#### `link.multihash`

**Deprecated** Please use `link.cid` instead.

#### `link.toJSON()`

#### `link.toString()`
Expand Down
11 changes: 10 additions & 1 deletion src/dag-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class DAGLink {
this._json = Object.freeze({
name: this.name,
size: this.size,
cid: this._cid.toBaseEncodedString()
cid: this._cid.toBaseEncodedString(),
multihash: this._cid.toBaseEncodedString()
})
}

Expand Down Expand Up @@ -56,6 +57,14 @@ class DAGLink {
set cid (cid) {
throw new Error("Can't set property: 'cid' is immutable")
}

get multihash () {
return this._cid.buffer
}

set multihash (cid) {
throw new Error("Can't set property: 'multihash' is immutable")
}
}

exports = module.exports = withIs(DAGLink, { className: 'DAGLink', symbolName: '@ipld/js-ipld-dag-pb/daglink' })
Expand Down
20 changes: 19 additions & 1 deletion test/dag-link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = (repo) => {
expect(link.toJSON()).to.eql({
name: 'hello',
size: 3,
cid: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U'
cid: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U',
multihash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U'
})
})

Expand All @@ -70,5 +71,22 @@ module.exports = (repo) => {
expect(error.message).to.include("'cid' is immutable")
}
})

it('exposes a multihash', () => {
const cid = new CID('QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')
const link = new DAGLink('hello', 3, cid)
expect(link.multihash).to.deep.equal(cid.buffer)
})

it('has an immutable multihash', () => {
const link = new DAGLink('hello', 3, 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')

try {
link.multihash = 'foo'
throw new Error('Should not be able to update multihash')
} catch (error) {
expect(error.message).to.include("'multihash' is immutable")
}
})
})
}
11 changes: 11 additions & 0 deletions test/dag-node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,36 +491,43 @@ module.exports = (repo) => {
{
name: '',
cid: 'QmSbCgdsX12C4KDw3PDmpBN9iCzS87a5DjgSCoW9esqzXk',
multihash: 'QmSbCgdsX12C4KDw3PDmpBN9iCzS87a5DjgSCoW9esqzXk',
size: 45623854
},
{
name: '',
cid: 'Qma4GxWNhywSvWFzPKtEswPGqeZ9mLs2Kt76JuBq9g3fi2',
multihash: 'Qma4GxWNhywSvWFzPKtEswPGqeZ9mLs2Kt76JuBq9g3fi2',
size: 45623854
},
{
name: '',
cid: 'QmQfyxyys7a1e3mpz9XsntSsTGc8VgpjPj5BF1a1CGdGNc',
multihash: 'QmQfyxyys7a1e3mpz9XsntSsTGc8VgpjPj5BF1a1CGdGNc',
size: 45623854
},
{
name: '',
cid: 'QmSh2wTTZT4N8fuSeCFw7wterzdqbE93j1XDhfN3vQHzDV',
multihash: 'QmSh2wTTZT4N8fuSeCFw7wterzdqbE93j1XDhfN3vQHzDV',
size: 45623854
},
{
name: '',
cid: 'QmVXsSVjwxMsCwKRCUxEkGb4f4B98gXVy3ih3v4otvcURK',
multihash: 'QmVXsSVjwxMsCwKRCUxEkGb4f4B98gXVy3ih3v4otvcURK',
size: 45623854
},
{
name: '',
cid: 'QmZjhH97MEYwQXzCqSQbdjGDhXWuwW4RyikR24pNqytWLj',
multihash: 'QmZjhH97MEYwQXzCqSQbdjGDhXWuwW4RyikR24pNqytWLj',
size: 45623854
},
{
name: '',
cid: 'QmRs6U5YirCqC7taTynz3x2GNaHJZ3jDvMVAzaiXppwmNJ',
multihash: 'QmRs6U5YirCqC7taTynz3x2GNaHJZ3jDvMVAzaiXppwmNJ',
size: 32538395
}
]
Expand All @@ -545,21 +552,25 @@ module.exports = (repo) => {
{
name: 'audio_only.m4a',
cid: 'QmaUAwAQJNtvUdJB42qNbTTgDpzPYD1qdsKNtctM5i7DGB',
multihash: 'QmaUAwAQJNtvUdJB42qNbTTgDpzPYD1qdsKNtctM5i7DGB',
size: 23319629
},
{
name: 'chat.txt',
cid: 'QmNVrxbB25cKTRuKg2DuhUmBVEK9NmCwWEHtsHPV6YutHw',
multihash: 'QmNVrxbB25cKTRuKg2DuhUmBVEK9NmCwWEHtsHPV6YutHw',
size: 996
},
{
name: 'playback.m3u',
cid: 'QmUcjKzDLXBPmB6BKHeKSh6ZoFZjss4XDhMRdLYRVuvVfu',
multihash: 'QmUcjKzDLXBPmB6BKHeKSh6ZoFZjss4XDhMRdLYRVuvVfu',
size: 116
},
{
name: 'zoom_0.mp4',
cid: 'QmQqy2SiEkKgr2cw5UbQ93TtLKEMsD8TdcWggR8q9JabjX',
multihash: 'QmQqy2SiEkKgr2cw5UbQ93TtLKEMsD8TdcWggR8q9JabjX',
size: 306281879
}
]
Expand Down
2 changes: 2 additions & 0 deletions test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ describe('IPLD Format resolver (local)', () => {
const links = [{
name: '',
cid: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U',
multihash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U',
size: 10
}, {
name: 'named link',
cid: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V',
multihash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V',
size: 8
}]
const create = (data, links, callback) => waterfall([
Expand Down

0 comments on commit 66dde2a

Please sign in to comment.