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

Commit

Permalink
chore: revert ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Dec 16, 2020
1 parent c2ec920 commit 7dd1e72
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 62 deletions.
1 change: 1 addition & 0 deletions examples/types-use-ipfs-from-ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default async function main() {

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

Expand Down
1 change: 1 addition & 0 deletions examples/types-use-ipfs-from-typed-js/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function main () {

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

Expand Down
22 changes: 15 additions & 7 deletions packages/ipfs-core/src/components/add-all/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
const mergeOptions = require('merge-options').bind({ ignoreUndefined: true })

/**
* @param {Object} config
* @param {import('..').Block} config.block
* @param {import('..').GCLock} config.gcLock
* @param {import('..').Preload} config.preload
* @param {import('..').Pin} config.pin
* @param {import('ipfs-interface/src/root').ShardingOptions} [config.options]
* @typedef {Object} Context
* @property {import('..').Block} block
* @property {import('..').GCLock} gcLock
* @property {import('..').Preload} preload
* @property {import('..').Pin} pin
* @property {import('ipfs-interface/src/root').ShardingOptions} [options]
*
* @param {Context} context
*/
module.exports = ({ block, gcLock, preload, pin, options }) => {
const isShardingEnabled = options && options.sharding

/** @type {import('ipfs-interface/src/root').AddAll} */
/**
* Import multiple files and data into IPFS.
*
* @param {import('ipfs-interface/src/files').ImportSource} source
* @param {import('ipfs-interface/src/root').AddAllOptions} [options]
* @returns {AsyncIterable<import('ipfs-interface/src/files').UnixFSEntry>}
*/
async function * addAll (source, options = {}) {
const opts = mergeOptions({
shardSplitThreshold: isShardingEnabled ? 1000 : Infinity,
Expand Down
16 changes: 12 additions & 4 deletions packages/ipfs-core/src/components/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
const last = require('it-last')

/**
* @param {Object} config
* @param {import('ipfs-interface/src/root').AddAll} config.addAll
* @typedef {Object} Context
* @property {ReturnType<import('./add-all')>} addAll
*
* @param {Context} context
*/
module.exports = ({ addAll }) => {
/** @type {import('ipfs-interface/src/root').Add} */
/**
* Import a file or data into IPFS.
*
* @param {import('ipfs-interface/src/files').ToEntry} entry
* @param {import('ipfs-interface/src/root').AddAllOptions} [options]
* @returns {Promise<import('ipfs-interface/src/files').UnixFSEntry>}
*/
async function add (entry, options) {
/** @type {import('ipfs-interface/src/files').ImportSource} */
const source = (entry) //
const source = (entry)
const result = await last(addAll(source, options))
// Note this should never happen as `addAll` should yield at least one item
// but to satisfy type checker we perfom this check and for good measure
Expand Down
16 changes: 12 additions & 4 deletions packages/ipfs-core/src/components/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ const { normalizeCidPath } = require('../utils')
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')

/**
* @param {Object} config
* @param {import('.').IPLD} config.ipld
* @param {import('.').Preload} config.preload
* @typedef {Object} Context
* @property {import('.').IPLD} ipld
* @property {import('.').Preload} preload
*
* @param {Context} context
*/
module.exports = function ({ ipld, preload }) {
/** @type {import('ipfs-interface/src/root').Cat} */
/**
* Returns content of the file addressed by a valid IPFS Path or CID.
*
* @param {import('ipfs-interface/src/root').IPFSPath} ipfsPath
* @param {import('ipfs-interface/src/root').CatOptions} [options]
* @returns {AsyncIterable<Uint8Array>}
*/
async function * cat (ipfsPath, options = {}) {
ipfsPath = normalizeCidPath(ipfsPath)

Expand Down
17 changes: 13 additions & 4 deletions packages/ipfs-core/src/components/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ const { normalizeCidPath, mapFile } = require('../utils')
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')

/**
* @param {Object} config
* @param {import('.').IPLD} config.ipld
* @param {import('.').Preload} config.preload
* @typedef {Object} Context
* @property {import('.').IPLD} ipld
* @property {import('.').Preload} preload
*
* @param {Context} context
*/
module.exports = function ({ ipld, preload }) {
/** @type {import('ipfs-interface/src/root').Get} */
/**
* Fetch a file or an entire directory tree from IPFS that is addressed by a
* valid IPFS Path.
*
* @param {import('ipfs-interface/src/root').IPFSPath} ipfsPath
* @param {import('ipfs-interface/src/root').GetOptions} [options]
* @returns {AsyncIterable<import('ipfs-interface/src/files').IPFSEntry>}
*/
async function * get (ipfsPath, options = {}) {
if (options.preload !== false) {
let pathComponents
Expand Down
16 changes: 12 additions & 4 deletions packages/ipfs-core/src/components/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ const { normalizeCidPath, mapFile } = require('../utils')
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')

/**
* @param {Object} config
* @param {import('.').IPLD} config.ipld
* @param {import('.').Preload} config.preload
* @typedef {Object} Context
* @property {import('.').IPLD} ipld
* @property {import('.').Preload} preload
*
* @param {Context} context
*/
module.exports = function ({ ipld, preload }) {
/** @type {import('ipfs-interface/src/root').List} */
/**
* Lists a directory from IPFS that is addressed by a valid IPFS Path.
*
* @param {import('ipfs-interface/src/root').IPFSPath} ipfsPath
* @param {import('ipfs-interface/src/root').ListOptions} [options]
* @returns {AsyncIterable<import('ipfs-interface/src/files').IPFSEntry>}
*/
async function * ls (ipfsPath, options = {}) {
const path = normalizeCidPath(ipfsPath)
const recursive = options.recursive
Expand Down
44 changes: 5 additions & 39 deletions packages/ipfs-interface/src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ import { ImportSource, IPFSEntry, ToEntry, UnixFSEntry } from './files'
import CID, { CIDVersion } from 'cids'

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

/**
* Import a file or data into IPFS.
*/
export interface Add {
(entry: ToEntry, options?: AddOptions): Promise<UnixFSEntry>
ls(ipfsPath: IPFSPath, options?: ListOptions): AsyncIterable<IPFSEntry>
}

export interface AddOptions extends AbortOptions {
Expand Down Expand Up @@ -70,13 +65,6 @@ export interface AddOptions extends AbortOptions {

}

/**
* Import multiple files and data into IPFS.
*/
export interface AddAll {
(source: ImportSource, options?: AddAllOptions & AbortOptions): AsyncIterable<UnixFSEntry>
}

export interface AddAllOptions extends AddOptions {

/**
Expand All @@ -97,13 +85,6 @@ export interface ShardingOptions {
sharding?: boolean
}

/**
* Returns content of the file addressed by a valid IPFS Path or CID.
*/
export interface Cat {
(ipfsPath: IPFSPath, options?:CatOptions): AsyncIterable<Uint8Array>
}

export interface CatOptions extends AbortOptions, PreloadOptions {
/**
* An offset to start reading the file from
Expand All @@ -115,23 +96,8 @@ export interface CatOptions extends AbortOptions, PreloadOptions {
length?: number
}

/**
* Fetch a file or an entire directory tree from IPFS that is addressed by a
* valid IPFS Path.
*/
export interface Get {
(ipfsPath: IPFSPath, options?: GetOptions): AsyncIterable<IPFSEntry>
}

export interface GetOptions extends AbortOptions, PreloadOptions {}

export interface List {
/**
* Lists a directory from IPFS that is addressed by a valid IPFS Path.
*/
(ipfsPath: IPFSPath, options?: ListOptions): AsyncIterable<IPFSEntry>
}

export interface ListOptions extends AbortOptions, PreloadOptions {
recursive?: boolean,
includeContent?: boolean
Expand Down

0 comments on commit 7dd1e72

Please sign in to comment.