Skip to content

Commit

Permalink
fix: additional lint items from Link interface work
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 12, 2022
1 parent c12db2a commit 91f677b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function * tree (source, base) {
* @template T
* @param {T} source
* @param {string[]} path
* @return {API.BlockCursorView<unknown>}
* @returns {API.BlockCursorView<unknown>}
*/
function get (source, path) {
let node = /** @type {Record<string, any>} */(source)
Expand Down Expand Up @@ -153,7 +153,7 @@ class Block {
/**
*
* @param {string} [path]
* @return {API.BlockCursorView<unknown>}
* @returns {API.BlockCursorView<unknown>}
*/
get (path = '/') {
return get(this.value, path.split('/').filter(Boolean))
Expand Down
11 changes: 6 additions & 5 deletions src/block/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
/* eslint-disable no-use-before-define */
import { Link, Version } from '../link/interface.js'
import { CID } from "../cid.js"
import { CID } from '../cid.js'

/**
* A byte-encoded representation of some type of `Data`.
Expand All @@ -14,6 +14,8 @@ import { CID } from "../cid.js"
*/
export interface ByteView<Data> extends Uint8Array, Phantom<Data> {}

declare const Marker: unique symbol

/**
* A utility type to retain an unused type parameter `T`.
* Similar to [phantom type parameters in Rust](https://doc.rust-lang.org/rust-by-example/generics/phantom.html).
Expand All @@ -32,7 +34,6 @@ export interface Phantom<T> {
// type contstraint.
[Marker]?: T
}
declare const Marker: unique symbol

/**
* Represents an IPLD block (including its CID) that can be decoded to data of
Expand Down Expand Up @@ -66,7 +67,7 @@ export interface BlockView<
cid: CID<T, C, A, V>
value: T

links(): Iterable<[string, CID]>
tree(): Iterable<string>
get(path:string): BlockCursorView<unknown>
links: () => Iterable<[string, CID]>
tree: () => Iterable<string>
get: (path: string) => BlockCursorView<unknown>
}
4 changes: 2 additions & 2 deletions src/cid.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const format = (link, base) => {
}
}

/** @type {WeakMap<API.UnknownLink, Map<string, string>>} */
/** @type {WeakMap<API.UnknownLink, Map<string, string>>} */
const cache = new WeakMap()

/**
Expand Down Expand Up @@ -174,7 +174,7 @@ export class CID {
* @template {API.Version} Version
* @param {API.Link<Data, Format, Alg, Version>} self
* @param {unknown} other
* @returns {other is cid}
* @returns {other is CID}
*/
static equals (self, other) {
const unknown =
Expand Down
6 changes: 2 additions & 4 deletions src/hashes/digest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const create = (code, digest) => {
* @param {Uint8Array} multihash
* @returns {MultihashDigest}
*/
export const decode = multihash => {
export const decode = (multihash) => {
const bytes = coerce(multihash)
const [code, sizeOffset] = varint.decode(bytes)
const [size, digestOffset] = varint.decode(bytes.subarray(sizeOffset))
Expand All @@ -49,9 +49,7 @@ export const equals = (a, b) => {
if (a === b) {
return true
} else {
const data = /** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */ (
b
)
const data = /** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */(b)

return (
a.code === data.code &&
Expand Down
12 changes: 5 additions & 7 deletions src/link/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { MultihashDigest } from '../hashes/interface'
import type { MultibaseEncoder, MultibaseDecoder, Multibase } from '../bases/interface'
import type { Phantom, ByteView } from '../block/interface'


export type { MultihashDigest, MultibaseEncoder, MultibaseDecoder }
export type Version = 0 | 1

Expand Down Expand Up @@ -33,14 +32,13 @@ export interface Link<
readonly byteLength: number
readonly bytes: ByteView<Link<Data, Format, Alg, V>>

equals: (other: unknown) => other is Link<Data, Format, Alg, Version>

equals(other: unknown): other is Link<Data, Format, Alg, Version>

toString<Prefix extends string>(base?: MultibaseEncoder<Prefix>): ToString<Link<Data, Format, Alg, Version>, Prefix>
toJSON(): { version: V, code: Format, hash: Uint8Array }
link(): Link<Data, Format, Alg, V>
toString: <Prefix extends string>(base?: MultibaseEncoder<Prefix>) => ToString<Link<Data, Format, Alg, Version>, Prefix>
toJSON: () => { version: V, code: Format, hash: Uint8Array }
link: () => Link<Data, Format, Alg, V>

toV1(): Link<Data, Format, Alg, 1>
toV1: () => Link<Data, Format, Alg, 1>
}

export interface LegacyLink<T extends unknown = unknown> extends Link<T, DAG_PB, SHA_256, 0> {
Expand Down
1 change: 0 additions & 1 deletion src/traversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { base58btc } from './bases/base58.js'
*/

/**
* @template T
* @param {object} options
* @param {CID} options.cid
* @param {(cid: CID) => Promise<BlockView|null>} options.load
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
],
"multiformats/*": [
"./src/*.js"
],

]
}
},
"include": [
Expand Down

0 comments on commit 91f677b

Please sign in to comment.