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

fix: regressions introduced by new releases of CID & multicodec #3442

Merged
merged 15 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion examples/custom-ipld-formats/daemon-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const codecName = 'dag-test'
const codecNumber = 392091

const baseTable = require('multicodec/src/base-table.json')
const { baseTable } = require('multicodec/src/base-table')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is working as expected. CI says:

example-custom-ipld-formats: Error: `put` requires a format
example-custom-ipld-formats:     at IPLDResolver.put (/home/travis/build/ipfs/js-ipfs/node_modules/ipld/src/index.js:180:13)
example-custom-ipld-formats:     at put (/home/travis/build/ipfs/js-ipfs/node_modules/ipfs-core/src/components/dag/put.js:75:30)
example-custom-ipld-formats:     at Object.put (/home/travis/build/ipfs/js-ipfs/node_modules/ipfs-core/src/utils.js:231:46)
example-custom-ipld-formats:     at main (/home/travis/build/ipfs/js-ipfs/examples/custom-ipld-formats/in-process-node.js:49:30)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to see what is happening here in a couple of hours

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, an Object.freeze is exported from base-table. This means that the object is not changed by the following change

baseTable[codecName] = codecNumber

// now require modules as usual
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-ipld-formats/in-process-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const codecName = 'dag-test'
const codecNumber = 392091

const baseTable = require('multicodec/src/base-table.json')
const { baseTable } = require('multicodec/src/base-table')
baseTable[codecName] = codecNumber

// now require modules as usual
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-ipld-formats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test-ipfs-example": "^2.0.3"
},
"dependencies": {
"cids": "1.0.2",
"cids": "^1.0.0",
"ipfs-cli": "^0.1.0",
"ipfs-core": "^0.2.1",
"ipfs-http-client": "^48.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"cids": "1.0.2",
"cids": "^1.0.0",
"delay": "^4.4.0",
"dirty-chai": "^2.0.1",
"err-code": "^2.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"bignumber.js": "^9.0.0",
"byteman": "^1.3.5",
"cid-tool": "^1.0.0",
"cids": "1.0.2",
"cids": "^1.0.0",
"debug": "^4.1.1",
"err-code": "^2.0.3",
"execa": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-cli/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const escapeControlCharacters = (str) => {
* CID properties
*
* @param {object} obj - all keys/values in this object will be have control characters stripped
* @param {string} cidBase - any encountered CIDs will be stringified using this base
* @param {import('cids').BaseNameOrCode} cidBase - any encountered CIDs will be stringified using this base
* @returns {object}
*/
const makeEntriesPrintable = (obj, cidBase = 'base58btc') => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"any-signal": "^2.0.0",
"blob-to-it": "^1.0.1",
"browser-readablestream-to-it": "^1.0.1",
"cids": "1.0.2",
"cids": "^1.0.0",
"err-code": "^2.0.3",
"ipfs-utils": "^5.0.0",
"it-all": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core-utils/src/cid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const CID = require('cids')
*
* @param {CID|Uint8Array|string} input - The CID to encode
* @param {Object} [options] - Optional options
* @param {string} [options.base] - Name of multibase codec to encode the CID with
* @param {import('cids').BaseNameOrCode} [options.base] - Name of multibase codec to encode the CID with
* @param {boolean} [options.upgrade] - Automatically upgrade v0 CIDs to v1 when
* necessary. Default: true.
* @returns {string} - CID in string representation
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"array-shuffle": "^1.0.1",
"bignumber.js": "^9.0.0",
"cbor": "^5.1.0",
"cids": "1.0.2",
"cids": "^1.0.0",
"class-is": "^1.1.0",
"dag-cbor-links": "^2.0.0",
"datastore-core": "^2.0.0",
Expand Down Expand Up @@ -107,7 +107,7 @@
"multiaddr": "^8.0.0",
"multiaddr-to-uri": "^6.0.0",
"multibase": "^3.0.0",
"multicodec": "2.0.4",
"multicodec": "^2.0.1",
"multihashing-async": "^2.0.1",
"native-abort-controller": "~0.0.3",
"p-queue": "^6.6.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module.exports = ({ ipld, name }) => {
*
* @typedef {Object} ResolveSettings
* @property {boolean} [recursive=true] - Resolve until result is an IPFS name.
* @property {string} [cidBase='base58btc'] - Multibase codec name the CID in the resolved path will be encoded with.
* @property {import('cids').BaseNameOrCode} [cidBase='base58btc'] - Multibase codec name the CID in the resolved path will be encoded with.
*
* @typedef {import('.').AbortOptions} AbortOptions
*/
4 changes: 2 additions & 2 deletions packages/ipfs-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dependencies": {
"any-signal": "^2.0.0",
"bignumber.js": "^9.0.0",
"cids": "1.0.2",
"cids": "^1.0.0",
"debug": "^4.1.1",
"form-data": "^3.0.0",
"ipfs-core-utils": "^0.5.3",
Expand All @@ -68,7 +68,7 @@
"merge-options": "^2.0.0",
"multiaddr": "^8.0.0",
"multibase": "^3.0.0",
"multicodec": "2.0.4",
"multicodec": "^2.0.1",
"multihashes": "^3.0.1",
"nanoid": "^3.1.12",
"native-abort-controller": "~0.0.3",
Expand Down
1 change: 1 addition & 0 deletions packages/ipfs-http-client/src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = configure((api, opts) => {
const cid = new CID(options.cid)
encodingOptions = {
...options,
// @ts-expect-error - https://github.com/multiformats/js-cid/pull/138
format: multicodec.getName(cid.code),
hashAlg: multihash.decode(cid.multihash).name
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/lib/ipld-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ module.exports = ({ formats = [], loadFormat = noop } = {}) => {
/**
* Attempts to load an IPLD format for the passed CID
*
* @param {string} codec - The code to load the format for
* @param {import('multicodec').CodecName} codec - The code to load the format for
* @returns {Promise<object>} - An IPLD format
*/
const loadResolver = async (codec) => {
// @ts-ignore - codec is a string and not a CodecName
const number = multicodec.getNumber(codec)
const format = configuredFormats[number] || await loadFormat(codec)

Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@hapi/ammo": "^5.0.1",
"@hapi/boom": "^9.1.0",
"@hapi/hapi": "^20.0.0",
"cids": "1.0.2",
"cids": "^1.0.0",
"debug": "^4.1.1",
"hapi-pino": "^8.3.0",
"ipfs-core-utils": "^0.5.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@hapi/boom": "^9.1.0",
"@hapi/content": "^5.0.2",
"@hapi/hapi": "^20.0.0",
"cids": "1.0.2",
"cids": "^1.0.0",
"debug": "^4.1.1",
"dlv": "^1.1.3",
"err-code": "^2.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-server/src/api/resources/block.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const multihash = require('multihashing-async').multihash
const codecs = require('multicodec/src/base-table.json')
const { baseTable: codecs } = require('multicodec/src/base-table.js')
const multipart = require('../../utils/multipart-request-parser')
const Joi = require('../../utils/joi')
const Boom = require('@hapi/boom')
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-message-port-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"dep-check": "aegir dep-check -i typescript -i rimraf"
},
"dependencies": {
"cids": "1.0.2",
"cids": "^1.0.0",
"ipld-block": "^0.11.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-message-port-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"devDependencies": {
"@types/it-all": "^1.0.0",
"aegir": "^29.2.2",
"cids": "1.0.2",
"cids": "^1.0.0",
"ipfs-utils": "^5.0.0",
"rimraf": "^3.0.2",
"typescript": "4.0.x"
Expand Down