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

Commit 7dd1e72

Browse files
committed
chore: revert ts-expect-error
1 parent c2ec920 commit 7dd1e72

File tree

8 files changed

+71
-62
lines changed

8 files changed

+71
-62
lines changed

examples/types-use-ipfs-from-ts/src/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default async function main() {
1414

1515
console.log('Added file:', file.path, file.cid.toString())
1616
try {
17+
// @ts-expect-error CID has no toUpperCase method
1718
file.cid.toUpperCase()
1819
} catch (error) {
1920

examples/types-use-ipfs-from-typed-js/src/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ async function main () {
1717

1818
console.log('Added file:', file.path, file.cid.toString())
1919
try {
20+
// @ts-expect-error CID has no toUpperCase method
2021
file.cid.toUpperCase()
2122
} catch(error) {
2223

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
88
const mergeOptions = require('merge-options').bind({ ignoreUndefined: true })
99

1010
/**
11-
* @param {Object} config
12-
* @param {import('..').Block} config.block
13-
* @param {import('..').GCLock} config.gcLock
14-
* @param {import('..').Preload} config.preload
15-
* @param {import('..').Pin} config.pin
16-
* @param {import('ipfs-interface/src/root').ShardingOptions} [config.options]
11+
* @typedef {Object} Context
12+
* @property {import('..').Block} block
13+
* @property {import('..').GCLock} gcLock
14+
* @property {import('..').Preload} preload
15+
* @property {import('..').Pin} pin
16+
* @property {import('ipfs-interface/src/root').ShardingOptions} [options]
17+
*
18+
* @param {Context} context
1719
*/
1820
module.exports = ({ block, gcLock, preload, pin, options }) => {
1921
const isShardingEnabled = options && options.sharding
2022

21-
/** @type {import('ipfs-interface/src/root').AddAll} */
23+
/**
24+
* Import multiple files and data into IPFS.
25+
*
26+
* @param {import('ipfs-interface/src/files').ImportSource} source
27+
* @param {import('ipfs-interface/src/root').AddAllOptions} [options]
28+
* @returns {AsyncIterable<import('ipfs-interface/src/files').UnixFSEntry>}
29+
*/
2230
async function * addAll (source, options = {}) {
2331
const opts = mergeOptions({
2432
shardSplitThreshold: isShardingEnabled ? 1000 : Infinity,

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
const last = require('it-last')
44

55
/**
6-
* @param {Object} config
7-
* @param {import('ipfs-interface/src/root').AddAll} config.addAll
6+
* @typedef {Object} Context
7+
* @property {ReturnType<import('./add-all')>} addAll
8+
*
9+
* @param {Context} context
810
*/
911
module.exports = ({ addAll }) => {
10-
/** @type {import('ipfs-interface/src/root').Add} */
12+
/**
13+
* Import a file or data into IPFS.
14+
*
15+
* @param {import('ipfs-interface/src/files').ToEntry} entry
16+
* @param {import('ipfs-interface/src/root').AddAllOptions} [options]
17+
* @returns {Promise<import('ipfs-interface/src/files').UnixFSEntry>}
18+
*/
1119
async function add (entry, options) {
1220
/** @type {import('ipfs-interface/src/files').ImportSource} */
13-
const source = (entry) //
21+
const source = (entry)
1422
const result = await last(addAll(source, options))
1523
// Note this should never happen as `addAll` should yield at least one item
1624
// but to satisfy type checker we perfom this check and for good measure

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ const { normalizeCidPath } = require('../utils')
55
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
66

77
/**
8-
* @param {Object} config
9-
* @param {import('.').IPLD} config.ipld
10-
* @param {import('.').Preload} config.preload
8+
* @typedef {Object} Context
9+
* @property {import('.').IPLD} ipld
10+
* @property {import('.').Preload} preload
11+
*
12+
* @param {Context} context
1113
*/
1214
module.exports = function ({ ipld, preload }) {
13-
/** @type {import('ipfs-interface/src/root').Cat} */
15+
/**
16+
* Returns content of the file addressed by a valid IPFS Path or CID.
17+
*
18+
* @param {import('ipfs-interface/src/root').IPFSPath} ipfsPath
19+
* @param {import('ipfs-interface/src/root').CatOptions} [options]
20+
* @returns {AsyncIterable<Uint8Array>}
21+
*/
1422
async function * cat (ipfsPath, options = {}) {
1523
ipfsPath = normalizeCidPath(ipfsPath)
1624

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ const { normalizeCidPath, mapFile } = require('../utils')
66
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
77

88
/**
9-
* @param {Object} config
10-
* @param {import('.').IPLD} config.ipld
11-
* @param {import('.').Preload} config.preload
9+
* @typedef {Object} Context
10+
* @property {import('.').IPLD} ipld
11+
* @property {import('.').Preload} preload
12+
*
13+
* @param {Context} context
1214
*/
1315
module.exports = function ({ ipld, preload }) {
14-
/** @type {import('ipfs-interface/src/root').Get} */
16+
/**
17+
* Fetch a file or an entire directory tree from IPFS that is addressed by a
18+
* valid IPFS Path.
19+
*
20+
* @param {import('ipfs-interface/src/root').IPFSPath} ipfsPath
21+
* @param {import('ipfs-interface/src/root').GetOptions} [options]
22+
* @returns {AsyncIterable<import('ipfs-interface/src/files').IPFSEntry>}
23+
*/
1524
async function * get (ipfsPath, options = {}) {
1625
if (options.preload !== false) {
1726
let pathComponents

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ const { normalizeCidPath, mapFile } = require('../utils')
66
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
77

88
/**
9-
* @param {Object} config
10-
* @param {import('.').IPLD} config.ipld
11-
* @param {import('.').Preload} config.preload
9+
* @typedef {Object} Context
10+
* @property {import('.').IPLD} ipld
11+
* @property {import('.').Preload} preload
12+
*
13+
* @param {Context} context
1214
*/
1315
module.exports = function ({ ipld, preload }) {
14-
/** @type {import('ipfs-interface/src/root').List} */
16+
/**
17+
* Lists a directory from IPFS that is addressed by a valid IPFS Path.
18+
*
19+
* @param {import('ipfs-interface/src/root').IPFSPath} ipfsPath
20+
* @param {import('ipfs-interface/src/root').ListOptions} [options]
21+
* @returns {AsyncIterable<import('ipfs-interface/src/files').IPFSEntry>}
22+
*/
1523
async function * ls (ipfsPath, options = {}) {
1624
const path = normalizeCidPath(ipfsPath)
1725
const recursive = options.recursive

packages/ipfs-interface/src/root.ts

+5-39
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ import { ImportSource, IPFSEntry, ToEntry, UnixFSEntry } from './files'
44
import CID, { CIDVersion } from 'cids'
55

66
export interface RootAPI {
7-
add: Add
8-
addAll: AddAll
9-
cat: Cat
10-
get: Get
11-
}
7+
add(entry: ToEntry, options?: AddOptions): Promise<UnixFSEntry>
8+
addAll(source: ImportSource, options?: AddAllOptions & AbortOptions): AsyncIterable<UnixFSEntry>
9+
cat(ipfsPath: IPFSPath, options?: CatOptions): AsyncIterable<Uint8Array>
10+
get(ipfsPath: IPFSPath, options?: GetOptions): AsyncIterable<IPFSEntry>
1211

13-
/**
14-
* Import a file or data into IPFS.
15-
*/
16-
export interface Add {
17-
(entry: ToEntry, options?: AddOptions): Promise<UnixFSEntry>
12+
ls(ipfsPath: IPFSPath, options?: ListOptions): AsyncIterable<IPFSEntry>
1813
}
1914

2015
export interface AddOptions extends AbortOptions {
@@ -70,13 +65,6 @@ export interface AddOptions extends AbortOptions {
7065

7166
}
7267

73-
/**
74-
* Import multiple files and data into IPFS.
75-
*/
76-
export interface AddAll {
77-
(source: ImportSource, options?: AddAllOptions & AbortOptions): AsyncIterable<UnixFSEntry>
78-
}
79-
8068
export interface AddAllOptions extends AddOptions {
8169

8270
/**
@@ -97,13 +85,6 @@ export interface ShardingOptions {
9785
sharding?: boolean
9886
}
9987

100-
/**
101-
* Returns content of the file addressed by a valid IPFS Path or CID.
102-
*/
103-
export interface Cat {
104-
(ipfsPath: IPFSPath, options?:CatOptions): AsyncIterable<Uint8Array>
105-
}
106-
10788
export interface CatOptions extends AbortOptions, PreloadOptions {
10889
/**
10990
* An offset to start reading the file from
@@ -115,23 +96,8 @@ export interface CatOptions extends AbortOptions, PreloadOptions {
11596
length?: number
11697
}
11798

118-
/**
119-
* Fetch a file or an entire directory tree from IPFS that is addressed by a
120-
* valid IPFS Path.
121-
*/
122-
export interface Get {
123-
(ipfsPath: IPFSPath, options?: GetOptions): AsyncIterable<IPFSEntry>
124-
}
125-
12699
export interface GetOptions extends AbortOptions, PreloadOptions {}
127100

128-
export interface List {
129-
/**
130-
* Lists a directory from IPFS that is addressed by a valid IPFS Path.
131-
*/
132-
(ipfsPath: IPFSPath, options?: ListOptions): AsyncIterable<IPFSEntry>
133-
}
134-
135101
export interface ListOptions extends AbortOptions, PreloadOptions {
136102
recursive?: boolean,
137103
includeContent?: boolean

0 commit comments

Comments
 (0)