Skip to content

Commit

Permalink
fix: export ipfs http client type and use option extension for client…
Browse files Browse the repository at this point in the history
… (#3763)

Bubbles the `OptionExtension` up to the root type for use by the HTTP client and exports an interface for use by consuming modules.

Supersedes #3749 and #3736
  • Loading branch information
achingbrain committed Jul 27, 2021
1 parent ec3af46 commit 4a7a810
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { base58btc } = require('multiformats/bases/base58')
* @typedef {import('./types').EndpointConfig} EndpointConfig
* @typedef {import('./types').Options} Options
* @typedef {import('multiformats/codecs/interface').BlockCodec<any, any>} BlockCodec
* @typedef {import('./types').IPFSHTTPClient} IPFSHTTPClient
*/

/**
Expand Down Expand Up @@ -49,7 +50,7 @@ function create (options = {}) {
loadHasher: options.ipld && options.ipld.loadHasher
})

/** @type {import('ipfs-core-types').IPFS & { getEndpointConfig: () => EndpointConfig }} */
/** @type {IPFSHTTPClient} */
const client = {
add: require('./add')(options),
addAll: require('./add-all')(options),
Expand Down
5 changes: 5 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Agent as HttpAgent } from 'http'
import { Agent as HttpsAgent } from 'https'
import { Multiaddr } from 'multiaddr'
import type { BlockCodec } from 'multiformats/codecs/interface'
import type { IPFS } from 'ipfs-core-types'

export interface Options {
host?: string
Expand Down Expand Up @@ -40,3 +41,7 @@ export interface EndpointConfig {
pathname: string
'api-path': string
}

export interface IPFSHTTPClient extends IPFS<HTTPClientExtraOptions> {
getEndpointConfig: () => EndpointConfig
}

0 comments on commit 4a7a810

Please sign in to comment.