Skip to content

Commit

Permalink
fix: changes for new lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerMauve authored and rvagg committed Oct 12, 2022
1 parent 163d463 commit e6c9957
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 30 deletions.
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

9 changes: 6 additions & 3 deletions src/bases/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as API from './interface.js'
* Class represents both BaseEncoder and MultibaseEncoder meaning it
* can be used to encode to multibase or base encode without multibase
* prefix.
*
* @class
* @template {string} Base
* @template {string} Prefix
Expand Down Expand Up @@ -46,6 +47,8 @@ class Encoder {
* Class represents both BaseDecoder and MultibaseDecoder so it could be used
* to decode multibases (with matching prefix) or just base decode strings
* with corresponding base encoding.
*
* @class
* @template {string} Base
* @template {string} Prefix
* @implements {API.MultibaseDecoder<Prefix>}
Expand Down Expand Up @@ -193,7 +196,7 @@ export class Codec {
/**
* @template {string} Base
* @template {string} Prefix
* @param {Object} options
* @param {object} options
* @param {Base} options.name
* @param {Prefix} options.prefix
* @param {(bytes:Uint8Array) => string} options.encode
Expand All @@ -206,7 +209,7 @@ export const from = ({ name, prefix, encode, decode }) =>
/**
* @template {string} Base
* @template {string} Prefix
* @param {Object} options
* @param {object} options
* @param {Base} options.name
* @param {Prefix} options.prefix
* @param {string} options.alphabet
Expand Down Expand Up @@ -324,7 +327,7 @@ const encode = (data, alphabet, bitsPerChar) => {
*
* @template {string} Base
* @template {string} Prefix
* @param {Object} options
* @param {object} options
* @param {Base} options.name
* @param {Prefix} options.prefix
* @param {string} options.alphabet
Expand Down
13 changes: 7 additions & 6 deletions src/bases/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export interface BaseEncoder {
/**
* Base encodes to a **plain** (and not a multibase) string. Unlike
* `encode` no multibase prefix is added.
*
* @param bytes
*/
baseEncode(bytes: Uint8Array): string
baseEncode: (bytes: Uint8Array) => string
}

/**
Expand All @@ -20,9 +21,10 @@ export interface BaseDecoder {
/**
* Decodes **plain** (and not a multibase) string. Unlike
* decode
*
* @param text
*/
baseDecode(text: string): Uint8Array
baseDecode: (text: string) => Uint8Array
}

/**
Expand Down Expand Up @@ -58,7 +60,7 @@ export interface MultibaseEncoder<Prefix extends string> {
* Encodes binary data into **multibase** string (which will have a
* prefix added).
*/
encode(bytes: Uint8Array): Multibase<Prefix>
encode: (bytes: Uint8Array) => Multibase<Prefix>
}

/**
Expand All @@ -71,9 +73,10 @@ export interface MultibaseDecoder<Prefix extends string> {
/**
* Decodes **multibase** string (which must have a multibase prefix added).
* If prefix does not match
*
* @param multibase
*/
decode(multibase: Multibase<Prefix>): Uint8Array
decode: (multibase: Multibase<Prefix>) => Uint8Array
}

/**
Expand All @@ -86,7 +89,6 @@ export interface MultibaseCodec<Prefix extends string> {
decoder: MultibaseDecoder<Prefix>
}


export interface UnibaseDecoder<Prefix extends string> extends MultibaseDecoder<Prefix> {
// Reserve this property so it can be used to derive type.
readonly decoders?: null
Expand All @@ -97,4 +99,3 @@ export interface UnibaseDecoder<Prefix extends string> extends MultibaseDecoder<
export interface CombobaseDecoder<Prefix extends string> extends MultibaseDecoder<Prefix> {
readonly decoders: Record<Prefix, UnibaseDecoder<Prefix>>
}

12 changes: 7 additions & 5 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const tree = function * (source, base) {
}

/**
*
* @template T
* @param {T} source
* @param {string[]} path
Expand Down Expand Up @@ -100,7 +101,7 @@ const get = (source, path) => {
*/
class Block {
/**
* @param {Object} options
* @param {object} options
* @param {CID<T, C, A, V>} options.cid
* @param {API.ByteView<T>} options.bytes
* @param {T} options.value
Expand Down Expand Up @@ -131,6 +132,7 @@ class Block {
}

/**
*
* @param {string} [path]
* @return {API.BlockCursorView<unknown>}
*/
Expand All @@ -143,7 +145,7 @@ class Block {
* @template {unknown} T - Logical type of the data encoded in the block
* @template {number} Code - multicodec code corresponding to codec used to encode the block
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
* @param {Object} options
* @param {object} options
* @param {T} options.value
* @param {API.BlockEncoder<Code, T>} options.codec
* @param {API.MultihashHasher<Alg>} options.hasher
Expand All @@ -169,7 +171,7 @@ const encode = async ({ value, codec, hasher }) => {
* @template {unknown} T - Logical type of the data encoded in the block
* @template {number} Code - multicodec code corresponding to codec used to encode the block
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
* @param {Object} options
* @param {object} options
* @param {API.ByteView<T>} options.bytes
* @param {API.BlockDecoder<Code, T>} options.codec
* @param {API.MultihashHasher<Alg>} options.hasher
Expand All @@ -188,7 +190,7 @@ const decode = async ({ bytes, codec, hasher }) => {
}

/**
* @typedef {Object} RequiredCreateOptions
* @typedef {object} RequiredCreateOptions
* @property {CID} options.cid
*/

Expand Down Expand Up @@ -220,7 +222,7 @@ const createUnsafe = ({ bytes, cid, value: maybeValue, codec }) => {
* @template {number} Code - multicodec code corresponding to codec used to encode the block
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template {API.Version} V - CID version
* @param {Object} options
* @param {object} options
* @param {API.Link<T, Code, Alg, V>} options.cid
* @param {API.ByteView<T>} options.bytes
* @param {API.BlockDecoder<Code, T>} options.codec
Expand Down
16 changes: 15 additions & 1 deletion src/cid.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class CID {
*/
static isCID (value) {
deprecate(/^0\.0/, IS_CID_DEPRECATION)
return !!(value && (value[cidSymbol] || value.asCID === value))
return Boolean(value && (value[cidSymbol] || value.asCID === value))
}

get toBaseEncodedString () {
Expand Down Expand Up @@ -255,6 +255,15 @@ export class CID {
}

/**
* Takes any input `value` and returns a `CID` instance if it was
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
* it will return value back. If `value` is not instance of this CID
* class, but is compatible CID it will return new instance of this
* `CID` class. Otherwise returs null.
*
* This allows two different incompatible versions of CID library to
* co-exist and interop as long as binary interface is compatible.
*
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
Expand Down Expand Up @@ -298,6 +307,7 @@ export class CID {
}

/**
*
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
Expand Down Expand Up @@ -334,6 +344,7 @@ export class CID {

/**
* Simplified version of `create` for CIDv0.
*
* @template {unknown} [T=unknown]
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
Expand All @@ -344,6 +355,7 @@ export class CID {

/**
* Simplified version of `create` for CIDv1.
*
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
Expand All @@ -361,6 +373,7 @@ export class CID {
*
* An error will be thrown if the bytes provided do not contain a valid
* binary representation of a CID.
*
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
Expand Down Expand Up @@ -603,6 +616,7 @@ const version = '0.0.0-dev'
* @param {string} message
*/
const deprecate = (range, message) => {
/* eslint-disable no-console */
if (range.test(version)) {
console.warn(message)
/* c8 ignore next 3 */
Expand Down
4 changes: 2 additions & 2 deletions src/codecs/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import type { ByteView } from '../block/interface'
export interface BlockEncoder<Code extends number, T> {
name: string
code: Code
encode(data: T): ByteView<T>
encode: (data: T) => ByteView<T>
}

/**
* IPLD decoder part of the codec.
*/
export interface BlockDecoder<Code extends number, T> {
code: Code
decode(bytes: ByteView<T>): T
decode: (bytes: ByteView<T>) => T
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/hashes/digest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as varint from '../varint.js'

/**
* Creates a multihash digest.
*
* @template {number} Code
* @param {Code} code
* @param {Uint8Array} digest
Expand All @@ -22,6 +23,7 @@ export const create = (code, digest) => {

/**
* Turns bytes representation of multihash digest into an instance.
*
* @param {Uint8Array} multihash
* @returns {MultihashDigest}
*/
Expand Down Expand Up @@ -67,6 +69,7 @@ export const equals = (a, b) => {
/**
* Represents a multihash digest which carries information about the
* hashing alogrithm and an actual hash digest.
*
* @template {number} Code
* @template {number} Size
* @class
Expand All @@ -75,6 +78,7 @@ export const equals = (a, b) => {
export class Digest {
/**
* Creates a multihash digest.
*
* @param {Code} code
* @param {Size} size
* @param {Uint8Array} digest
Expand Down
2 changes: 1 addition & 1 deletion src/hashes/hasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Digest from './digest.js'
/**
* @template {string} Name
* @template {number} Code
* @param {Object} options
* @param {object} options
* @param {Name} options.name
* @param {Code} options.code
* @param {(input: Uint8Array) => Await<Uint8Array>} options.encode
Expand Down
4 changes: 2 additions & 2 deletions src/hashes/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface MultihashHasher<Code extends number = number> {
*
* @param {Uint8Array} input
*/
digest(input: Uint8Array): Promise<MultihashDigest<Code>> | MultihashDigest<Code>
digest: (input: Uint8Array) => Promise<MultihashDigest<Code>> | MultihashDigest<Code>

/**
* Name of the multihash
Expand All @@ -68,5 +68,5 @@ export interface MultihashHasher<Code extends number = number> {
* impractical e.g. implementation of Hash Array Mapped Trie (HAMT).
*/
export interface SyncMultihashHasher<Code extends number = number> extends MultihashHasher<Code> {
digest(input: Uint8Array): MultihashDigest<Code>
digest: (input: Uint8Array) => MultihashDigest<Code>
}
2 changes: 2 additions & 0 deletions src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ const SHA_256_CODE = 0x12

/**
* Simplified version of `create` for CIDv0.
*
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
* @returns {API.LegacyLink}
*/
export const createLegacy = digest => CID.create(0, DAG_PB_CODE, digest)

/**
* Simplified version of `create` for CIDv1.
*
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
Expand Down
3 changes: 2 additions & 1 deletion src/traversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { base58btc } from './bases/base58.js'
*/

/**
* @param {Object} options
* @template T
* @param {object} options
* @param {CID} options.cid
* @param {(cid: CID) => Promise<BlockView|null>} options.load
* @param {Set<string>} [options.seen]
Expand Down
1 change: 0 additions & 1 deletion test/test-multibase-spec.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-env mocha */
'use strict'

import { bases } from 'multiformats/basics'
import { fromString } from 'multiformats/bytes'
Expand Down

0 comments on commit e6c9957

Please sign in to comment.