Skip to content

Commit

Permalink
fix: update aegir and revert varint
Browse files Browse the repository at this point in the history
This PR upgrade to aegir v31 and reverts varint to 5.0.2 to dedupe upstream.

New base table with 1 new codec "thread"

Notes on the aegir v31 release https://github.com/ipfs/aegir/releases/tag/v31.0.0
  • Loading branch information
hugomrdias committed Mar 2, 2021
1 parent 139c2d5 commit 6b29756
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 52 deletions.
38 changes: 24 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
- uses: gozala/typescript-error-reporter-action@v1.0.4
- run: yarn build
- run: yarn aegir dep-check
- run: npm install
- run: npx aegir lint
- uses: gozala/typescript-error-reporter-action@v1.0.8
- run: npx aegir build
- run: npx aegir dep-check
- uses: ipfs/aegir/actions/bundle-size@master
name: size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
test-node:
Expand All @@ -34,34 +33,45 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- run: npm install
- run: npx aegir test -t node --bail --cov
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npx aegir test -t browser -t webworker --bail
- uses: microsoft/playwright-github-action@v1
- run: npm install
- run: npx aegir test -t browser -t webworker --bail --cov
- uses: codecov/codecov-action@v1
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
- uses: microsoft/playwright-github-action@v1
- run: npm install
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
test-webkit:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: microsoft/playwright-github-action@v1
- run: npm install
- run: npx aegir test -t browser -t webworker --bail -- --browser webkit
test-electron-main:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-main --bail
test-electron-renderer:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-renderer --bail
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls",
"update-table": "node tools/update-table.js"
},
"pre-push": [
Expand All @@ -50,14 +48,23 @@
},
"homepage": "https://github.com/multiformats/js-multicodec#readme",
"dependencies": {
"uint8arrays": "1.1.0",
"varint": "^6.0.0"
"uint8arrays": "^2.1.3",
"varint": "^5.0.2"
},
"devDependencies": {
"aegir": "^29.2.2",
"@types/varint": "^5.0.0",
"aegir": "^31.0.1",
"bent": "^7.3.12",
"pre-push": "~0.1.1"
},
"eslintConfig": {
"extends": "ipfs"
},
"aegir": {
"build": {
"bundlesizeMax": "6.7kB"
}
},
"contributors": [
"Henrique Dias <hacdias@gmail.com>",
"David Dias <daviddias.p@gmail.com>",
Expand Down
1 change: 1 addition & 0 deletions src/generated-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const baseTable = Object.freeze({
'udt': 0x012d,
'utp': 0x012e,
'unix': 0x0190,
'thread': 0x0196,
'p2p': 0x01a5,
'ipfs': 0x01a5,
'https': 0x01bb,
Expand Down
21 changes: 21 additions & 0 deletions src/generated-types.d.ts

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions src/generated-types.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function addPrefix (multicodecStrOrCode, data) {
* @returns {Uint8Array}
*/
function rmPrefix (data) {
varint.decode(data)
varint.decode(/** @type {Buffer} */(data))
return data.slice(varint.decode.bytes)
}

Expand All @@ -60,7 +60,7 @@ function rmPrefix (data) {
* @returns {CodecName}
*/
function getNameFromData (prefixedData) {
const code = varint.decode(prefixedData)
const code = /** @type {CodecCode} */(varint.decode(/** @type {Buffer} */(prefixedData)))
const name = codeToName[code]
if (name === undefined) {
throw new Error(`Code "${code}" not found`)
Expand Down Expand Up @@ -99,7 +99,7 @@ function getCodeFromName (name) {
* @returns {CodecCode}
*/
function getCodeFromData (prefixedData) {
return varint.decode(prefixedData)
return /** @type {CodecCode} */(varint.decode(/** @type {Buffer} */(prefixedData)))
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/** @typedef {import('./generated-types').ConstantCodeMap} ConstantCodeMap */
/** @typedef {import('./generated-types').NameUint8ArrayMap} NameUint8ArrayMap */
/** @typedef {import('./generated-types').CodeNameMap} CodeNameMap */
/** @typedef {import('./generated-types').CodecName} CodecName */
/** @typedef {import('./generated-types').CodecConstant} CodecConstant */

const { baseTable } = require('./generated-table')
const varintEncode = require('./util').varintEncode
Expand All @@ -11,15 +13,17 @@ const nameToVarint = /** @type {NameUint8ArrayMap} */ ({})
const constantToCode = /** @type {ConstantCodeMap} */({})
const codeToName = /** @type {CodeNameMap} */({})

// eslint-disable-next-line guard-for-in
for (const name in baseTable) {
const code = baseTable[name]
nameToVarint[name] = varintEncode(code)
const codecName = /** @type {CodecName} */(name)
const code = baseTable[codecName]
nameToVarint[codecName] = varintEncode(code)

const constant = name.toUpperCase().replace(/-/g, '_')
const constant = /** @type {CodecConstant} */(codecName.toUpperCase().replace(/-/g, '_'))
constantToCode[constant] = code

if (!codeToName[code]) {
codeToName[code] = name
codeToName[code] = codecName
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ module.exports = {
varintEncode
}

/**
* @param {Uint8Array} buf
*/
function uint8ArrayToNumber (buf) {
return parseInt(uint8ArrayToString(buf, 'base16'), 16)
}

/**
* @param {number} num
*/
function numberToUint8Array (num) {
let hexString = num.toString(16)
if (hexString.length % 2 === 1) {
Expand All @@ -23,10 +29,16 @@ function numberToUint8Array (num) {
return uint8ArrayFromString(hexString, 'base16')
}

/**
* @param {Uint8Array} input
*/
function varintUint8ArrayEncode (input) {
return Uint8Array.from(varint.encode(uint8ArrayToNumber(input)))
}

/**
* @param {number} num
*/
function varintEncode (num) {
return Uint8Array.from(varint.encode(num))
}
3 changes: 2 additions & 1 deletion test/multicodec.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ describe('multicodec', () => {
})

it('returns all codec numbers from names', () => {
// eslint-disable-next-line guard-for-in
for (const name in nameToCode) {
expect(multicodec.getCodeFromName(/** @type {CodecName} */(name))).to.eql(nameToCode[name])
expect(multicodec.getCodeFromName(/** @type {CodecName} */(name))).to.eql(nameToCode[/** @type {CodecName} */(name)])
}
})

Expand Down
8 changes: 4 additions & 4 deletions tools/update-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ const run = async () => {
/**
* Constant names for all available codecs
*/
export type CodecConstant = ${names.map(n => `${n.toUpperCase().replace(/-/g, '_')}`).join(' | ')};
export type CodecConstant = ${names.map(n => `${n.toUpperCase().replace(/-/g, '_')}`).join(' | ')}
/**
* Names for all available codecs
*/
export type CodecName = ${names.join(' | ')};
export type CodecName = ${names.join(' | ')}
/**
* Number for all available codecs
*/
export type CodecCode = ${codes.join(' | ')};
export type CodecCode = ${codes.join(' | ')}
export type ConstantCodeMap = Record<CodecConstant, CodecCode>
export type NameUint8ArrayMap = Record<CodecName, Uint8Array>
Expand All @@ -64,7 +64,7 @@ ${processed}
module.exports = { baseTable }
`

fs.writeFileSync(path.join(__dirname, '../src/generated-types.ts'), typesTemplate)
fs.writeFileSync(path.join(__dirname, '../src/generated-types.d.ts'), typesTemplate)
fs.writeFileSync(path.join(__dirname, '../src/generated-table.js'), tableTemplate)
}

Expand Down

0 comments on commit 6b29756

Please sign in to comment.