Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d5a8668

Browse files
committed
fix: type check ipfs-core
1 parent 7ae81dc commit d5a8668

File tree

8 files changed

+37
-15
lines changed

8 files changed

+37
-15
lines changed

packages/ipfs-core/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
},
3333
"scripts": {
3434
"lint": "aegir lint",
35-
"build": "aegir build",
35+
"check": "tsc --noEmit",
36+
"build": "npm run build:bundle && npm run build:types",
37+
"build:bundle": "aegir build",
38+
"build:types": "tsc --emitDeclarationOnly --declarationDir dist",
3639
"test": "aegir test",
3740
"test:node": "aegir test -t node",
3841
"test:browser": "aegir test -t browser",
@@ -132,5 +135,12 @@
132135
"optionalDependencies": {
133136
"prom-client": "^12.0.0",
134137
"prometheus-gc-stats": "^0.6.0"
138+
},
139+
"typesVersions": {
140+
"*": {
141+
"*": [
142+
"dist/*"
143+
]
144+
}
135145
}
136146
}

packages/ipfs-core/src/components/add-all/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Parses chunker string into options used by DAGBuilder in ipfs-unixfs-engine
55
*
66
*
7-
* @param {string} chunker - Chunker algorithm supported formats:
7+
* @param {string} [chunker] - Chunker algorithm supported formats:
88
* "size-{size}"
99
* "rabin"
1010
* "rabin-{avg}"

packages/ipfs-core/src/components/add.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ module.exports = ({ addAll }) => {
3535
* @type {Add<{}>}
3636
*/
3737
async function add (source, options) { // eslint-disable-line require-await
38-
return last(addAll(source, options))
38+
/** @type {UnixFSEntry} - Could be undefined if empty */
39+
const result = (await last(addAll(source, options)))
40+
return result
3941
}
4042
return add
4143
}

packages/ipfs-core/src/components/dag/get.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const toCidAndPath = require('ipfs-core-utils/src/to-cid-and-path')
3838
*/
3939

4040
module.exports = ({ ipld, preload }) => {
41-
return withTimeoutOption(async function get (ipfsPath, options = {}) {
41+
/** @type {Get} */
42+
const get = async function get (ipfsPath, options = {}) {
4243
const {
4344
cid,
4445
path
@@ -53,16 +54,19 @@ module.exports = ({ ipld, preload }) => {
5354
}
5455

5556
if (options.path) {
56-
if (options.localResolve) {
57-
return first(ipld.resolve(cid, options.path))
58-
}
59-
60-
return last(ipld.resolve(cid, options.path))
57+
const result = options.localResolve
58+
/** @type {DagEntry} - first will return undefined if empty */
59+
? (await first(ipld.resolve(cid, options.path)))
60+
/** @type {DagEntry} - last will return undefined if empty */
61+
: (await last(ipld.resolve(cid, options.path)))
62+
return result
6163
}
6264

6365
return {
6466
value: await ipld.get(cid, options),
6567
remainderPath: ''
6668
}
67-
})
69+
}
70+
71+
return withTimeoutOption(get)
6872
}

packages/ipfs-core/src/components/init.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ module.exports = ({
198198

199199
/**
200200
* @param {IPFSRepo} repo
201-
* @param {InitOptions} options
201+
* @param {Object} options
202202
* @param {PrivateKey} options.privateKey
203203
* @param {boolean} [options.emptyRepo]
204204
* @param {number} [options.bits=2048] - Number of bits to use in the generated key
@@ -231,8 +231,6 @@ async function initNewRepo (repo, { privateKey, emptyRepo, algorithm, bits, prof
231231
PrivKey: uint8ArrayToString(peerId.privKey.bytes, 'base64pad')
232232
}
233233

234-
privateKey = peerId.privKey
235-
236234
log('peer identity: %s', config.Identity.PeerID)
237235

238236
await repo.init(config)

packages/ipfs-core/src/components/pin/add.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module.exports = ({ addAll }) =>
1313
* @returns {Promise<CID>}
1414
*/
1515
async (path, options = {}) =>
16-
await last(addAll({ path, ...options }, options))
16+
/** @type {CID} - Need to loosen check here because it could be void */
17+
(await last(addAll({ path, ...options }, options)))
1718

1819
/**
1920
* @typedef {AddSettings & AbortOptions} AddOptions

packages/ipfs-core/src/components/pin/rm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = ({ rmAll }) =>
2323
* ```
2424
*/
2525
async (path, options) =>
26-
await last(rmAll({ path, ...options }, options))
26+
/** @type {CID} - Need to loosen check here because it could be void */
27+
(await last(rmAll({ path, ...options }, options)))
2728

2829
/**
2930
* @typedef {RmSettings & AbortOptions} RmOptions

packages/ipfs-core/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../typescript.json",
3+
"include": [
4+
"./src"
5+
]
6+
}

0 commit comments

Comments
 (0)