Skip to content

Commit

Permalink
mv name
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jan 20, 2023
1 parent 19941c5 commit afaff5c
Show file tree
Hide file tree
Showing 87 changed files with 370 additions and 349 deletions.
12 changes: 3 additions & 9 deletions src/add-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { configure } from './lib/configure.js'
import { multipartRequest } from 'ipfs-core-utils/multipart-request'
import { toUrlSearchParams } from './lib/to-url-search-params.js'
import { abortSignal } from './lib/abort-signal.js'
import type { AbortOptions, HTTPClientExtraOptions, IPFSCoreAddProgressFn, IPFSUtilsHttpUploadProgressFn } from './types.js'
import type { ClientOptions, IPFSCoreAddProgressFn, IPFSUtilsHttpUploadProgressFn } from './types.js'
import type { Version as CIDVersion } from 'multiformats/cid'
import type { Mtime } from 'ipfs-unixfs'
import type { ImportCandidateStream } from 'ipfs-core-types/src/utils.js'

export interface AddProgressFn { (bytes: number, path?: string): void }

export interface AddOptions extends AbortOptions {
export interface AddOptions extends ClientOptions {
/**
* Chunking algorithm used to build ipfs DAGs. (defaults to 'size-262144')
*/
Expand Down Expand Up @@ -103,16 +103,10 @@ export interface AddResult {
}

export const createAddAll = configure((api) => {
/**
* @type {import('./types.js').RootAPI["addAll"]}
*/

// addAll: (source: ImportCandidateStream, options?: AddAllOptions & AbortOptions & OptionExtension) => AsyncIterable<AddResult>

/**
* Import multiple files and data into IPFS
*/
async function * addAll (source: ImportCandidateStream, options?: AddAllOptions & AbortOptions & HTTPClientExtraOptions): AsyncIterable<AddResult> {
async function * addAll (source: ImportCandidateStream, options?: AddAllOptions): AsyncIterable<AddResult> {
// allow aborting requests on body errors
const controller = new AbortController()
const signal = abortSignal(controller.signal, options?.signal)
Expand Down
4 changes: 2 additions & 2 deletions src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import last from 'it-last'
import { configure } from './lib/configure.js'
import { normaliseInput } from 'ipfs-core-utils/files/normalise-input-single'
import type { ImportCandidate } from 'ipfs-core-types/src/utils.js'
import type { AddResult, HTTPClientExtraOptions, Options } from './types.js'
import type { AddResult, Options } from './types.js'

export function createAdd (options: Options) {
const all = createAddAll(options)
return configure(() => {
/**
* Import a file or data into IPFS
*/
async function add (input: ImportCandidate, options?: AddOptions & HTTPClientExtraOptions): Promise<AddResult> {
async function add (input: ImportCandidate, options?: AddOptions): Promise<AddResult> {
const source = normaliseInput(input)
// // @ts-expect-error - all may return undefined if source is empty
const addAllPromise = all(source, options)
Expand Down
4 changes: 2 additions & 2 deletions src/bitswap/stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CID } from 'multiformats/cid'
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import { peerIdFromString } from '@libp2p/peer-id'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { ClientOptions } from '../types.js'

export interface Stats {
provideBufLen: number
Expand All @@ -28,7 +28,7 @@ export const createStat = configure(api => {
* console.log(stats)
* ```
*/
async function stat (options?: AbortOptions & HTTPClientExtraOptions): Promise<Stats> {
async function stat (options?: ClientOptions): Promise<Stats> {
const res = await api.post('bitswap/stat', {
searchParams: toUrlSearchParams(options),
signal: options?.signal,
Expand Down
6 changes: 3 additions & 3 deletions src/bitswap/wantlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { CID } from 'multiformats/cid'
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'

export interface WantlistOptions {
export interface WantlistOptions extends ClientOptions {
peer: PeerId
}

Expand All @@ -19,7 +19,7 @@ export const createWantlist = configure(api => {
* // [ CID('QmHash') ]
* ```
*/
async function wantlist (options?: WantlistOptions & AbortOptions & HTTPClientExtraOptions): Promise<CID[]> {
async function wantlist (options?: WantlistOptions): Promise<CID[]> {
const searchParams: any = { ...options }
if (options?.peer != null) {
searchParams.peer = options.peer.toString()
Expand Down
4 changes: 2 additions & 2 deletions src/block/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { CID } from 'multiformats/cid'
import type { AbortOptions, HTTPClientExtraOptions, PreloadOptions } from '../types.js'
import type { ClientOptions, PreloadOptions } from '../types.js'

export const createGet = configure(api => {
/**
Expand All @@ -13,7 +13,7 @@ export const createGet = configure(api => {
* console.log(block)
* ```
*/
async function get (cid: CID, options?: AbortOptions & PreloadOptions & HTTPClientExtraOptions): Promise<Uint8Array> {
async function get (cid: CID, options?: ClientOptions & PreloadOptions): Promise<Uint8Array> {
const res = await api.post('block/get', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
6 changes: 3 additions & 3 deletions src/block/put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { multipartRequest } from 'ipfs-core-utils/multipart-request'
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import { abortSignal } from '../lib/abort-signal.js'
import type { AbortOptions, HTTPClientExtraOptions, PreloadOptions } from '../types.js'
import type { ClientOptions, PreloadOptions } from '../types.js'

export interface PutOptions extends AbortOptions, PreloadOptions {
export interface PutOptions extends ClientOptions, PreloadOptions {
/**
* Multicodec to use in returned CID. (Defaults to 'raw')
*/
Expand Down Expand Up @@ -60,7 +60,7 @@ export const createPut = configure(api => {
* // the CID of the object
* ```
*/
async function put (data: Uint8Array, options?: PutOptions & HTTPClientExtraOptions): Promise<CID> {
async function put (data: Uint8Array, options?: PutOptions): Promise<CID> {
// allow aborting requests on body errors
const controller = new AbortController()
const signal = abortSignal(controller.signal, options?.signal)
Expand Down
6 changes: 3 additions & 3 deletions src/block/rm.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CID } from 'multiformats/cid'
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'

export interface RmOptions extends AbortOptions {
export interface RmOptions extends ClientOptions {
/**
* Ignores non-existent blocks
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ export const createRm = configure(api => {
* }
* ```
*/
async function * rm (cid: CID | CID[], options?: RmOptions & HTTPClientExtraOptions): AsyncIterable<RmResult> {
async function * rm (cid: CID | CID[], options?: RmOptions): AsyncIterable<RmResult> {
if (!Array.isArray(cid)) {
cid = [cid]
}
Expand Down
4 changes: 2 additions & 2 deletions src/block/stat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CID } from 'multiformats/cid'
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions, PreloadOptions } from '../types.js'
import type { ClientOptions, PreloadOptions } from '../types.js'

export interface StatResult {
/**
Expand Down Expand Up @@ -29,7 +29,7 @@ export const createStat = configure(api => {
* // Logs: 3739
* ```
*/
async function stat (cid: CID, options?: AbortOptions & PreloadOptions & HTTPClientExtraOptions): Promise<StatResult> {
async function stat (cid: CID, options?: ClientOptions & PreloadOptions): Promise<StatResult> {
const res = await api.post('block/stat', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/add.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import { multiaddr } from '@multiformats/multiaddr'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { ClientOptions } from '../types.js'

export const createAdd = configure(api => {
/**
Expand All @@ -18,7 +18,7 @@ export const createAdd = configure(api => {
* // ['/ip4/104....9z']
* ```
*/
async function add (addr: Multiaddr, options?: AbortOptions & HTTPClientExtraOptions): Promise<{ Peers: Multiaddr[] }> {
async function add (addr: Multiaddr, options?: ClientOptions): Promise<{ Peers: Multiaddr[] }> {
const res = await api.post('bootstrap/add', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import { Multiaddr, multiaddr } from '@multiformats/multiaddr'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'

export const createList = configure(api => {
/**
Expand All @@ -15,7 +15,7 @@ export const createList = configure(api => {
* // [address1, address2, ...]
* ```
*/
async function list (options?: AbortOptions & HTTPClientExtraOptions): Promise<{ Peers: Multiaddr[] }> {
async function list (options?: ClientOptions): Promise<{ Peers: Multiaddr[] }> {
const res = await api.post('bootstrap/list', {
signal: options?.signal,
searchParams: toUrlSearchParams(options),
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/rm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import { Multiaddr, multiaddr } from '@multiformats/multiaddr'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'

export const createRm = configure(api => {
/**
Expand All @@ -15,7 +15,7 @@ export const createRm = configure(api => {
* // [address1, address2, ...]
* ```
*/
async function rm (addr: Multiaddr, options?: AbortOptions & HTTPClientExtraOptions): Promise<{ Peers: Multiaddr[] }> {
async function rm (addr: Multiaddr, options?: ClientOptions): Promise<{ Peers: Multiaddr[] }> {
const res = await api.post('bootstrap/rm', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
6 changes: 3 additions & 3 deletions src/cat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { configure } from './lib/configure.js'
import { toUrlSearchParams } from './lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions, IPFSPath, PreloadOptions } from './types.js'
import type { ClientOptions, IPFSPath, PreloadOptions } from './types.js'

export interface CatOptions extends AbortOptions, PreloadOptions {
export interface CatOptions extends ClientOptions, PreloadOptions {
/**
* An offset to start reading the file from
*/
Expand All @@ -17,7 +17,7 @@ export const createCat = configure(api => {
/**
* Returns content of the file addressed by a valid IPFS Path or CID
*/
async function * cat (path: IPFSPath, options?: CatOptions & HTTPClientExtraOptions): AsyncIterable<Uint8Array> {
async function * cat (path: IPFSPath, options?: CatOptions): AsyncIterable<Uint8Array> {
const res = await api.post('cat', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { configure } from './lib/configure.js'
import { toUrlSearchParams } from './lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions } from './types.js'
import type { ClientOptions } from './types.js'

export const createCommands = configure(api => {
/**
* Returns a list of available commands
*/
const commands = async (options?: AbortOptions & HTTPClientExtraOptions): Promise<string[]> => {
const commands = async (options?: ClientOptions): Promise<string[]> => {
const res = await api.post('commands', {
signal: options?.signal,
searchParams: toUrlSearchParams(options),
Expand Down
4 changes: 2 additions & 2 deletions src/config/get-all.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'
import type { Config } from './utils.js'

export const createGetAll = configure(api => {
/**
* Returns the full config been used. If the daemon is off, it returns the
* stored config
*/
const getAll = async (options?: AbortOptions & HTTPClientExtraOptions): Promise<Config> => {
const getAll = async (options?: ClientOptions): Promise<Config> => {
const res = await api.post('config/show', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
4 changes: 2 additions & 2 deletions src/config/get.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'

export const createGet = configure(api => {
/**
* Returns a value from the currently being used config. If the daemon
* is off, it returns the value from the stored config.
*/
const get = async (key: string, options?: AbortOptions & HTTPClientExtraOptions): Promise<string | object> => {
const get = async (key: string, options?: ClientOptions): Promise<string | object> => {
if (key == null) {
throw new Error('key argument is required')
}
Expand Down
6 changes: 3 additions & 3 deletions src/config/profiles/apply.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { configure } from '../../lib/configure.js'
import { toUrlSearchParams } from '../../lib/to-url-search-params.js'
import type { ClientOptions } from '../../types.js'
import type { Config } from '../utils.js'
import type { AbortOptions, HTTPClientExtraOptions } from '../../types.js'

export interface ProfilesApplyOptions extends AbortOptions {
export interface ProfilesApplyOptions extends ClientOptions {
dryRun?: boolean
}

Expand All @@ -17,7 +17,7 @@ export const createApply = configure(api => {
* Apply a profile to the current config. Note that restarting the node
* will be necessary for any change to take effect.
*/
async function apply (profile: string, options?: ProfilesApplyOptions & HTTPClientExtraOptions): Promise<ProfilesApplyResult> {
async function apply (profile: string, options?: ProfilesApplyOptions): Promise<ProfilesApplyResult> {
const res = await api.post('config/profile/apply', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
4 changes: 2 additions & 2 deletions src/config/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import { abortSignal } from '../lib/abort-signal.js'
import type { Config } from './utils.js'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'

export const createReplace = configure(api => {
/**
* Replaces the full config. Note that restarting the node will be
* necessary for any change to take effect.
*/
const replace = async (config: Config, options?: AbortOptions & HTTPClientExtraOptions): Promise<void> => {
const replace = async (config: Config, options?: ClientOptions): Promise<void> => {
// allow aborting requests on body errors
const controller = new AbortController()
const signal = abortSignal(controller.signal, options?.signal)
Expand Down
4 changes: 2 additions & 2 deletions src/config/set.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions } from '../types.js'
import type { ClientOptions } from '../types.js'

export const createSet = configure(api => {
/**
* Adds or replaces a config value. Note that restarting the node will be
* necessary for any change to take effect.
*/
const set = async (key: string, value: any, options?: AbortOptions & HTTPClientExtraOptions): Promise<void> => {
const set = async (key: string, value: any, options?: ClientOptions): Promise<void> => {
if (typeof key !== 'string') {
throw new Error('Invalid key type')
}
Expand Down
4 changes: 2 additions & 2 deletions src/dag/export.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { CID } from 'multiformats'
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
import type { AbortOptions, HTTPClientExtraOptions, PreloadOptions } from '../types.js'
import type { ClientOptions, PreloadOptions } from '../types.js'

export const createExport = configure(api => {
/**
* Exports a CAR for the entire DAG available from the given root CID. The CAR will have a single
* root and IPFS will attempt to fetch and bundle all blocks that are linked within the connected
* DAG.
*/
async function * dagExport (root: CID, options?: AbortOptions & PreloadOptions & HTTPClientExtraOptions): AsyncIterable<Uint8Array> {
async function * dagExport (root: CID, options?: ClientOptions & PreloadOptions): AsyncIterable<Uint8Array> {
const res = await api.post('dag/export', {
signal: options?.signal,
searchParams: toUrlSearchParams({
Expand Down
6 changes: 3 additions & 3 deletions src/dag/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import first from 'it-first'
import last from 'it-last'
import errCode from 'err-code'
import { createGet as createBlockGet } from '../block/get.js'
import type { AbortOptions, HTTPClientExtraOptions, Multicodecs, Options, PreloadOptions } from '../types.js'
import type { ClientOptions, Multicodecs, Options, PreloadOptions } from '../types.js'
import type { CID } from 'multiformats'

// TODO: this does not use the RPC API.

export interface GetOptions extends AbortOptions, PreloadOptions {
export interface GetOptions extends ClientOptions, PreloadOptions {
/**
* An optional path within the DAG to resolve
*/
Expand Down Expand Up @@ -81,7 +81,7 @@ export const createGet = (codecs: Multicodecs, options: Options) => {
* // 6
* ```
*/
const get = async (cid: CID, options?: GetOptions & HTTPClientExtraOptions): Promise<GetResult> => {
const get = async (cid: CID, options?: GetOptions): Promise<GetResult> => {
if (options?.path != null) {
const entry = options.localResolve != null
? await first(resolve(cid, options.path, codecs, getBlock, options))
Expand Down
Loading

0 comments on commit afaff5c

Please sign in to comment.