Skip to content

Commit

Permalink
yet another attempt to make tools happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Jun 13, 2022
1 parent 434f4c0 commit 16a20d8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 32 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@
"standard": {
"ignore": [
"dist",
"vendor",
"**/interface.js"
"vendor"
]
},
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion src/block.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bytes as binary, CID } from './index.js'
// Linter can see that API is used in types.
// eslint-disable-next-line
import * as API from './interface.js'
import * as API from './block/interface.js'

const readonly = ({ enumerable = true, configurable = false } = {}) => ({
enumerable,
Expand Down
16 changes: 6 additions & 10 deletions src/codecs/json.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-check

/**
* @template T
* @typedef {import('./interface').ByteView<T>} ByteView
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
import * as API from './interface.js'

const textEncoder = new TextEncoder()
const textDecoder = new TextDecoder()
Expand All @@ -14,13 +10,13 @@ export const code = 0x0200
/**
* @template T
* @param {T} node
* @returns {ByteView<T>}
* @returns {API.ByteView<T>}
*/
export const encode = (node) => textEncoder.encode(JSON.stringify(node))
export const encode = node => textEncoder.encode(JSON.stringify(node))

/**
* @template T
* @param {ByteView<T>} data
* @param {API.ByteView<T>} data
* @returns {T}
*/
export const decode = (data) => JSON.parse(textDecoder.decode(data))
export const decode = data => JSON.parse(textDecoder.decode(data))
17 changes: 6 additions & 11 deletions src/codecs/raw.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
// @ts-check

// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
import * as API from './interface.js'
import { coerce } from '../bytes.js'

/**
* @template T
* @typedef {import('./interface').ByteView<T>} ByteView
*/

export const name = 'raw'
export const code = 0x55

/**
* @param {Uint8Array} node
* @returns {ByteView<Uint8Array>}
* @returns {API.ByteView<Uint8Array>}
*/
export const encode = (node) => coerce(node)
export const encode = node => coerce(node)

/**
* @param {ByteView<Uint8Array>} data
* @param {API.ByteView<Uint8Array>} data
* @returns {Uint8Array}
*/
export const decode = (data) => coerce(data)
export const decode = data => coerce(data)
9 changes: 3 additions & 6 deletions src/hashes/hasher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as Digest from './digest.js'
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
import * as API from './interface.js'

/**
* @template {string} Name
Expand All @@ -17,7 +19,7 @@ export const from = ({ name, code, encode }) => new Hasher(name, code, encode)
* @template {string} Name
* @template {number} Code
* @class
* @implements {MultihashHasher<Code>}
* @implements {API.MultihashHasher<Code>}
*/
export class Hasher {
/**
Expand Down Expand Up @@ -50,11 +52,6 @@ export class Hasher {
}
}

/**
* @template {number} Alg
* @typedef {import('./interface').MultihashHasher} MultihashHasher
*/

/**
* @template T
* @typedef {Promise<T>|T} Await
Expand Down
4 changes: 4 additions & 0 deletions src/hashes/interface.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// this is dummy module overlayed by interface.ts
// just trying to stop eslint from campaining about
// no named exports
// eslint-disable-next-line no-void, no-shadow-restricted-names
export const undefined = void 0
2 changes: 0 additions & 2 deletions src/hashes/sha2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-check

import crypto from 'crypto'
import { from } from './hasher.js'
import { coerce } from '../bytes.js'
Expand Down

0 comments on commit 16a20d8

Please sign in to comment.