Skip to content

Commit

Permalink
BREAKING: rename CodecNumber to CodecCode
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Dec 12, 2020
1 parent 23f3e93 commit bcdb9be
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/base-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict'

/**
* @type {import('./generated-types').NameNumberMap}
* @type {import('./generated-types').NameCodeMap}
*/
const baseTable = Object.freeze({
'identity': 0x00,
Expand Down
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

/** @typedef {import('./generated-types').ConstantNumberMap} ConstantNumberMap */
/** @typedef {import('./generated-types').ConstantCodeMap} ConstantCodeMap */

const { baseTable } = require('./base-table')

const constants = /** @type {ConstantNumberMap} */({})
const constants = /** @type {ConstantCodeMap} */({})

for (const [name, code] of Object.entries(baseTable)) {
const constant = name.toUpperCase().replace(/-/g, '_')
Expand Down
8 changes: 4 additions & 4 deletions src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export type CodecName = 'identity' | 'cidv1' | 'cidv2' | 'cidv3' | 'ip4' | 'tcp'
/**
* Number for all available codecs
*/
export type CodecNumber = 0x00 | 0x01 | 0x02 | 0x03 | 0x04 | 0x06 | 0x11 | 0x12 | 0x13 | 0x14 | 0x15 | 0x16 | 0x17 | 0x18 | 0x19 | 0x1a | 0x1b | 0x1c | 0x1d | 0x1e | 0x21 | 0x22 | 0x23 | 0x29 | 0x2a | 0x2f | 0x30 | 0x31 | 0x32 | 0x33 | 0x35 | 0x36 | 0x37 | 0x38 | 0x50 | 0x51 | 0x55 | 0x56 | 0x60 | 0x63 | 0x70 | 0x71 | 0x72 | 0x78 | 0x7b | 0x7c | 0x81 | 0x82 | 0x83 | 0x84 | 0x85 | 0x86 | 0x90 | 0x91 | 0x92 | 0x93 | 0x94 | 0x95 | 0x96 | 0x97 | 0x98 | 0xb0 | 0xb1 | 0xb2 | 0xc0 | 0xc1 | 0xce | 0xd0 | 0xd1 | 0xd4 | 0xd5 | 0xd6 | 0xe0 | 0xe1 | 0xe2 | 0xe3 | 0xe4 | 0xe5 | 0xe6 | 0xe7 | 0xea | 0xeb | 0xec | 0xed | 0xee | 0xf0 | 0xf1 | 0xfa | 0xfb | 0x0111 | 0x0113 | 0x0114 | 0x0115 | 0x0122 | 0x0129 | 0x012d | 0x012e | 0x0190 | 0x01a5 | 0x01a5 | 0x01bb | 0x01bc | 0x01bd | 0x01be | 0x01bf | 0x01c0 | 0x01cc | 0x01dd | 0x01de | 0x01df | 0x01e0 | 0x0200 | 0x0201 | 0x0301 | 0x1012 | 0x1052 | 0x1053 | 0x1054 | 0x1055 | 0x1100 | 0x1200 | 0x1201 | 0x1202 | 0x1203 | 0x1204 | 0x1300 | 0x1d01 | 0x534d | 0xb201 | 0xb202 | 0xb203 | 0xb204 | 0xb205 | 0xb206 | 0xb207 | 0xb208 | 0xb209 | 0xb20a | 0xb20b | 0xb20c | 0xb20d | 0xb20e | 0xb20f | 0xb210 | 0xb211 | 0xb212 | 0xb213 | 0xb214 | 0xb215 | 0xb216 | 0xb217 | 0xb218 | 0xb219 | 0xb21a | 0xb21b | 0xb21c | 0xb21d | 0xb21e | 0xb21f | 0xb220 | 0xb221 | 0xb222 | 0xb223 | 0xb224 | 0xb225 | 0xb226 | 0xb227 | 0xb228 | 0xb229 | 0xb22a | 0xb22b | 0xb22c | 0xb22d | 0xb22e | 0xb22f | 0xb230 | 0xb231 | 0xb232 | 0xb233 | 0xb234 | 0xb235 | 0xb236 | 0xb237 | 0xb238 | 0xb239 | 0xb23a | 0xb23b | 0xb23c | 0xb23d | 0xb23e | 0xb23f | 0xb240 | 0xb241 | 0xb242 | 0xb243 | 0xb244 | 0xb245 | 0xb246 | 0xb247 | 0xb248 | 0xb249 | 0xb24a | 0xb24b | 0xb24c | 0xb24d | 0xb24e | 0xb24f | 0xb250 | 0xb251 | 0xb252 | 0xb253 | 0xb254 | 0xb255 | 0xb256 | 0xb257 | 0xb258 | 0xb259 | 0xb25a | 0xb25b | 0xb25c | 0xb25d | 0xb25e | 0xb25f | 0xb260 | 0xb301 | 0xb302 | 0xb303 | 0xb304 | 0xb305 | 0xb306 | 0xb307 | 0xb308 | 0xb309 | 0xb30a | 0xb30b | 0xb30c | 0xb30d | 0xb30e | 0xb30f | 0xb310 | 0xb311 | 0xb312 | 0xb313 | 0xb314 | 0xb315 | 0xb316 | 0xb317 | 0xb318 | 0xb319 | 0xb31a | 0xb31b | 0xb31c | 0xb31d | 0xb31e | 0xb31f | 0xb320 | 0xb321 | 0xb322 | 0xb323 | 0xb324 | 0xb325 | 0xb326 | 0xb327 | 0xb328 | 0xb329 | 0xb32a | 0xb32b | 0xb32c | 0xb32d | 0xb32e | 0xb32f | 0xb330 | 0xb331 | 0xb332 | 0xb333 | 0xb334 | 0xb335 | 0xb336 | 0xb337 | 0xb338 | 0xb339 | 0xb33a | 0xb33b | 0xb33c | 0xb33d | 0xb33e | 0xb33f | 0xb340 | 0xb341 | 0xb342 | 0xb343 | 0xb344 | 0xb345 | 0xb346 | 0xb347 | 0xb348 | 0xb349 | 0xb34a | 0xb34b | 0xb34c | 0xb34d | 0xb34e | 0xb34f | 0xb350 | 0xb351 | 0xb352 | 0xb353 | 0xb354 | 0xb355 | 0xb356 | 0xb357 | 0xb358 | 0xb359 | 0xb35a | 0xb35b | 0xb35c | 0xb35d | 0xb35e | 0xb35f | 0xb360 | 0xb361 | 0xb362 | 0xb363 | 0xb364 | 0xb365 | 0xb366 | 0xb367 | 0xb368 | 0xb369 | 0xb36a | 0xb36b | 0xb36c | 0xb36d | 0xb36e | 0xb36f | 0xb370 | 0xb371 | 0xb372 | 0xb373 | 0xb374 | 0xb375 | 0xb376 | 0xb377 | 0xb378 | 0xb379 | 0xb37a | 0xb37b | 0xb37c | 0xb37d | 0xb37e | 0xb37f | 0xb380 | 0xb381 | 0xb382 | 0xb383 | 0xb384 | 0xb385 | 0xb386 | 0xb387 | 0xb388 | 0xb389 | 0xb38a | 0xb38b | 0xb38c | 0xb38d | 0xb38e | 0xb38f | 0xb390 | 0xb391 | 0xb392 | 0xb393 | 0xb394 | 0xb395 | 0xb396 | 0xb397 | 0xb398 | 0xb399 | 0xb39a | 0xb39b | 0xb39c | 0xb39d | 0xb39e | 0xb39f | 0xb3a0 | 0xb3a1 | 0xb3a2 | 0xb3a3 | 0xb3a4 | 0xb3a5 | 0xb3a6 | 0xb3a7 | 0xb3a8 | 0xb3a9 | 0xb3aa | 0xb3ab | 0xb3ac | 0xb3ad | 0xb3ae | 0xb3af | 0xb3b0 | 0xb3b1 | 0xb3b2 | 0xb3b3 | 0xb3b4 | 0xb3b5 | 0xb3b6 | 0xb3b7 | 0xb3b8 | 0xb3b9 | 0xb3ba | 0xb3bb | 0xb3bc | 0xb3bd | 0xb3be | 0xb3bf | 0xb3c0 | 0xb3c1 | 0xb3c2 | 0xb3c3 | 0xb3c4 | 0xb3c5 | 0xb3c6 | 0xb3c7 | 0xb3c8 | 0xb3c9 | 0xb3ca | 0xb3cb | 0xb3cc | 0xb3cd | 0xb3ce | 0xb3cf | 0xb3d0 | 0xb3d1 | 0xb3d2 | 0xb3d3 | 0xb3d4 | 0xb3d5 | 0xb3d6 | 0xb3d7 | 0xb3d8 | 0xb3d9 | 0xb3da | 0xb3db | 0xb3dc | 0xb3dd | 0xb3de | 0xb3df | 0xb3e0 | 0xb401 | 0xb402 | 0xce11 | 0xf101 | 0xf102 | 0x807124 | 0x817124 | 0x947124 | 0x957124 | 0xa27124 | 0xa37124 | 0xb19910;
export type CodecCode = 0x00 | 0x01 | 0x02 | 0x03 | 0x04 | 0x06 | 0x11 | 0x12 | 0x13 | 0x14 | 0x15 | 0x16 | 0x17 | 0x18 | 0x19 | 0x1a | 0x1b | 0x1c | 0x1d | 0x1e | 0x21 | 0x22 | 0x23 | 0x29 | 0x2a | 0x2f | 0x30 | 0x31 | 0x32 | 0x33 | 0x35 | 0x36 | 0x37 | 0x38 | 0x50 | 0x51 | 0x55 | 0x56 | 0x60 | 0x63 | 0x70 | 0x71 | 0x72 | 0x78 | 0x7b | 0x7c | 0x81 | 0x82 | 0x83 | 0x84 | 0x85 | 0x86 | 0x90 | 0x91 | 0x92 | 0x93 | 0x94 | 0x95 | 0x96 | 0x97 | 0x98 | 0xb0 | 0xb1 | 0xb2 | 0xc0 | 0xc1 | 0xce | 0xd0 | 0xd1 | 0xd4 | 0xd5 | 0xd6 | 0xe0 | 0xe1 | 0xe2 | 0xe3 | 0xe4 | 0xe5 | 0xe6 | 0xe7 | 0xea | 0xeb | 0xec | 0xed | 0xee | 0xf0 | 0xf1 | 0xfa | 0xfb | 0x0111 | 0x0113 | 0x0114 | 0x0115 | 0x0122 | 0x0129 | 0x012d | 0x012e | 0x0190 | 0x01a5 | 0x01a5 | 0x01bb | 0x01bc | 0x01bd | 0x01be | 0x01bf | 0x01c0 | 0x01cc | 0x01dd | 0x01de | 0x01df | 0x01e0 | 0x0200 | 0x0201 | 0x0301 | 0x1012 | 0x1052 | 0x1053 | 0x1054 | 0x1055 | 0x1100 | 0x1200 | 0x1201 | 0x1202 | 0x1203 | 0x1204 | 0x1300 | 0x1d01 | 0x534d | 0xb201 | 0xb202 | 0xb203 | 0xb204 | 0xb205 | 0xb206 | 0xb207 | 0xb208 | 0xb209 | 0xb20a | 0xb20b | 0xb20c | 0xb20d | 0xb20e | 0xb20f | 0xb210 | 0xb211 | 0xb212 | 0xb213 | 0xb214 | 0xb215 | 0xb216 | 0xb217 | 0xb218 | 0xb219 | 0xb21a | 0xb21b | 0xb21c | 0xb21d | 0xb21e | 0xb21f | 0xb220 | 0xb221 | 0xb222 | 0xb223 | 0xb224 | 0xb225 | 0xb226 | 0xb227 | 0xb228 | 0xb229 | 0xb22a | 0xb22b | 0xb22c | 0xb22d | 0xb22e | 0xb22f | 0xb230 | 0xb231 | 0xb232 | 0xb233 | 0xb234 | 0xb235 | 0xb236 | 0xb237 | 0xb238 | 0xb239 | 0xb23a | 0xb23b | 0xb23c | 0xb23d | 0xb23e | 0xb23f | 0xb240 | 0xb241 | 0xb242 | 0xb243 | 0xb244 | 0xb245 | 0xb246 | 0xb247 | 0xb248 | 0xb249 | 0xb24a | 0xb24b | 0xb24c | 0xb24d | 0xb24e | 0xb24f | 0xb250 | 0xb251 | 0xb252 | 0xb253 | 0xb254 | 0xb255 | 0xb256 | 0xb257 | 0xb258 | 0xb259 | 0xb25a | 0xb25b | 0xb25c | 0xb25d | 0xb25e | 0xb25f | 0xb260 | 0xb301 | 0xb302 | 0xb303 | 0xb304 | 0xb305 | 0xb306 | 0xb307 | 0xb308 | 0xb309 | 0xb30a | 0xb30b | 0xb30c | 0xb30d | 0xb30e | 0xb30f | 0xb310 | 0xb311 | 0xb312 | 0xb313 | 0xb314 | 0xb315 | 0xb316 | 0xb317 | 0xb318 | 0xb319 | 0xb31a | 0xb31b | 0xb31c | 0xb31d | 0xb31e | 0xb31f | 0xb320 | 0xb321 | 0xb322 | 0xb323 | 0xb324 | 0xb325 | 0xb326 | 0xb327 | 0xb328 | 0xb329 | 0xb32a | 0xb32b | 0xb32c | 0xb32d | 0xb32e | 0xb32f | 0xb330 | 0xb331 | 0xb332 | 0xb333 | 0xb334 | 0xb335 | 0xb336 | 0xb337 | 0xb338 | 0xb339 | 0xb33a | 0xb33b | 0xb33c | 0xb33d | 0xb33e | 0xb33f | 0xb340 | 0xb341 | 0xb342 | 0xb343 | 0xb344 | 0xb345 | 0xb346 | 0xb347 | 0xb348 | 0xb349 | 0xb34a | 0xb34b | 0xb34c | 0xb34d | 0xb34e | 0xb34f | 0xb350 | 0xb351 | 0xb352 | 0xb353 | 0xb354 | 0xb355 | 0xb356 | 0xb357 | 0xb358 | 0xb359 | 0xb35a | 0xb35b | 0xb35c | 0xb35d | 0xb35e | 0xb35f | 0xb360 | 0xb361 | 0xb362 | 0xb363 | 0xb364 | 0xb365 | 0xb366 | 0xb367 | 0xb368 | 0xb369 | 0xb36a | 0xb36b | 0xb36c | 0xb36d | 0xb36e | 0xb36f | 0xb370 | 0xb371 | 0xb372 | 0xb373 | 0xb374 | 0xb375 | 0xb376 | 0xb377 | 0xb378 | 0xb379 | 0xb37a | 0xb37b | 0xb37c | 0xb37d | 0xb37e | 0xb37f | 0xb380 | 0xb381 | 0xb382 | 0xb383 | 0xb384 | 0xb385 | 0xb386 | 0xb387 | 0xb388 | 0xb389 | 0xb38a | 0xb38b | 0xb38c | 0xb38d | 0xb38e | 0xb38f | 0xb390 | 0xb391 | 0xb392 | 0xb393 | 0xb394 | 0xb395 | 0xb396 | 0xb397 | 0xb398 | 0xb399 | 0xb39a | 0xb39b | 0xb39c | 0xb39d | 0xb39e | 0xb39f | 0xb3a0 | 0xb3a1 | 0xb3a2 | 0xb3a3 | 0xb3a4 | 0xb3a5 | 0xb3a6 | 0xb3a7 | 0xb3a8 | 0xb3a9 | 0xb3aa | 0xb3ab | 0xb3ac | 0xb3ad | 0xb3ae | 0xb3af | 0xb3b0 | 0xb3b1 | 0xb3b2 | 0xb3b3 | 0xb3b4 | 0xb3b5 | 0xb3b6 | 0xb3b7 | 0xb3b8 | 0xb3b9 | 0xb3ba | 0xb3bb | 0xb3bc | 0xb3bd | 0xb3be | 0xb3bf | 0xb3c0 | 0xb3c1 | 0xb3c2 | 0xb3c3 | 0xb3c4 | 0xb3c5 | 0xb3c6 | 0xb3c7 | 0xb3c8 | 0xb3c9 | 0xb3ca | 0xb3cb | 0xb3cc | 0xb3cd | 0xb3ce | 0xb3cf | 0xb3d0 | 0xb3d1 | 0xb3d2 | 0xb3d3 | 0xb3d4 | 0xb3d5 | 0xb3d6 | 0xb3d7 | 0xb3d8 | 0xb3d9 | 0xb3da | 0xb3db | 0xb3dc | 0xb3dd | 0xb3de | 0xb3df | 0xb3e0 | 0xb401 | 0xb402 | 0xce11 | 0xf101 | 0xf102 | 0x807124 | 0x817124 | 0x947124 | 0x957124 | 0xa27124 | 0xa37124 | 0xb19910;

export type ConstantNumberMap = Record<CodecConstant, CodecNumber>
export type ConstantCodeMap = Record<CodecConstant, CodecCode>
export type NameUint8ArrayMap = Record<CodecName, Uint8Array>
export type NumberNameMap = Record<CodecNumber, CodecName>
export type NameNumberMap = Record<CodecName, CodecNumber>
export type CodeNameMap = Record<CodecCode, CodecName>
export type NameCodeMap = Record<CodecName, CodecCode>
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict'

/** @typedef {import('./generated-types').CodecName} CodecName */
/** @typedef {import('./generated-types').CodecNumber} CodecNumber */
/** @typedef {import('./generated-types').CodecCode} CodecCode */

const varint = require('varint')
const intTable = require('./int-table')
Expand Down Expand Up @@ -71,7 +71,7 @@ function getCodec (prefixedData) {
/**
* Get the name of the codec (human friendly).
*
* @param {CodecNumber} codec
* @param {CodecCode} codec
* @returns {CodecName|undefined}
*/
function getName (codec) {
Expand All @@ -82,7 +82,7 @@ function getName (codec) {
* Get the code of the codec
*
* @param {CodecName} name
* @returns {CodecNumber}
* @returns {CodecCode}
*/
function getNumber (name) {
const code = codecNameToCodeVarint[name]
Expand All @@ -96,7 +96,7 @@ function getNumber (name) {
* Get the code of the prefixed data.
*
* @param {Uint8Array} prefixedData
* @returns {CodecNumber}
* @returns {CodecCode}
*/
function getCode (prefixedData) {
return varint.decode(prefixedData)
Expand All @@ -119,7 +119,7 @@ function getCodeVarint (codecName) {
/**
* Get the varint of a code.
*
* @param {CodecNumber} code
* @param {CodecCode} code
* @returns {Array.<number>}
*/
function getVarint (code) {
Expand Down
4 changes: 2 additions & 2 deletions src/int-table.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

/** @typedef {import('./generated-types').CodecName} CodecName */
/** @typedef {import('./generated-types').CodecNumber} CodecNumber */
/** @typedef {import('./generated-types').CodecCode} CodecCode */

const { baseTable } = require('./base-table')

/**
* @type {Map<CodecNumber,CodecName>}
* @type {Map<CodecCode,CodecName>}
*/
const nameTable = new Map()

Expand Down
2 changes: 1 addition & 1 deletion test/multicodec.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

/** @typedef {import("../src/generated-types").CodecName} CodecName */
/** @typedef {import("../src/generated-types").CodecNumber} CodecNumber */
/** @typedef {import("../src/generated-types").CodecCode} CodecCode */

const { expect } = require('aegir/utils/chai')
const multicodec = require('../src')
Expand Down
10 changes: 5 additions & 5 deletions tools/update-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ export type CodecName = ${names.join(' | ')};
/**
* Number for all available codecs
*/
export type CodecNumber = ${codes.join(' | ')};
export type CodecCode = ${codes.join(' | ')};
export type ConstantNumberMap = Record<CodecConstant, CodecNumber>
export type ConstantCodeMap = Record<CodecConstant, CodecCode>
export type NameUint8ArrayMap = Record<CodecName, Uint8Array>
export type NumberNameMap = Record<CodecNumber, CodecName>
export type NameNumberMap = Record<CodecName, CodecNumber>
export type CodeNameMap = Record<CodecCode, CodecName>
export type NameCodeMap = Record<CodecName, CodecCode>
`

const tableTemplate = `// DO NOT CHANGE THIS FILE. IT IS GENERATED BY tools/update-table.js
/* eslint quote-props: off */
'use strict'
/**
* @type {import('./generated-types').NameNumberMap}
* @type {import('./generated-types').NameCodeMap}
*/
const baseTable = Object.freeze({
${processed}
Expand Down

0 comments on commit bcdb9be

Please sign in to comment.