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

Commit efd147a

Browse files
authored
chore: rename import types (#3678)
Use `ImportCandidate` and `ImportCandidateStream` instead of `ToEntry` and `ImportSource` as they are a bit more descriptive. Plus we already have `BrowserImportCandidate` for `Blob`s so it's more consistent too.
1 parent bb8f8bc commit efd147a

File tree

12 files changed

+39
-39
lines changed

12 files changed

+39
-39
lines changed

packages/ipfs-core-types/src/root.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AbortOptions, PreloadOptions, IPFSPath, ImportSource, ToEntry } from './utils'
1+
import { AbortOptions, PreloadOptions, IPFSPath, ImportCandidateStream, ImportCandidate } from './utils'
22
import CID, { CIDVersion } from 'cids'
33
import { Mtime } from 'ipfs-unixfs'
44
import { Multiaddr } from 'multiaddr'
@@ -8,12 +8,12 @@ export interface API<OptionExtension = {}> {
88
/**
99
* Import a file or data into IPFS
1010
*/
11-
add: (entry: ToEntry, options?: AddOptions & OptionExtension) => Promise<AddResult>
11+
add: (entry: ImportCandidate, options?: AddOptions & OptionExtension) => Promise<AddResult>
1212

1313
/**
1414
* Import multiple files and data into IPFS
1515
*/
16-
addAll: (source: ImportSource, options?: AddAllOptions & AbortOptions & OptionExtension) => AsyncIterable<AddResult>
16+
addAll: (source: ImportCandidateStream, options?: AddAllOptions & AbortOptions & OptionExtension) => AsyncIterable<AddResult>
1717

1818
/**
1919
* Returns content of the file addressed by a valid IPFS Path or CID

packages/ipfs-core-types/src/utils.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export interface DirectoryEntry extends BaseEntry {
2020
content?: undefined
2121
}
2222

23-
export type ImportSource =
24-
| AwaitIterable<ToEntry>
25-
| ReadableStream<ToEntry>
23+
export type ImportCandidateStream =
24+
| AwaitIterable<ImportCandidate>
25+
| ReadableStream<ImportCandidate>
2626

27-
export type ToEntry =
27+
export type ImportCandidate =
2828
| ToFile
2929
| ToDirectory
3030
| ToContent

packages/ipfs-core-utils/src/files/normalise-input/index.browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const normaliseContent = require('./normalise-content.browser')
44
const normaliseInput = require('./normalise-input')
55

66
/**
7-
* @typedef {import('ipfs-core-types/src/utils').ImportSource} ImportSource
7+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidateStream} ImportCandidateStream
88
* @typedef {import('ipfs-core-types/src/utils').BrowserImportCandidate} BrowserImportCandidate
99
*/
1010

@@ -17,7 +17,7 @@ const normaliseInput = require('./normalise-input')
1717
*
1818
* See https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsadddata-options
1919
*
20-
* @param {ImportSource} input
20+
* @param {ImportCandidateStream} input
2121
* @returns {AsyncGenerator<BrowserImportCandidate, void, undefined>}
2222
*/
2323
// @ts-ignore

packages/ipfs-core-utils/src/files/normalise-input/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const normaliseContent = require('./normalise-content')
44
const normaliseInput = require('./normalise-input')
55

66
/**
7-
* @typedef {import('ipfs-core-types/src/utils').ImportSource} ImportSource
7+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidateStream} ImportCandidateStream
88
* @typedef {import('ipfs-unixfs-importer').ImportCandidate} ImportCandidate
99
*/
1010

@@ -17,7 +17,7 @@ const normaliseInput = require('./normalise-input')
1717
*
1818
* See https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsadddata-options
1919
*
20-
* @param {ImportSource} input
20+
* @param {ImportCandidateStream} input
2121
* @returns {AsyncGenerator<ImportCandidate, void, undefined>}
2222
*/
2323
module.exports = (input) => normaliseInput(input, normaliseContent)

packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const {
1717

1818
/**
1919
* @typedef {import('ipfs-core-types/src/utils').ToContent} ToContent
20-
* @typedef {import('ipfs-unixfs-importer').ImportCandidate} ImportCandidate
21-
* @typedef {import('ipfs-core-types/src/utils').ToEntry} ToEntry
20+
* @typedef {import('ipfs-unixfs-importer').ImportCandidate} ImporterImportCandidate
21+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidate} ImportCandidate
2222
*/
2323

2424
/**
25-
* @param {import('ipfs-core-types/src/utils').ImportSource} input
25+
* @param {import('ipfs-core-types/src/utils').ImportCandidateStream} input
2626
* @param {(content:ToContent) => AsyncIterable<Uint8Array>} normaliseContent
2727
*/
2828
// eslint-disable-next-line complexity
@@ -76,7 +76,7 @@ module.exports = async function * normaliseInput (input, normaliseContent) {
7676
// (Async)Iterable<String>
7777
// (Async)Iterable<{ path, content }>
7878
if (isFileObject(value) || isBlob(value) || typeof value === 'string' || value instanceof String) {
79-
yield * map(peekable, (/** @type {ToEntry} */ value) => toFileObject(value, normaliseContent))
79+
yield * map(peekable, (/** @type {ImportCandidate} */ value) => toFileObject(value, normaliseContent))
8080
return
8181
}
8282

@@ -85,7 +85,7 @@ module.exports = async function * normaliseInput (input, normaliseContent) {
8585
// ReadableStream<(Async)Iterable<?>>
8686
// ReadableStream<ReadableStream<?>>
8787
if (value[Symbol.iterator] || value[Symbol.asyncIterator] || isReadableStream(value)) {
88-
yield * map(peekable, (/** @type {ToEntry} */ value) => toFileObject(value, normaliseContent))
88+
yield * map(peekable, (/** @type {ImportCandidate} */ value) => toFileObject(value, normaliseContent))
8989
return
9090
}
9191
}
@@ -102,14 +102,14 @@ module.exports = async function * normaliseInput (input, normaliseContent) {
102102
}
103103

104104
/**
105-
* @param {ToEntry} input
105+
* @param {ImportCandidate} input
106106
* @param {(content:ToContent) => AsyncIterable<Uint8Array>} normaliseContent
107107
*/
108108
async function toFileObject (input, normaliseContent) {
109109
// @ts-ignore - Those properties don't exist on most input types
110110
const { path, mode, mtime, content } = input
111111

112-
/** @type {ImportCandidate} */
112+
/** @type {ImporterImportCandidate} */
113113
const file = {
114114
path: path || '',
115115
mode: parseMode(mode),

packages/ipfs-core-utils/src/files/normalise-input/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function isBlob (obj) {
2222
* An object with a path or content property
2323
*
2424
* @param {any} obj
25-
* @returns {obj is import('ipfs-core-types/src/utils').ToEntry}
25+
* @returns {obj is import('ipfs-core-types/src/utils').ImportCandidate}
2626
*/
2727
function isFileObject (obj) {
2828
return typeof obj === 'object' && (obj.path || obj.content)

packages/ipfs-grpc-client/src/core-api/add-all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async function sendFile (index, sink, content, path, mode, mtime) {
8686
}
8787

8888
/**
89-
* @param {import('ipfs-core-types/src/utils').ImportSource} stream
89+
* @param {import('ipfs-core-types/src/utils').ImportCandidateStream} stream
9090
* @param {import('it-pushable').Pushable<any>} sink
9191
*/
9292
async function sendFiles (stream, sink) {

packages/ipfs-http-client/src/lib/multipart-request.browser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const normaliseInput = require('ipfs-core-utils/src/files/normalise-input/index.
66
const modeToString = require('./mode-to-string')
77

88
/**
9-
* @typedef {import('ipfs-core-types/src/utils').ImportSource} ImportSource
10-
* @typedef {import('ipfs-core-types/src/utils').ToEntry} ToEntry
9+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidateStream} ImportCandidateStream
10+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidate} ImportCandidate
1111
*/
1212

1313
/**
14-
* @param {ImportSource|ToEntry} source
14+
* @param {ImportCandidateStream|ImportCandidate} source
1515
* @param {AbortController} abortController
1616
* @param {Headers|Record<string, string>} [headers]
1717
*/

packages/ipfs-http-client/src/lib/multipart-request.node.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ const merge = require('merge-options').bind({ ignoreUndefined: true })
88
const toStream = require('it-to-stream')
99

1010
/**
11-
* @typedef {import('ipfs-core-types/src/utils').ImportSource} ImportSource
12-
* @typedef {import('ipfs-core-types/src/utils').ToEntry} ToEntry
11+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidateStream} ImportCandidateStream
12+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidate} ImportCandidate
1313
*/
1414

1515
/**
16-
* @param {ImportSource|ToEntry} source
16+
* @param {ImportCandidateStream|ImportCandidate} source
1717
* @param {AbortController} abortController
1818
* @param {Headers|Record<string, string>} [headers]
1919
* @param {string} [boundary]
2020
*/
2121
async function multipartRequest (source, abortController, headers = {}, boundary = `-----------------------------${nanoid()}`) {
2222
/**
23-
* @param {ImportSource|ToEntry} source
23+
* @param {ImportCandidateStream|ImportCandidate} source
2424
*/
2525
async function * streamFiles (source) {
2626
try {

packages/ipfs-http-server/src/api/resources/files-regular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ exports.add = {
303303
}
304304
},
305305
/**
306-
* @param {import('ipfs-core-types/src/utils').ImportSource} source
306+
* @param {import('ipfs-core-types/src/utils').ImportCandidateStream} source
307307
*/
308308
function (source) {
309309
return ipfs.addAll(source, {

packages/ipfs-message-port-client/src/core.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ const {
3939
* @typedef {import('./interface').MessagePortClientOptions} MessagePortClientOptions
4040
* @typedef {import('ipfs-core-types/src/root').API<MessagePortClientOptions>} RootAPI
4141
*
42-
* @typedef {import('ipfs-core-types/src/utils').ToEntry} ToEntry
42+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidate} ImportCandidate
4343
* @typedef {import('ipfs-core-types/src/utils').ToFile} ToFile
4444
* @typedef {import('ipfs-core-types/src/utils').ToDirectory} ToDirectory
4545
* @typedef {import('ipfs-core-types/src/utils').ToContent} ToContent
46-
* @typedef {import('ipfs-core-types/src/utils').ImportSource} ImportSource
46+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidateStream} ImportCandidateStream
4747
*/
4848

4949
/**
@@ -181,7 +181,7 @@ const identity = (v) => v
181181
* Encodes input passed to the `ipfs.add` via the best possible strategy for the
182182
* given input.
183183
*
184-
* @param {ToEntry} input
184+
* @param {ImportCandidate} input
185185
* @param {Transferable[]} transfer
186186
* @returns {EncodedAddInput}
187187
*/
@@ -235,7 +235,7 @@ const encodeAddInput = (input, transfer) => {
235235
* Encodes input passed to the `ipfs.add` via the best possible strategy for the
236236
* given input.
237237
*
238-
* @param {ImportSource} input
238+
* @param {ImportCandidateStream} input
239239
* @param {Transferable[]} transfer
240240
* @returns {EncodedAddAllInput}
241241
*/
@@ -272,7 +272,7 @@ const encodeAddAllInput = (input, transfer) => {
272272
* Function encodes individual item of some `AsyncIterable` by choosing most
273273
* effective strategy.
274274
*
275-
* @param {ToEntry} content
275+
* @param {ImportCandidate} content
276276
* @param {Transferable[]} transfer
277277
* @returns {EncodedAddInput}
278278
*/
@@ -296,7 +296,7 @@ const encodeAsyncIterableContent = (content, transfer) => {
296296
}
297297

298298
/**
299-
* @param {ToEntry} content
299+
* @param {ImportCandidate} content
300300
* @param {Transferable[]} transfer
301301
* @returns {EncodedAddInput}
302302
*/
@@ -388,7 +388,7 @@ const encodeFileContent = (content, transfer) => {
388388
* iterable or `null`.
389389
*
390390
* @template I
391-
* @param {Iterable<I>|ToEntry|ImportSource} input
391+
* @param {Iterable<I>|ImportCandidate|ImportCandidateStream} input
392392
* @returns {Iterable<I>|null}
393393
*/
394394
const asIterable = (input) => {
@@ -406,7 +406,7 @@ const asIterable = (input) => {
406406
* matched `AsyncIterable` or `null`.
407407
*
408408
* @template I
409-
* @param {AsyncIterable<I>|ToEntry|ImportSource} input
409+
* @param {AsyncIterable<I>|ImportCandidate|ImportCandidateStream} input
410410
* @returns {AsyncIterable<I>|null}
411411
*/
412412
const asAsyncIterable = (input) => {

packages/ipfs-message-port-server/src/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const { decodeCID, encodeCID } = require('ipfs-message-port-protocol/src/cid')
1616
* @typedef {import('ipfs-core-types/src/root').AddAllOptions} AddAllOptions
1717
* @typedef {import('ipfs-core-types/src/root').IPFSEntry} IPFSEntry
1818
* @typedef {import('ipfs-message-port-protocol/src/cid').EncodedCID} EncodedCID
19-
* @typedef {import('ipfs-core-types/src/utils').ImportSource} ImportSource
20-
* @typedef {import('ipfs-core-types/src/utils').ToEntry} ToEntry
19+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidateStream} ImportCandidateStream
20+
* @typedef {import('ipfs-core-types/src/utils').ImportCandidate} ImportCandidate
2121
* @typedef {import('ipfs-core-types/src/root').AddResult} AddResult
2222
* @typedef {import('ipfs-message-port-protocol/src/root').EncodedAddInput} EncodedAddInput
2323
* @typedef {import('ipfs-message-port-protocol/src/root').EncodedAddAllInput} EncodedAddAllInput
@@ -188,7 +188,7 @@ exports.CoreService = class CoreService {
188188

189189
/**
190190
* @param {EncodedAddAllInput} input
191-
* @returns {ImportSource}
191+
* @returns {ImportCandidateStream}
192192
*/
193193
const decodeAddAllInput = input =>
194194
decodeIterable(input, decodeFileInput)

0 commit comments

Comments
 (0)