Skip to content

Commit ffc4e6f

Browse files
committed
feat: remove deprecated CID properties & methods
1 parent 85a9296 commit ffc4e6f

File tree

3 files changed

+0
-153
lines changed

3 files changed

+0
-153
lines changed

src/cid.js

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -219,41 +219,6 @@ export class CID {
219219
return `CID(${this.toString()})`
220220
}
221221

222-
// Deprecated
223-
224-
/**
225-
* @param {any} value
226-
* @returns {value is CID}
227-
*/
228-
static isCID (value) {
229-
deprecate(/^0\.0/, IS_CID_DEPRECATION)
230-
return Boolean(value && (value[cidSymbol] || value.asCID === value))
231-
}
232-
233-
get toBaseEncodedString () {
234-
throw new Error('Deprecated, use .toString()')
235-
}
236-
237-
get codec () {
238-
throw new Error(
239-
'"codec" property is deprecated, use integer "code" property instead'
240-
)
241-
}
242-
243-
get buffer () {
244-
throw new Error(
245-
'Deprecated .buffer property, use .bytes to get Uint8Array instead'
246-
)
247-
}
248-
249-
get multibaseName () {
250-
throw new Error('"multibaseName" property is deprecated')
251-
}
252-
253-
get prefix () {
254-
throw new Error('"prefix" property is deprecated')
255-
}
256-
257222
/**
258223
* Takes any input `value` and returns a `CID` instance if it was
259224
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
@@ -605,38 +570,3 @@ const encodeCID = (version, code, multihash) => {
605570
const cidSymbol = Symbol.for('@ipld/js-cid/CID')
606571
const readonly = { writable: false, configurable: false, enumerable: true }
607572
const hidden = { writable: false, enumerable: false, configurable: false }
608-
609-
// ESM does not support importing package.json where this version info
610-
// should come from. To workaround it version is copied here.
611-
const version = '0.0.0-dev'
612-
// Start throwing exceptions on major version bump
613-
/**
614-
*
615-
* @param {RegExp} range
616-
* @param {string} message
617-
*/
618-
const deprecate = (range, message) => {
619-
/* eslint-disable no-console */
620-
if (range.test(version)) {
621-
console.warn(message)
622-
/* c8 ignore next 3 */
623-
} else {
624-
throw new Error(message)
625-
}
626-
}
627-
628-
const IS_CID_DEPRECATION = `CID.isCID(v) is deprecated and will be removed in the next major release.
629-
Following code pattern:
630-
631-
if (CID.isCID(value)) {
632-
doSomethingWithCID(value)
633-
}
634-
635-
Is replaced with:
636-
637-
const cid = CID.asCID(value)
638-
if (cid) {
639-
// Make sure to use cid instead of value
640-
doSomethingWithCID(cid)
641-
}
642-
`

test/test-cid.spec.js

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ describe('CID', () => {
8282
assert.throws(() => CID.create(0, 113, hash), msg)
8383
})
8484

85-
// This was failing for quite some time, test just missed await so it went
86-
// unnoticed. Not sure we still care about checking fourth argument.
87-
// it('throws on trying to pass specific base encoding [deprecated]', async () => {
88-
// const hash = await sha256.digest(textEncoder.encode('abc'))
89-
// const msg = 'No longer supported, cannot specify base encoding in instantiation'
90-
// assert.throws(() => CID.create(0, 112, hash, 'base32'), msg)
91-
// })
92-
9385
it('throws on trying to base encode CIDv0 in other base than base58btc', async () => {
9486
const mhStr = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
9587
const cid = CID.parse(mhStr)
@@ -286,18 +278,6 @@ describe('CID', () => {
286278
)
287279
})
288280

289-
it('.isCid', () => {
290-
assert.ok(CID.isCID(CID.parse(h1)))
291-
292-
assert.ok(!CID.isCID(false))
293-
294-
assert.ok(!CID.isCID(textEncoder.encode('hello world')))
295-
296-
assert.ok(CID.isCID(CID.parse(h1).toV0()))
297-
298-
assert.ok(CID.isCID(CID.parse(h1).toV1()))
299-
})
300-
301281
it('works with deepEquals', () => {
302282
const ch1 = CID.parse(h1)
303283
assert.deepStrictEqual(ch1, CID.parse(h1))
@@ -515,12 +495,6 @@ describe('CID', () => {
515495
assert.ok(equals(json.hash, hash.bytes))
516496
})
517497

518-
it('isCID', async () => {
519-
const hash = await sha256.digest(textEncoder.encode('abc'))
520-
const cid = CID.create(1, 112, hash)
521-
assert.strictEqual(OLDCID.isCID(cid), false)
522-
})
523-
524498
it('asCID', async () => {
525499
const hash = await sha256.digest(textEncoder.encode('abc'))
526500
class IncompatibleCID {
@@ -545,7 +519,6 @@ describe('CID', () => {
545519
const code = 112
546520

547521
const incompatibleCID = new IncompatibleCID(version, code, hash)
548-
assert.ok(CID.isCID(incompatibleCID))
549522
assert.strictEqual(incompatibleCID.toString(), '[object Object]')
550523
// @ts-expect-error - no such method
551524
assert.strictEqual(typeof incompatibleCID.toV0, 'undefined')
@@ -719,59 +692,8 @@ describe('CID', () => {
719692
)
720693
})
721694

722-
describe('deprecations', async () => {
723-
it('codec', async () => {
724-
const hash = await sha256.digest(textEncoder.encode('abc'))
725-
const cid = CID.create(1, 112, hash)
726-
727-
assert.throws(
728-
() => cid.codec,
729-
'"codec" property is deprecated, use integer "code" property instead'
730-
)
731-
assert.throws(
732-
// @ts-expect-error - 'string' is not assignable to parameter of type 'number'
733-
() => CID.create(1, 'dag-pb', hash),
734-
'String codecs are no longer supported'
735-
)
736-
})
737-
738-
it('multibaseName', async () => {
739-
const hash = await sha256.digest(textEncoder.encode('abc'))
740-
const cid = CID.create(1, 112, hash)
741-
assert.throws(
742-
() => cid.multibaseName,
743-
'"multibaseName" property is deprecated'
744-
)
745-
})
746-
747-
it('prefix', async () => {
748-
const hash = await sha256.digest(textEncoder.encode('abc'))
749-
const cid = CID.create(1, 112, hash)
750-
assert.throws(() => cid.prefix, '"prefix" property is deprecated')
751-
})
752-
753-
it('toBaseEncodedString()', async () => {
754-
const hash = await sha256.digest(textEncoder.encode('abc'))
755-
const cid = CID.create(1, 112, hash)
756-
assert.throws(
757-
// @ts-expect-error - deprecated
758-
() => cid.toBaseEncodedString(),
759-
'Deprecated, use .toString()'
760-
)
761-
})
762-
})
763-
764695
it('invalid CID version', async () => {
765696
const encoded = varint.encodeTo(2, new Uint8Array(32))
766697
assert.throws(() => CID.decode(encoded), 'Invalid CID version 2')
767698
})
768-
769-
it('buffer', async () => {
770-
const hash = await sha256.digest(textEncoder.encode('abc'))
771-
const cid = CID.create(1, 112, hash)
772-
assert.throws(
773-
() => cid.buffer,
774-
'Deprecated .buffer property, use .bytes to get Uint8Array instead'
775-
)
776-
})
777699
})

test/test-link.spec.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* globals describe, it */
22

33
import * as Link from '../src/link.js'
4-
import { CID } from '../src/cid.js'
54
import chai from 'chai'
65
import chaiAsPromised from 'chai-as-promised'
76
import { sha256 } from '../src/hashes/sha2.js'
@@ -24,10 +23,6 @@ describe('Link', () => {
2423
it('isLink', () => {
2524
assert.equal(Link.isLink(0), false)
2625
assert.equal(Link.isLink(false), false)
27-
assert.equal(CID.isCID(CID.parse(h1)), true)
28-
assert.equal(CID.isCID(CID.parse(h1).toV0()), true)
29-
30-
assert.equal(CID.isCID(CID.parse(h1).toV1()), true)
3126
})
3227

3328
describe('create', () => {

0 commit comments

Comments
 (0)