Skip to content

Commit

Permalink
chore: revert "feat: add typeScript support (#3236)" (#3264)
Browse files Browse the repository at this point in the history
This reverts commit be26dd7.

The build was failing.
  • Loading branch information
achingbrain authored Sep 3, 2020
1 parent 1502822 commit 4eddfed
Show file tree
Hide file tree
Showing 23 changed files with 26 additions and 121 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
"shunkin <[email protected]>",
"victorbjelkholm <[email protected]>",
"Łukasz Magiera <[email protected]>",
"Łukasz Magiera <[email protected]>",
"Xmader <[email protected]>"
"Łukasz Magiera <[email protected]>"
]
}
17 changes: 2 additions & 15 deletions src/add-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ const configure = require('./lib/configure')
const multipartRequest = require('./lib/multipart-request')
const toUrlSearchParams = require('./lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

module.exports = configure((api) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../ipfs/src/core/components/add-all').AddAll<import('.').HttpOptions>}
*/
async function * addAll (input, options = {}) {
return async function * addAll (input, options = {}) {
const progressFn = options.progress

// allow aborting requests on body errors
Expand Down Expand Up @@ -43,16 +39,8 @@ module.exports = configure((api) => {
}
}
}
return addAll
})

/**
* @typedef {import('../../ipfs/src/core/components/add-all').UnixFSEntry} UnixFSEntry
*/

/**
* @returns {UnixFSEntry}
*/
function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) {
const output = {
path: name,
Expand All @@ -71,6 +59,5 @@ function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) {
}
}

// @ts-ignore
return output
}
16 changes: 1 addition & 15 deletions src/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,12 @@ const addAll = require('./add-all')
const last = require('it-last')
const configure = require('./lib/configure')

/**
* @typedef {import("./lib/core").ClientOptions} ClientOptions
*/

// eslint-disable-next-line valid-jsdoc
/**
* @param {ClientOptions} options
*/
module.exports = (options) => {
const all = addAll(options)

return configure(() => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../ipfs/src/core/components/add').Add<import('.').HttpOptions>}
*/
async function add (input, options = {}) { // eslint-disable-line require-await
// @ts-ignore
return async function add (input, options = {}) { // eslint-disable-line require-await
return last(all(input, options))
}
return add
})(options)
}
7 changes: 1 addition & 6 deletions src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../../ipfs/src/core/components/bitswap/stat').Stat<import('..').HttpOptions>}
*/
async function stat (options = {}) {
return async (options = {}) => {
const res = await api.post('bitswap/stat', {
searchParams: toUrlSearchParams(options),
timeout: options.timeout,
Expand All @@ -20,7 +16,6 @@ module.exports = configure(api => {

return toCoreInterface(await res.json())
}
return stat
})

function toCoreInterface (res) {
Expand Down
7 changes: 1 addition & 6 deletions src/bitswap/unwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../../ipfs/src/core/components/bitswap/unwant').Unwant<import('..').HttpOptions>}
*/
async function unwant (cid, options = {}) {
return async (cid, options = {}) => {
const res = await api.post('bitswap/unwant', {
timeout: options.timeout,
signal: options.signal,
Expand All @@ -22,5 +18,4 @@ module.exports = configure(api => {

return res.json()
}
return unwant
})
7 changes: 1 addition & 6 deletions src/bitswap/wantlist-for-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../../ipfs/src/core/components/bitswap/wantlist-for-peer').WantlistForPeer<import('..').HttpOptions>}
*/
async function wantlistForPeer (peerId, options = {}) {
return async (peerId, options = {}) => {
peerId = typeof peerId === 'string' ? peerId : new CID(peerId).toString()

const res = await (await api.post('bitswap/wantlist', {
Expand All @@ -24,5 +20,4 @@ module.exports = configure(api => {

return (res.Keys || []).map(k => new CID(k['/']))
}
return wantlistForPeer
})
7 changes: 1 addition & 6 deletions src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../../ipfs/src/core/components/bitswap/wantlist').WantlistFn<import('..').HttpOptions>}
*/
async function wantlist (options = {}) {
return async (options = {}) => {
const res = await (await api.post('bitswap/wantlist', {
timeout: options.timeout,
signal: options.signal,
Expand All @@ -19,5 +15,4 @@ module.exports = configure(api => {

return (res.Keys || []).map(k => new CID(k['/']))
}
return wantlist
})
7 changes: 1 addition & 6 deletions src/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../../ipfs/src/core/components/block/get').BlockGet<import('..').HttpOptions>}
*/
async function get (cid, options = {}) {
return async (cid, options = {}) => {
cid = new CID(cid)

const res = await api.post('block/get', {
Expand All @@ -25,5 +21,4 @@ module.exports = configure(api => {

return new Block(new Uint8Array(await res.arrayBuffer()), cid)
}
return get
})
6 changes: 1 addition & 5 deletions src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ const multipartRequest = require('../lib/multipart-request')
const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../../ipfs/src/core/components/block/put').BlockPut<import('..').HttpOptions>}
*/
async function put (data, options = {}) {
if (Block.isBlock(data)) {
const { name, length } = multihash.decode(data.cid.multihash)
Expand Down
2 changes: 1 addition & 1 deletion src/config/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const multipartRequest = require('../lib/multipart-request')
const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

module.exports = configure(api => {
return async (config, options = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const configure = require('../lib/configure')
const multipartRequest = require('../lib/multipart-request')
const toUrlSearchParams = require('../lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')
const multicodec = require('multicodec')

module.exports = configure((api, opts) => {
Expand Down
2 changes: 1 addition & 1 deletion src/files/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const configure = require('../lib/configure')
const multipartRequest = require('../lib/multipart-request')
const toUrlSearchParams = require('../lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

module.exports = configure(api => {
return async (path, input, options = {}) => {
Expand Down
7 changes: 1 addition & 6 deletions src/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ const configure = require('./lib/configure')
const toUrlSearchParams = require('./lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../ipfs/src/core/components/id').Id<import('.').HttpOptions>}
*/
async function id (options = {}) {
return async (options = {}) => {
const res = await api.post('id', {
timeout: options.timeout,
signal: options.signal,
Expand All @@ -27,5 +23,4 @@ module.exports = configure(api => {

return output
}
return id
})
14 changes: 3 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@ const urlSource = require('ipfs-utils/src/files/url-source')
*/

/**
* @typedef {object} HttpOptions
* @property {Headers | Record<string, string>} [headers] - An object or [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) instance that can be used to set custom HTTP headers. Note that this option can also be [configured globally](#custom-headers) via the constructor options.
* @property {URLSearchParams | Record<string, string>} [searchParams] - An object or [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) instance that can be used to add additional query parameters to the query string sent with each request.
* @property {object} [ipld]
* @property {any[]} [ipld.formats] - An array of additional [IPLD formats](https://github.com/ipld/interface-ipld-format) to support
* @property {(format: string) => Promise<any>} [ipld.loadFormat] - an async function that takes the name of an [IPLD format](https://github.com/ipld/interface-ipld-format) as a string and should return the implementation of that codec
*/

// eslint-disable-next-line valid-jsdoc
/**
* @param {ClientOptions} options
*
* @param {ClientOptions } options
* @return {Object}
*/
function ipfsClient (options = {}) {
return {
Expand Down
15 changes: 2 additions & 13 deletions src/lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,8 @@ const Client = require('./core')
*/

/**
* @template T
* @typedef {(client: Client, clientOptions: ClientOptions) => T} Fn
*/

/**
* @template T
* @typedef {(clientOptions: ClientOptions) => T} Factory
*/

/**
* @template T
* @param {Fn<T>} fn
* @returns {Factory<T>}
* @param {function(Client, ClientOptions): void} fn
* @returns {function(ClientOptions): void}
*/
const configure = (fn) => {
return (options) => {
Expand Down
4 changes: 0 additions & 4 deletions src/lib/to-url-search-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
const modeToString = require('./mode-to-string')
const mtimeToObject = require('./mtime-to-object')

/**
* @param {object} params
* @returns {URLSearchParams}
*/
module.exports = ({ arg, searchParams, hashAlg, mtime, mode, ...options } = {}) => {
if (searchParams) {
options = {
Expand Down
2 changes: 1 addition & 1 deletion src/object/patch/append-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const multipartRequest = require('../../lib/multipart-request')
const configure = require('../../lib/configure')
const toUrlSearchParams = require('../../lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

module.exports = configure(api => {
return async (cid, data, options = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/object/patch/set-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const multipartRequest = require('../../lib/multipart-request')
const configure = require('../../lib/configure')
const toUrlSearchParams = require('../../lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

module.exports = configure(api => {
return async (cid, data, options = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const multipartRequest = require('../lib/multipart-request')
const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')
const unit8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')

Expand Down
2 changes: 1 addition & 1 deletion src/pubsub/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
const multipartRequest = require('../lib/multipart-request')
const anySignal = require('any-signal')
const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

module.exports = configure(api => {
return async (topic, data, options = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pubsub/subscription-tracker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { AbortController } = require('abort-controller')
const AbortController = require('abort-controller')

class SubscriptionTracker {
constructor () {
Expand Down
7 changes: 1 addition & 6 deletions src/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ const configure = require('./lib/configure')
const toUrlSearchParams = require('./lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../ipfs/src/core/components/resolve').Resolve<import('.').HttpOptions>}
*/
async function resolve (path, options = {}) {
return async (path, options = {}) => {
const res = await api.post('resolve', {
timeout: options.timeout,
signal: options.signal,
Expand All @@ -21,5 +17,4 @@ module.exports = configure(api => {
const { Path } = await res.json()
return Path
}
return resolve
})
7 changes: 1 addition & 6 deletions src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const configure = require('./lib/configure')
const toUrlSearchParams = require('./lib/to-url-search-params')

module.exports = configure(api => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {import('../../ipfs/src/core/components/version').Version<import('.').HttpOptions>}
*/
async function version (options = {}) {
return async (options = {}) => {
const res = await api.post('version', {
timeout: options.timeout,
signal: options.signal,
Expand All @@ -20,5 +16,4 @@ module.exports = configure(api => {

return toCamel(data)
}
return version
})

0 comments on commit 4eddfed

Please sign in to comment.