From caf935f79aad73fdc786447fb6e039bc7503bc4f Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 18 Sep 2020 22:50:15 +0200 Subject: [PATCH 01/46] wip: pin.remote.add|ls|rm This adds basic boilerplate for supporting remote pinning commands introduced in https://github.com/ipfs/go-ipfs/pull/7661 License: MIT Signed-off-by: Marcin Rataj --- docs/core-api/PIN.md | 4 ++++ packages/ipfs-http-client/src/pin/index.js | 3 ++- .../ipfs-http-client/src/pin/remote/add.js | 20 ++++++++++++++++++ .../ipfs-http-client/src/pin/remote/index.js | 7 +++++++ .../ipfs-http-client/src/pin/remote/ls.js | 21 +++++++++++++++++++ .../ipfs-http-client/src/pin/remote/rm.js | 20 ++++++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 packages/ipfs-http-client/src/pin/remote/add.js create mode 100644 packages/ipfs-http-client/src/pin/remote/index.js create mode 100644 packages/ipfs-http-client/src/pin/remote/ls.js create mode 100644 packages/ipfs-http-client/src/pin/remote/rm.js diff --git a/docs/core-api/PIN.md b/docs/core-api/PIN.md index fcc0571698..acef4ae877 100644 --- a/docs/core-api/PIN.md +++ b/docs/core-api/PIN.md @@ -25,6 +25,10 @@ - [Options](#options-4) - [Returns](#returns-4) - [Example](#example-4) +- TODO `ipfs.pin.remote.add(ipfsPath, [options])` +- TODO `ipfs.pin.remote.ls([options])` +- TODO `ipfs.pin.remote.rm(requestid)` +- TODO `ipfs.pin.remote.~TBD~replace(requestid, ipfsPath, [options])` ## `ipfs.pin.add(ipfsPath, [options])` diff --git a/packages/ipfs-http-client/src/pin/index.js b/packages/ipfs-http-client/src/pin/index.js index 39f7b5ecc8..8fd6fcc01f 100644 --- a/packages/ipfs-http-client/src/pin/index.js +++ b/packages/ipfs-http-client/src/pin/index.js @@ -5,5 +5,6 @@ module.exports = config => ({ addAll: require('./add-all')(config), ls: require('./ls')(config), rm: require('./rm')(config), - rmAll: require('./rm-all')(config) + rmAll: require('./rm-all')(config), + remote: require('./remote')(config) }) diff --git a/packages/ipfs-http-client/src/pin/remote/add.js b/packages/ipfs-http-client/src/pin/remote/add.js new file mode 100644 index 0000000000..8d87feee61 --- /dev/null +++ b/packages/ipfs-http-client/src/pin/remote/add.js @@ -0,0 +1,20 @@ +'use strict' + +const configure = require('../lib/configure') +const toUrlSearchParams = require('../lib/to-url-search-params') +const toCamel = require('../../lib/object-to-camel') + +module.exports = configure(api => { + return async (path, options = {}) => { + const res = await api.post('pin/remote/add', { + timeout: options.timeout, + signal: options.signal, + searchParams: toUrlSearchParams({ + arg: path, + ...options + }), + headers: options.headers + }) + return toCamel(await res.json()) + } +}) diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js new file mode 100644 index 0000000000..e923029ae0 --- /dev/null +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -0,0 +1,7 @@ +'use strict' + +module.exports = config => ({ + add: require('./add')(config), + ls: require('./ls')(config), + rm: require('./rm')(config) +}) diff --git a/packages/ipfs-http-client/src/pin/remote/ls.js b/packages/ipfs-http-client/src/pin/remote/ls.js new file mode 100644 index 0000000000..21da47f36b --- /dev/null +++ b/packages/ipfs-http-client/src/pin/remote/ls.js @@ -0,0 +1,21 @@ +'use strict' + +const configure = require('../lib/configure') +const toUrlSearchParams = require('../lib/to-url-search-params') +const toCamel = require('../../lib/object-to-camel') + +module.exports = configure(api => { + return async (path, options = {}) => { + const res = await api.post('pin/remote/ls', { + timeout: options.timeout, + signal: options.signal, + searchParams: toUrlSearchParams({ + arg: path, + ...options + }), + headers: options.headers + }) + const pins = await res.json() + return pins.map(toCamel) + } +}) diff --git a/packages/ipfs-http-client/src/pin/remote/rm.js b/packages/ipfs-http-client/src/pin/remote/rm.js new file mode 100644 index 0000000000..4362840ca1 --- /dev/null +++ b/packages/ipfs-http-client/src/pin/remote/rm.js @@ -0,0 +1,20 @@ +'use strict' + +const configure = require('../lib/configure') +const toUrlSearchParams = require('../lib/to-url-search-params') +const toCamel = require('../../lib/object-to-camel') + +module.exports = configure(api => { + return async (path, options = {}) => { + const res = await api.post('pin/remote/rm', { + timeout: options.timeout, + signal: options.signal, + searchParams: toUrlSearchParams({ + arg: path, + ...options + }), + headers: options.headers + }) + return toCamel(await res.json()) + } +}) From 4d54a7c207fcfd546d05a743c139937533f455f9 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 4 Dec 2020 18:08:05 -0800 Subject: [PATCH 02/46] chore: update remote pinning api implementation --- packages/interface-ipfs-core/tsconfig.json | 11 ++ packages/interface-ipfs-core/type/basic.ts | 15 ++ packages/interface-ipfs-core/type/index.ts | 19 +++ .../interface-ipfs-core/type/pin/remote.ts | 106 ++++++++++++ .../type/pin/remote/service.ts | 74 ++++++++ packages/ipfs-http-client/src/pin/index.js | 4 +- .../ipfs-http-client/src/pin/remote/add.js | 20 --- .../ipfs-http-client/src/pin/remote/index.js | 158 +++++++++++++++++- .../ipfs-http-client/src/pin/remote/ls.js | 21 --- .../ipfs-http-client/src/pin/remote/rm.js | 20 --- .../src/pin/remote/service.js | 138 +++++++++++++++ packages/ipfs-http-client/tsconfig.json | 3 + 12 files changed, 522 insertions(+), 67 deletions(-) create mode 100644 packages/interface-ipfs-core/tsconfig.json create mode 100644 packages/interface-ipfs-core/type/basic.ts create mode 100644 packages/interface-ipfs-core/type/index.ts create mode 100644 packages/interface-ipfs-core/type/pin/remote.ts create mode 100644 packages/interface-ipfs-core/type/pin/remote/service.ts delete mode 100644 packages/ipfs-http-client/src/pin/remote/add.js delete mode 100644 packages/ipfs-http-client/src/pin/remote/ls.js delete mode 100644 packages/ipfs-http-client/src/pin/remote/rm.js create mode 100644 packages/ipfs-http-client/src/pin/remote/service.js diff --git a/packages/interface-ipfs-core/tsconfig.json b/packages/interface-ipfs-core/tsconfig.json new file mode 100644 index 0000000000..0be1742148 --- /dev/null +++ b/packages/interface-ipfs-core/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "type", + "package.json", + ] +} diff --git a/packages/interface-ipfs-core/type/basic.ts b/packages/interface-ipfs-core/type/basic.ts new file mode 100644 index 0000000000..5695c90c31 --- /dev/null +++ b/packages/interface-ipfs-core/type/basic.ts @@ -0,0 +1,15 @@ +/** + * Common options across all cancellable requests. + */ +export interface AbortOptions { + /** + * Can be provided to a function that starts a long running task, which will + * be aborted when signal is triggered. + */ + signal?: AbortSignal + /** + * Can be provided to a function that starts a long running task, which will + * be aborted after provided timeout (in ms). + */ + timeout?: number +} diff --git a/packages/interface-ipfs-core/type/index.ts b/packages/interface-ipfs-core/type/index.ts new file mode 100644 index 0000000000..424db1be9a --- /dev/null +++ b/packages/interface-ipfs-core/type/index.ts @@ -0,0 +1,19 @@ + +import * as Basic from './basic' +import * as PinRemote from './pin/remote' + +export { Basic, PinRemote } + +// class Foo implements PinRemote.API { + +// } +// // export { Basic, PinRemote } + +// declare namespace Lib { +// import { AbortOptions } from '/basic' +// import { API } from './pin/remote' +// } + +// export { Lib } + +// // export { Lib } diff --git a/packages/interface-ipfs-core/type/pin/remote.ts b/packages/interface-ipfs-core/type/pin/remote.ts new file mode 100644 index 0000000000..bab855a677 --- /dev/null +++ b/packages/interface-ipfs-core/type/pin/remote.ts @@ -0,0 +1,106 @@ +import CID from 'cids' +import Multiaddr from 'multiaddr' +import { API as Service } from './remote/service' +import { AbortOptions } from '../basic' + +export interface API { + /** + * API for configuring remote pinning services. + */ + service: Service + + /** + * Stores an IPFS object(s) from a given path to a remote pinning service. + */ + add(cid:CID, options:AddOptions & AbortOptions):Promise + + /** + * Returns a list of matching pins on the remote pinning service. + */ + ls(query: Query & AbortOptions): AsyncIterable + + /** + * Removes a single pin object matching query allowing it to be garbage + * collected (if needed). Will error if multiple pins mtach provided + * query. To remove all matches use `rmAll` instead. + */ + rm(query: Query & AbortOptions): Promise + + /** + * Removes all pin object that match given query allowing them to be garbage + * collected if needed. + */ + rmAll(query: Query & AbortOptions): Promise +} + +export interface AddOptions extends RemoteServiceOptions { + /** + * Optional name for pinned data; can be used for lookups later (max 255 + * characters) + */ + name?: string + + /** + * Optional list of multiaddrs known to provide the data (max 20). + */ + origins?: Multiaddr[] + + /** + * If true, will add to the queue on the remote service and return + * RequestID immediately. If false or amitted will wait until pinned on the + * remote service. + */ + background?: boolean +} + +/** + * Reperesents query for matching pin objects. + */ +export interface Query extends RemoteServiceOptions { + /** + * If provided, will only include pin objects that have a CID from the given + * set. + */ + cid?: CID[] + /** + * If passed, will only include pin objects with names that have this name + * (case-sensitive, exact match). + */ + name?: string + + /** + * Customize the text matching strategy applied when name filter is present. + * Uses "exact" if omitted. + */ + match?: TextMatchingStrategy + + /** + * Return pin objects for pins that have one of the specified status values. + * If omitted treated as ["pinned"] + */ + status?: Status[] +} + +export interface RemoteServiceOptions { + /** + * Name of the remote pinning service to use. + */ + service: string +} + +export interface Pin { + status: Status + cid: CID + name?: string +} + +export type TextMatchingStrategy = + | 'exact' + | 'iexact' + | 'partial' + | 'ipartial' +export type Status = + | 'queued' + | 'pinning' + | 'pinned' + | 'failed' diff --git a/packages/interface-ipfs-core/type/pin/remote/service.ts b/packages/interface-ipfs-core/type/pin/remote/service.ts new file mode 100644 index 0000000000..d75ef073f1 --- /dev/null +++ b/packages/interface-ipfs-core/type/pin/remote/service.ts @@ -0,0 +1,74 @@ +import { AbortOptions } from '../../basic' + +export interface API { + /** + * Registers remote pinning service with a given name. Errors if service + * with the given name is already registered. + */ + add(name: string, credentials:Credentials & AbortOptions): Promise + + /** + * Unregisteres remote pinning service with a given name. If service with such + * name isn't registerede this is a noop. + */ + rm(name: string, options?:AbortOptions):Promise + + /** + * List registered remote pinning services. + */ + ls(options:ListOptions & AbortOptions):Promise +} + +export interface Credentials { + /** + * Service URL + */ + url: URL + /** + * Service key + */ + key: string +} + +export interface RemotePinService { + /** + * Service name + */ + service: string + /** + * Service URL + */ + url: URL + /** + * Pin count on the remote service. It is fetched from the remote service and + * is done only if `pinCount` option is used. Furthermore it may not be + * present if service was unreachable. + */ + stat?: Stat +} + +export interface ListOptions { + /** + * If `true` will try to fetch and include current pin count on the remote + * service. + */ + stat?: boolean +} + +export type Stat = ValidStat | InvalidStat + +type ValidStat = { + status: 'valid' + pinCount: PinCount +} + +type InvalidStat = { + status: 'invalid' + pinCount?: void +} +export type PinCount = { + queued: number, + pinning: number, + pinned: number, + failed: number +} diff --git a/packages/ipfs-http-client/src/pin/index.js b/packages/ipfs-http-client/src/pin/index.js index 8fd6fcc01f..e27a8af501 100644 --- a/packages/ipfs-http-client/src/pin/index.js +++ b/packages/ipfs-http-client/src/pin/index.js @@ -1,10 +1,12 @@ 'use strict' +const Remote = require('./remote') + module.exports = config => ({ add: require('./add')(config), addAll: require('./add-all')(config), ls: require('./ls')(config), rm: require('./rm')(config), rmAll: require('./rm-all')(config), - remote: require('./remote')(config) + remote: new Remote(config) }) diff --git a/packages/ipfs-http-client/src/pin/remote/add.js b/packages/ipfs-http-client/src/pin/remote/add.js deleted file mode 100644 index 8d87feee61..0000000000 --- a/packages/ipfs-http-client/src/pin/remote/add.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict' - -const configure = require('../lib/configure') -const toUrlSearchParams = require('../lib/to-url-search-params') -const toCamel = require('../../lib/object-to-camel') - -module.exports = configure(api => { - return async (path, options = {}) => { - const res = await api.post('pin/remote/add', { - timeout: options.timeout, - signal: options.signal, - searchParams: toUrlSearchParams({ - arg: path, - ...options - }), - headers: options.headers - }) - return toCamel(await res.json()) - } -}) diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js index e923029ae0..1aac78b864 100644 --- a/packages/ipfs-http-client/src/pin/remote/index.js +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -1,7 +1,155 @@ 'use strict' -module.exports = config => ({ - add: require('./add')(config), - ls: require('./ls')(config), - rm: require('./rm')(config) -}) +const CID = require('cids') +const Client = require('../../lib/core') +const Service = require('./service') +const toUrlSearchParams = require('../../lib/to-url-search-params') + +/** + * @typedef {import('../..').HttpOptions} HttpOptions + * @typedef {import('../../lib/core').ClientOptions} ClientOptions + * @typedef {import('interface-ipfs-core/type/basic').AbortOptions} AbortOptions + * @typedef {import('interface-ipfs-core/type/pin/remote').API} API + * @typedef {import('interface-ipfs-core/type/pin/remote').Pin} Pin + * @typedef {import('interface-ipfs-core/type/pin/remote').AddOptions} AddOptions + * @typedef {import('interface-ipfs-core/type/pin/remote').Query} Query + * + * @implements {API} + */ +class Remote { + /** + * @param {ClientOptions} options + */ + constructor (options) { + /** @private */ + this.client = new Client(options) + /** @readonly */ + this.service = new Service(options) + } + + /** + * Stores an IPFS object(s) from a given path to a remote pinning service. + * + * @param {CID} cid + * @param {AddOptions & AbortOptions & HttpOptions} options + * @returns {Promise} + */ + add (cid, options) { + return Remote.add(this.client, cid, options) + } + + /** + * @param {Client} client + * @param {CID} cid + * @param {AddOptions & AbortOptions & HttpOptions} options + */ + static async add (client, cid, { timeout, signal, headers, ...options }) { + const { name, origins, background, service } = options + const response = await client.post('pin/remote/add', { + timeout, + signal, + headers, + searchParams: toUrlSearchParams({ + arg: cid.toString(), + service, + name, + origins, + background + }) + }) + + return Remote.decodePin(await response.json()) + } + + /** + * @param {Object} json + * @returns {Pin} + */ + static decodePin ({ Name: name, Status: status, Cid: cid }) { + return { + cid: new CID(cid), + name, + status + } + } + + /** + * Returns a list of matching pins on the remote pinning service. + * + * @param {Query & AbortOptions & HttpOptions} query + */ + ls (query) { + return Remote.ls(this.client, query) + } + + /** + * + * @param {Client} client + * @param {Query & AbortOptions & HttpOptions} options + * @returns {AsyncIterable} + */ + static async * ls (client, { timeout, signal, headers, ...query }) { + const response = await client.post('pin/remote/ls', { + signal, + timeout, + headers, + searchParams: Remote.encodeQuery(query) + }) + + for await (const pin of response.ndjson()) { + yield Remote.decodePin(pin) + } + } + + /** + * @param {Query & { all?: boolean }} query + * @returns {URLSearchParams} + */ + static encodeQuery ({ service, cid, name, match, status, all }) { + return toUrlSearchParams({ + service, + name, + match, + status, + force: all ? true : undefined, + cid: cid && cid.map(String) + }) + } + + /** + * Removes a single pin object matching query allowing it to be garbage + * collected (if needed). Will error if multiple pins mtach provided + * query. To remove all matches use `rmAll` instead. + * + * @param {Query & AbortOptions & HttpOptions} query + */ + rm (query) { + return Remote.rm(this.client, { ...query, all: false }) + } + + /** + * Removes all pin object that match given query allowing them to be garbage + * collected if needed. + * + * @param {Query & AbortOptions & HttpOptions} query + */ + rmAll (query) { + return Remote.rm(this.client, { ...query, all: true }) + } + + /** + * + * @param {Client} client + * @param {{all: boolean} & Query & AbortOptions & HttpOptions} options + */ + static async rm (client, { timeout, signal, headers, ...query }) { + await client.post('pin/remote/rm', { + timeout, + signal, + headers, + searchParams: Remote.encodeQuery(query) + }) + } +} + +module.exports = Remote diff --git a/packages/ipfs-http-client/src/pin/remote/ls.js b/packages/ipfs-http-client/src/pin/remote/ls.js deleted file mode 100644 index 21da47f36b..0000000000 --- a/packages/ipfs-http-client/src/pin/remote/ls.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict' - -const configure = require('../lib/configure') -const toUrlSearchParams = require('../lib/to-url-search-params') -const toCamel = require('../../lib/object-to-camel') - -module.exports = configure(api => { - return async (path, options = {}) => { - const res = await api.post('pin/remote/ls', { - timeout: options.timeout, - signal: options.signal, - searchParams: toUrlSearchParams({ - arg: path, - ...options - }), - headers: options.headers - }) - const pins = await res.json() - return pins.map(toCamel) - } -}) diff --git a/packages/ipfs-http-client/src/pin/remote/rm.js b/packages/ipfs-http-client/src/pin/remote/rm.js deleted file mode 100644 index 4362840ca1..0000000000 --- a/packages/ipfs-http-client/src/pin/remote/rm.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict' - -const configure = require('../lib/configure') -const toUrlSearchParams = require('../lib/to-url-search-params') -const toCamel = require('../../lib/object-to-camel') - -module.exports = configure(api => { - return async (path, options = {}) => { - const res = await api.post('pin/remote/rm', { - timeout: options.timeout, - signal: options.signal, - searchParams: toUrlSearchParams({ - arg: path, - ...options - }), - headers: options.headers - }) - return toCamel(await res.json()) - } -}) diff --git a/packages/ipfs-http-client/src/pin/remote/service.js b/packages/ipfs-http-client/src/pin/remote/service.js new file mode 100644 index 0000000000..5fb78c8750 --- /dev/null +++ b/packages/ipfs-http-client/src/pin/remote/service.js @@ -0,0 +1,138 @@ +'use strict' + +const Client = require('../../lib/core') +const toUrlSearchParams = require('../../lib/to-url-search-params') + +/** + * @typedef {import('../../lib/core').ClientOptions} ClientOptions + * @typedef {import('../..').HttpOptions} HttpOptions + * @typedef {import('interface-ipfs-core/type/basic').AbortOptions} AbortOptions + * @typedef {import('interface-ipfs-core/type/pin/remote/service').API} API + * @typedef {import('interface-ipfs-core/type/pin/remote/service').Credentials} Credentials + * @typedef {import('interface-ipfs-core/type/pin/remote/service').ListOptions} ListOptions + * @typedef {import('interface-ipfs-core/type/pin/remote/service').RemotePinService} RemotePinService + * @implements {API} + */ +class Service { + /** + * @param {ClientOptions} options + */ + constructor (options) { + /** @private */ + this.client = new Client(options) + } + + /** + * @param {Client} client + * @param {string} name + * @param {Credentials & AbortOptions & HttpOptions} options + */ + static async add (client, name, options) { + const { url, key, headers, timeout, signal } = options + await client.post('pin/remote/servire/rm', { + timeout, + signal, + searchParams: toUrlSearchParams({ + arg: [name, url, key] + }), + headers + }) + } + + /** + * @param {Client} client + * @param {string} name + * @param {AbortOptions & HttpOptions} [options] + */ + static async rm (client, name, { timeout, signal, headers } = {}) { + await client.post('pin/remote/add', { + timeout, + signal, + headers, + searchParams: toUrlSearchParams({ + arg: name + }) + }) + } + + /** + * @param {Client} client + * @param {ListOptions & AbortOptions & HttpOptions} [options] + */ + static async ls (client, { stat, timeout, signal, headers } = {}) { + const response = await client.post('pin/remote/service/ls', { + searchParams: stat === true ? toUrlSearchParams({ stat }) : undefined, + timeout, + signal, + headers + }) + /** @type {{RemoteServices: Object[]}} */ + const { RemoteServices } = await response.json() + return RemoteServices.map(Service.decodeRemoteService) + } + + /** + * @param {Object} json + * @returns {import('interface-ipfs-core/type/pin/remote/service').RemotePinService} + */ + static decodeRemoteService (json) { + return { + service: json.Service, + url: new URL(json.ApiEndpoint), + stat: Service.decodeStat(json.stat) + } + } + + /** + * @param {Object} json + * @returns {import('interface-ipfs-core/type/pin/remote/service').Stat|undefined} + */ + static decodeStat (json) { + switch (json.Status) { + case 'valid': { + return { + status: 'valid', + pinCount: json.PinCount + } + } + case 'invalid': { + return { status: 'invalid' } + } + default: + return undefined + } + } + + /** + * Registers remote pinning service with a given name. Errors if service + * with the given name is already registered. + * + * @param {string} name + * @param {Credentials & AbortOptions & HttpOptions} options + */ + add (name, options) { + return Service.add(this.client, name, options) + } + + /** + * Unregisteres remote pinning service with a given name. If service with such + * name isn't registerede this is a noop. + * + * @param {string} name + * @param {AbortOptions & HttpOptions} [options] + */ + rm (name, options) { + return Service.rm(this.client, name, options) + } + + /** + * List registered remote pinning services. + * + * @param {ListOptions & AbortOptions & HttpOptions} [options] + */ + ls (options) { + return Service.ls(this.client, options) + } +} + +module.exports = Service diff --git a/packages/ipfs-http-client/tsconfig.json b/packages/ipfs-http-client/tsconfig.json index bbdcd5851e..7d1242110c 100644 --- a/packages/ipfs-http-client/tsconfig.json +++ b/packages/ipfs-http-client/tsconfig.json @@ -13,6 +13,9 @@ }, { "path": "../ipfs-core" + }, + { + "path": "../interface-ipfs-core" } ] } From 9669fc6ead078c9fd40b4605319ecb219d495975 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 09:57:27 -0800 Subject: [PATCH 03/46] fix: rename url field to endpoint --- .../interface-ipfs-core/type/pin/remote/service.ts | 10 ++++++---- packages/ipfs-http-client/src/pin/remote/service.js | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/interface-ipfs-core/type/pin/remote/service.ts b/packages/interface-ipfs-core/type/pin/remote/service.ts index d75ef073f1..0f50081a92 100644 --- a/packages/interface-ipfs-core/type/pin/remote/service.ts +++ b/packages/interface-ipfs-core/type/pin/remote/service.ts @@ -21,9 +21,9 @@ export interface API { export interface Credentials { /** - * Service URL + * Service endpoint */ - url: URL + endpoint: URL /** * Service key */ @@ -36,9 +36,11 @@ export interface RemotePinService { */ service: string /** - * Service URL + * Service endpoint URL */ - url: URL + endpoint: URL +} + /** * Pin count on the remote service. It is fetched from the remote service and * is done only if `pinCount` option is used. Furthermore it may not be diff --git a/packages/ipfs-http-client/src/pin/remote/service.js b/packages/ipfs-http-client/src/pin/remote/service.js index 5fb78c8750..659b25849a 100644 --- a/packages/ipfs-http-client/src/pin/remote/service.js +++ b/packages/ipfs-http-client/src/pin/remote/service.js @@ -28,12 +28,12 @@ class Service { * @param {Credentials & AbortOptions & HttpOptions} options */ static async add (client, name, options) { - const { url, key, headers, timeout, signal } = options + const { endpoint, key, headers, timeout, signal } = options await client.post('pin/remote/servire/rm', { timeout, signal, searchParams: toUrlSearchParams({ - arg: [name, url, key] + arg: [name, endpoint, key] }), headers }) @@ -78,7 +78,7 @@ class Service { static decodeRemoteService (json) { return { service: json.Service, - url: new URL(json.ApiEndpoint), + endpoint: new URL(json.ApiEndpoint), stat: Service.decodeStat(json.stat) } } From e1ec19d23165ab1210a9cdd94b3b4adf32840d2a Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 11:40:56 -0800 Subject: [PATCH 04/46] fix: make ls type more intelegent in regards stats --- .../type/pin/remote/service.ts | 14 ++++-------- .../src/pin/remote/service.js | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/interface-ipfs-core/type/pin/remote/service.ts b/packages/interface-ipfs-core/type/pin/remote/service.ts index 0f50081a92..8885219bba 100644 --- a/packages/interface-ipfs-core/type/pin/remote/service.ts +++ b/packages/interface-ipfs-core/type/pin/remote/service.ts @@ -16,7 +16,8 @@ export interface API { /** * List registered remote pinning services. */ - ls(options:ListOptions & AbortOptions):Promise + ls(options: { stat: true } & AbortOptions): Promise + ls(options?: AbortOptions):Promise } export interface Credentials { @@ -41,20 +42,13 @@ export interface RemotePinService { endpoint: URL } +export interface RemotePinServiceWithStat extends RemotePinService { /** * Pin count on the remote service. It is fetched from the remote service and * is done only if `pinCount` option is used. Furthermore it may not be * present if service was unreachable. */ - stat?: Stat -} - -export interface ListOptions { - /** - * If `true` will try to fetch and include current pin count on the remote - * service. - */ - stat?: boolean + stat: Stat } export type Stat = ValidStat | InvalidStat diff --git a/packages/ipfs-http-client/src/pin/remote/service.js b/packages/ipfs-http-client/src/pin/remote/service.js index 659b25849a..07f0c21051 100644 --- a/packages/ipfs-http-client/src/pin/remote/service.js +++ b/packages/ipfs-http-client/src/pin/remote/service.js @@ -9,8 +9,8 @@ const toUrlSearchParams = require('../../lib/to-url-search-params') * @typedef {import('interface-ipfs-core/type/basic').AbortOptions} AbortOptions * @typedef {import('interface-ipfs-core/type/pin/remote/service').API} API * @typedef {import('interface-ipfs-core/type/pin/remote/service').Credentials} Credentials - * @typedef {import('interface-ipfs-core/type/pin/remote/service').ListOptions} ListOptions * @typedef {import('interface-ipfs-core/type/pin/remote/service').RemotePinService} RemotePinService + * @typedef {import('interface-ipfs-core/type/pin/remote/service').RemotePinServiceWithStat} RemotePinServiceWithStat * @implements {API} */ class Service { @@ -56,8 +56,9 @@ class Service { } /** + * @template {true} Stat * @param {Client} client - * @param {ListOptions & AbortOptions & HttpOptions} [options] + * @param {{ stat?: Stat } & AbortOptions & HttpOptions} [options] */ static async ls (client, { stat, timeout, signal, headers } = {}) { const response = await client.post('pin/remote/service/ls', { @@ -68,24 +69,26 @@ class Service { }) /** @type {{RemoteServices: Object[]}} */ const { RemoteServices } = await response.json() - return RemoteServices.map(Service.decodeRemoteService) + + /** @type {Stat extends true ? RemotePinServiceWithStat[] : RemotePinService []} */ + return (RemoteServices.map(Service.decodeRemoteService)) } /** * @param {Object} json - * @returns {import('interface-ipfs-core/type/pin/remote/service').RemotePinService} + * @returns {RemotePinServiceWithStat} */ static decodeRemoteService (json) { return { service: json.Service, endpoint: new URL(json.ApiEndpoint), - stat: Service.decodeStat(json.stat) + stat: json.stat && Service.decodeStat(json.stat) } } /** * @param {Object} json - * @returns {import('interface-ipfs-core/type/pin/remote/service').Stat|undefined} + * @returns {import('interface-ipfs-core/type/pin/remote/service').Stat} */ static decodeStat (json) { switch (json.Status) { @@ -98,8 +101,9 @@ class Service { case 'invalid': { return { status: 'invalid' } } - default: - return undefined + default: { + return { status: json.Status } + } } } @@ -128,7 +132,7 @@ class Service { /** * List registered remote pinning services. * - * @param {ListOptions & AbortOptions & HttpOptions} [options] + * @param {{ stat?: true } & AbortOptions & HttpOptions} [options] */ ls (options) { return Service.ls(this.client, options) From 7f4783dffdc45d08d00792c88dadf4b556934270 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 11:41:48 -0800 Subject: [PATCH 05/46] chore: remove obsolete code --- packages/interface-ipfs-core/type/index.ts | 19 ------------------- .../interface-ipfs-core/type/pin/remote.ts | 11 ----------- 2 files changed, 30 deletions(-) delete mode 100644 packages/interface-ipfs-core/type/index.ts diff --git a/packages/interface-ipfs-core/type/index.ts b/packages/interface-ipfs-core/type/index.ts deleted file mode 100644 index 424db1be9a..0000000000 --- a/packages/interface-ipfs-core/type/index.ts +++ /dev/null @@ -1,19 +0,0 @@ - -import * as Basic from './basic' -import * as PinRemote from './pin/remote' - -export { Basic, PinRemote } - -// class Foo implements PinRemote.API { - -// } -// // export { Basic, PinRemote } - -// declare namespace Lib { -// import { AbortOptions } from '/basic' -// import { API } from './pin/remote' -// } - -// export { Lib } - -// // export { Lib } diff --git a/packages/interface-ipfs-core/type/pin/remote.ts b/packages/interface-ipfs-core/type/pin/remote.ts index bab855a677..07448ef07c 100644 --- a/packages/interface-ipfs-core/type/pin/remote.ts +++ b/packages/interface-ipfs-core/type/pin/remote.ts @@ -68,12 +68,6 @@ export interface Query extends RemoteServiceOptions { */ name?: string - /** - * Customize the text matching strategy applied when name filter is present. - * Uses "exact" if omitted. - */ - match?: TextMatchingStrategy - /** * Return pin objects for pins that have one of the specified status values. * If omitted treated as ["pinned"] @@ -94,11 +88,6 @@ export interface Pin { name?: string } -export type TextMatchingStrategy = - | 'exact' - | 'iexact' - | 'partial' - | 'ipartial' export type Status = | 'queued' | 'pinning' From e46491434552818aec5568aa191c3e181b53469c Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 11:42:35 -0800 Subject: [PATCH 06/46] feat: improve API documntation --- docs/core-api/PIN.md | 428 +++++++++++++++++- .../interface-ipfs-core/type/pin/remote.ts | 4 +- 2 files changed, 415 insertions(+), 17 deletions(-) diff --git a/docs/core-api/PIN.md b/docs/core-api/PIN.md index c3cc004e2e..cd68eb3d52 100644 --- a/docs/core-api/PIN.md +++ b/docs/core-api/PIN.md @@ -25,10 +25,37 @@ - [Options](#options-4) - [Returns](#returns-4) - [Example](#example-4) -- TODO `ipfs.pin.remote.add(ipfsPath, [options])` -- TODO `ipfs.pin.remote.ls([options])` -- TODO `ipfs.pin.remote.rm(requestid)` -- TODO `ipfs.pin.remote.~TBD~replace(requestid, ipfsPath, [options])` +- [`ipfs.pin.remote.service.add(name, options)`](#ipfspinremoteserviceaddname-options) + - [Parameters](#parameters-5) + - [Options](#options-5) + - [Returns](#returns-5) + - [Example](#example-5) +- [`ipfs.pin.remote.service.ls([options])`](#ipfspinremoteservicels_options) + - [Options](#options-6) + - [Returns](#returns-6) + - [Example](#example-6) +- [`ipfs.pin.remote.service.rm(name, [options])`](#ipfspinremoteservicermname-options) + - [Parameters](#parameters-6) + - [Options](#options-7) + - [Returns](#returns-7) + - [Example](#example-7) +- [`ipfs.pin.remote.add(cid, [options])`](#ipfspinremoteaddcid-options) + - [Parameters](#parameters-7) + - [Options](#options-8) + - [Returns](#returns-8) + - [Example](#example-8) +- [`ipfs.pin.remote.ls(options)`](#ipfspinremotelsoptions) + - [Options](#options-9) + - [Returns](#returns-9) + - [Example](#example-9) +- [`ipfs.pin.remote.rm(options)`](#ipfspinremotermoptions) + - [Options](#options-10) + - [Returns](#returns-10) + - [Example](#example-10) +- [`ipfs.pin.remote.rmAll(options)`](#ipfspinremotermalloptions) + - [Options](#options-11) + - [Returns](#returns-11) + - [Example](#example-11) ## `ipfs.pin.add(ipfsPath, [options])` @@ -38,7 +65,7 @@ | Name | Type | Description | | ---- | ---- | ----------- | -| source | [CID][] or String | A CID or IPFS Path to pin in your repo | +| source | [CID][] or `string` | A CID or IPFS Path to pin in your repo | ### Options @@ -47,7 +74,7 @@ An optional object which may have the following keys: | Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | recursive | `boolean` | `true` | Recursively pin all links contained by the object | -| timeout | `Number` | `undefined` | A timeout in ms | +| timeout | `number` | `undefined` | A timeout in ms | | signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | ### Returns @@ -75,7 +102,7 @@ A great source of [examples][] can be found in the tests for this API. | Name | Type | Description | | ---- | ---- | ----------- | -| source | `AsyncIterable<{ cid: CID, path: String, recursive: Boolean, comments: String }>` | One or more CIDs or IPFS Paths to pin in your repo | +| source | `AsyncIterable<{ cid: CID, path: string, recursive: boolean, comments: string }>` | One or more CIDs or IPFS Paths to pin in your repo | ### Options @@ -83,7 +110,7 @@ An optional object which may have the following keys: | Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | -| timeout | `Number` | `undefined` | A timeout in ms | +| timeout | `number` | `undefined` | A timeout in ms | | signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | ### Returns @@ -127,9 +154,9 @@ An optional object which may have the following keys: | Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | -| paths | [CID][] or `Array` or `String` or `Array` | CIDs or IPFS paths to search for in the pinset | -| type | `String` | `undefined` | Filter by this type of pin ("recursive", "direct" or "indirect") | -| timeout | `Number` | `undefined` | A timeout in ms | +| paths | [CID][] or `Array` or `string` or `Array` | CIDs or IPFS paths to search for in the pinset | +| type | `string` | `undefined` | Filter by this type of pin ("recursive", "direct" or "indirect") | +| timeout | `number` | `undefined` | A timeout in ms | | signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | ### Returns @@ -170,7 +197,7 @@ A great source of [examples][] can be found in the tests for this API. | Name | Type | Description | | ---- | ---- | ----------- | -| ipfsPath | [CID][] of String | Unpin this CID or IPFS Path | +| ipfsPath | [CID][] of string | Unpin this CID or IPFS Path | ### Options @@ -179,7 +206,7 @@ An optional object which may have the following keys: | Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | recursive | `boolean` | `true` | Recursively unpin the object linked | -| timeout | `Number` | `undefined` | A timeout in ms | +| timeout | `number` | `undefined` | A timeout in ms | | signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | ### Returns @@ -207,7 +234,7 @@ A great source of [examples][] can be found in the tests for this API. | Name | Type | Description | | ---- | ---- | ----------- | -| source | [CID][], String or `AsyncIterable<{ cid: CID, path: String, recursive: Boolean }>` | Unpin this CID | +| source | [CID][], string or `AsyncIterable<{ cid: CID, path: string, recursive: boolean }>` | Unpin this CID | ### Options @@ -215,7 +242,7 @@ An optional object which may have the following keys: | Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | -| timeout | `Number` | `undefined` | A timeout in ms | +| timeout | `number` | `undefined` | A timeout in ms | | signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | ### Returns @@ -236,6 +263,377 @@ for await (const cid of ipfs.pin.rmAll(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH56 A great source of [examples][] can be found in the tests for this API. +## `ipfs.pin.remote.service.add(name, options)` + +> Registers remote pinning service with a given name. Errors if service with the given name is already registered. + +### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| name | `string` | Service name | + +### Options + +An object which must contain following fields: + +| Name | Type | Description | +| ---- | ---- | ----------- | +| endpoint | `string` | Service endpoint URL | +| key | `string` | Service key | + + + +An object may have the following optional fields: + +| Name | Type | Default | Description | +| ---- | ---- | ------- | ----------- | +| timeout | `number` | `undefined` | A timeout in ms | +| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | + +### Returns + +| Type | Description | +| ---- | -------- | +| Promise | Resolves if added succesfully, or fails with error e.g. if service with such name is already registered | + + +### Example + +```JavaScript +await ipfs.pin.remote.sevice.add('pinata', { + endpoint: new URL('https://api.pinata.cloud'), + name: 'block-party' +}) +``` + +A great source of [examples][] can be found in the tests for this API. + + +## `ipfs.pin.remote.service.ls([options])` + +> List registered remote pinning services. + +### Options + +An object may have the following optional fields: + +| Name | Type | Default | Description | +| ---- | ---- | ------- | ----------- | +| stat | `boolean` | `false` | If `true` will include service stats. | +| timeout | `number` | `undefined` | A timeout in ms | +| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | + +### Returns + +| Type | Description | +| ---- | -------- | +| Promise<[RemotePinService][][]> | List of registered services | + +#### `RemotePinService` + +Object contains following fields: + +| Name | Type | Description | +| ---- | ---- | -------- | +| service | `string` | Service name | +| endpoint | `URL` | Service endpoint URL | +| stat | [Stat][] | Is included only when `stat: true` option was passed | + +#### `Stat` + +If stats could not be fetched from service (e.g. endpoint was unreachable) object has following form: + +| Name | Type | Description | +| ---- | ---- | -------- | +| status | `'invalid'` | Service status | + + +If stats were fetched from service succesfully object has following form: + +| Name | Type | Description | +| ---- | ---- | -------- | +| status | `'valid'` | Service status | +| pinCount | [PinCount][] | Pin counts | + +#### `PinCount` + +Object has following fields: + +| Name | Type | Description | +| ---- | ---- | ----------- | +| queued | `number` | Number of queued pins | +| pinning | `number` | Number of pins that are pinning | +| pinned | `number` | Number of pinned pins | +| failed | `number` | Number of faield pins | + + + +### Example + +```JavaScript +await ipfs.pin.remote.sevice.ls() +// [{ +// service: 'pinata' +// endpoint: new URL('https://api.pinata.cloud'), +// }] + +await ipfs.pin.remote.service.ls({ stat: true }) +// [{ +// service: 'pinata' +// endpoint: new URL('https://api.pinata.cloud'), +// stat: { +// status: 'valid', +// pinCount: { +// queued: 0, +// pinning: 0, +// pinned: 1, +// failed: 0, +// } +// } +// }] +``` + +A great source of [examples][] can be found in the tests for this API. + + +## `ipfs.pin.remote.service.rm(name, [options])` + +> Unregisteres remote pinning service with a given name (if service with such name is regisetered). + +### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| name | `string` | Service name | + +### Options + +An object may have the following optional fields: + +| Name | Type | Default | Description | +| ---- | ---- | ------- | ----------- | +| timeout | `number` | `undefined` | A timeout in ms | +| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | + +### Returns + +| Type | Description | +| ---- | -------- | +| Promise | Resolves on completion | + + +### Example + +```JavaScript +await ipfs.pin.remote.sevice.rm('pinata') +``` + +A great source of [examples][] can be found in the tests for this API. + + +## `ipfs.pin.remote.add(cid, [options])` + +> Pin a content with a given CID to a remote pinning service + +### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| cid | [CID][] | A CID to pin on a remote pinning service | + +### Options + +An object which must contain following fields: + +| Name | Type | Description | +| ---- | ---- | ----------- | +| service | `string` | Name of the remote pinning service to use | + + +An object may have the following optional fields: + +| Name | Type | Default | Description | +| ---- | ---- | ------- | ----------- | +| name | `string` | `undefined` | Name for pinned data; can be used for lookups later (max 255 characters) | +| origins | `Multiaddr[]` | `undefined` | List of multiaddrs known to provide the data (max 20) | +| background | `boolean` | `false` | If true, will add to the queue on the remote service and return immediately. If false or omitted will wait until pinned on the remote service | +| timeout | `number` | `undefined` | A timeout in ms | +| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | + +### Returns + +| Type | Description | +| ---- | -------- | +| [Pin][] | Pin Object | + +#### `Pin` + +Object has following fields: + +| Type | Description | +| ---- | ----------- | +| [Status][] | Pin status | +| [CID][] | CID of the content | +| `string | undefined` | name that was given to the pin, or `undefined` if no name was not given | + +#### `Status` + +Status is one of the following string values: + +`'queued'`, `'pinning'`, `'pinned'`, `'failed'` + +### Example + +```JavaScript +const cid = new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u') +const pin = await ipfs.pin.remote.add(cid, { + service: 'pinata', + name: 'block-party' +}) +console.log(pin) +// Logs: +// { +// status: 'pinned', +// cid: CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'), +// name: 'block-party' +// } +``` + +A great source of [examples][] can be found in the tests for this API. + +## `ipfs.pin.remote.ls(options)` + +> Returns a list of matching pins on the remote pinning service. + + +### Options + +An object which must contain following fields: + +| Name | Type | Description | +| ---- | ---- | ----------- | +| service | `string` | Name of the remote pinning service to use | + +An object may have the following optional fields: + +| Name | Type | Default | Description | +| ---- | ---- | ------- | ----------- | +| cid | [CID][][] | `undefined` | If provided, will only include pin objects that have a CID from the given set. | +| name | `string` | `undefined` | If passed, will only include pin objects with names that have this name (case-sensitive, exact match). | +| status | [Status][][] | ['pinned'] | Return pin objects for pins that have one of the specified status values | +| timeout | `number` | `undefined` | A timeout in ms | +| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | + +### Returns + +| Type | Description | +| ---- | -------- | +| AyncIterable<[Pin][]> | Pin Objects | + +### Example + +```JavaScript +const pins = await ipfs.pin.remote.ls({ + service: 'pinata' +}) +console.log(pins) +// Logs: +// [{ +// status: 'pinned', +// cid: CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'), +// name: 'block-party' +// }] +``` + +A great source of [examples][] can be found in the tests for this API. + +## `ipfs.pin.remote.rm(options)` + +> Removes a single matching pin object from the remote pinning service. Will error when multiple pins mtach, to remove all matches `rmAll` should be used instead. + +### Options + +An object which must contain following fields: + +| Name | Type | Description | +| ---- | ---- | ----------- | +| service | `string` | Name of the remote pinning service to use | + +An object may also contain following optional fields: + +| Name | Type | Default | Description | +| ---- | ---- | ------- | ----------- | +| cid | [CID][][] | `undefined` | If provided, will match pin object(s) that have a CID from the given set. | +| name | `string` | `undefined` | If provided, will match pin object(s) with exact (case-sensitive) name. | +| status | [Status][][] | ['pinned'] | If provided, will match pin object(s) that have a status from the given set. | +| timeout | `number` | `undefined` | A timeout in ms | +| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | + +### Returns + +| Type | Description | +| ---- | -------- | +| Promise | Succeeds on completion | + +### Example + +```JavaScript +await ipfs.pin.remote.rm({ + service: 'pinata', + name: 'block-party' +}) +``` + +A great source of [examples][] can be found in the tests for this API. + +## `ipfs.pin.remote.rmAll(options)` + +> Removes all the matching pin objects from the remote pinning +service. + +### Options + +An object which must contain following fields: + +| Name | Type | Description | +| ---- | ---- | ----------- | +| service | `string` | Name of the remote pinning service to use | + +An object may also contain following optional fields: + +| Name | Type | Default | Description | +| ---- | ---- | ------- | ----------- | +| cid | [CID][][] | `undefined` | If provided, will match pin object(s) that have a CID from the given set. | +| name | `string` | `undefined` | If provided, will match pin object(s) with exact (case-sensitive) name. | +| status | [Status][][] | ['pinned'] | If provided, will match pin object(s) that have a status from the given set. | +| timeout | `number` | `undefined` | A timeout in ms | +| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | + +### Returns + +| Type | Description | +| ---- | -------- | +| Promise | Succeeds on completion | + +### Example + +```JavaScript +// Delete all non 'pinned' pins +await ipfs.pin.remote.rmAll({ + service: 'pinata', + status: ['queued', 'pinning', 'failed'] +}) +``` + +A great source of [examples][] can be found in the tests for this API. + +[Pin]: #pin +[Status]: #status +[RemotePinService]: #remotepinservice +[Status]: #status +[Stat]: #stat +[PinCount]: #pincount [examples]: https://github.com/ipfs/js-ipfs/blob/master/packages/interface-ipfs-core/src/pin [cid]: https://www.npmjs.com/package/cids [AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal diff --git a/packages/interface-ipfs-core/type/pin/remote.ts b/packages/interface-ipfs-core/type/pin/remote.ts index 07448ef07c..f9815ed33d 100644 --- a/packages/interface-ipfs-core/type/pin/remote.ts +++ b/packages/interface-ipfs-core/type/pin/remote.ts @@ -10,7 +10,7 @@ export interface API { service: Service /** - * Stores an IPFS object(s) from a given path to a remote pinning service. + * Pin a content with a given CID to a remote pinning service. */ add(cid:CID, options:AddOptions & AbortOptions):Promise @@ -47,7 +47,7 @@ export interface AddOptions extends RemoteServiceOptions { /** * If true, will add to the queue on the remote service and return - * RequestID immediately. If false or amitted will wait until pinned on the + * immediately. If false or omitted will wait until pinned on the * remote service. */ background?: boolean From 28871af1cf494b5330f44fd0f13fb98ff90226b5 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 11:43:49 -0800 Subject: [PATCH 07/46] chore: don't typecheck src in interface-ipfs-core --- packages/interface-ipfs-core/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/interface-ipfs-core/tsconfig.json b/packages/interface-ipfs-core/tsconfig.json index 0be1742148..82c9da695f 100644 --- a/packages/interface-ipfs-core/tsconfig.json +++ b/packages/interface-ipfs-core/tsconfig.json @@ -4,7 +4,6 @@ "outDir": "dist" }, "include": [ - "src", "type", "package.json", ] From 02402c7d18b04f8302aeb58cb960f8f87ebe64ed Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 11:46:19 -0800 Subject: [PATCH 08/46] trigger ci From 0da18507f51a58fdd785bfd95764a5f96cbcfc7e Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 12:16:05 -0800 Subject: [PATCH 09/46] chore: change cid dep to use git pull --- packages/interface-ipfs-core/package.json | 2 +- packages/ipfs-cli/package.json | 2 +- packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-core/package.json | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs-http-gateway/package.json | 2 +- packages/ipfs-http-server/package.json | 2 +- packages/ipfs-message-port-protocol/package.json | 2 +- packages/ipfs-message-port-server/package.json | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index ec0df71dc6..7c3e7ad590 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -34,7 +34,7 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "chai-subset": "^1.6.0", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "delay": "^4.4.0", "dirty-chai": "^2.0.1", "err-code": "^2.0.3", diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index 5a07a23034..12c3a8cec5 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -32,7 +32,7 @@ "bignumber.js": "^9.0.0", "byteman": "^1.3.5", "cid-tool": "^1.0.0", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "debug": "^4.1.1", "err-code": "^2.0.3", "execa": "^5.0.0", diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index db583a2ca9..d338d8b20a 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -41,7 +41,7 @@ "any-signal": "^2.0.0", "blob-to-it": "^1.0.1", "browser-readablestream-to-it": "^1.0.1", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "err-code": "^2.0.3", "ipfs-utils": "^5.0.0", "it-all": "^1.0.4", diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index a4269322a5..c012edaebd 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -57,7 +57,7 @@ "array-shuffle": "^1.0.1", "bignumber.js": "^9.0.0", "cbor": "^5.1.0", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "class-is": "^1.1.0", "dag-cbor-links": "^2.0.0", "datastore-core": "^2.0.0", diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index 315abda5e0..dd4ada6634 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -52,7 +52,7 @@ "dependencies": { "any-signal": "^2.0.0", "bignumber.js": "^9.0.0", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "debug": "^4.1.1", "form-data": "^3.0.0", "ipfs-core-utils": "^0.5.3", diff --git a/packages/ipfs-http-gateway/package.json b/packages/ipfs-http-gateway/package.json index d5add58cc9..a52439751a 100644 --- a/packages/ipfs-http-gateway/package.json +++ b/packages/ipfs-http-gateway/package.json @@ -32,7 +32,7 @@ "@hapi/ammo": "^5.0.1", "@hapi/boom": "^9.1.0", "@hapi/hapi": "^20.0.0", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "debug": "^4.1.1", "hapi-pino": "^8.3.0", "ipfs-core-utils": "^0.5.3", diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index 23c1f2a4d5..ba88d14bc9 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -32,7 +32,7 @@ "@hapi/boom": "^9.1.0", "@hapi/content": "^5.0.2", "@hapi/hapi": "^20.0.0", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "debug": "^4.1.1", "dlv": "^1.1.3", "err-code": "^2.0.3", diff --git a/packages/ipfs-message-port-protocol/package.json b/packages/ipfs-message-port-protocol/package.json index 4ca7dafd92..2ee6ec8527 100644 --- a/packages/ipfs-message-port-protocol/package.json +++ b/packages/ipfs-message-port-protocol/package.json @@ -42,7 +42,7 @@ "dep-check": "aegir dep-check -i typescript -i rimraf" }, "dependencies": { - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "ipld-block": "^0.11.0" }, "devDependencies": { diff --git a/packages/ipfs-message-port-server/package.json b/packages/ipfs-message-port-server/package.json index 90cb15a2ee..84dbd33625 100644 --- a/packages/ipfs-message-port-server/package.json +++ b/packages/ipfs-message-port-server/package.json @@ -50,7 +50,7 @@ "devDependencies": { "@types/it-all": "^1.0.0", "aegir": "^29.2.2", - "cids": "^1.0.0", + "cids": "git://github.com/multiformats/js-cid#multicodec-210", "ipfs-utils": "^5.0.0", "rimraf": "^3.0.2", "typescript": "4.0.x" From 58134d5806f33ed1d0f8ef4a86b832c94512b5e5 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 13:02:44 -0800 Subject: [PATCH 10/46] Revert "chore: change cid dep to use git pull" This reverts commit 0da18507f51a58fdd785bfd95764a5f96cbcfc7e. --- packages/interface-ipfs-core/package.json | 2 +- packages/ipfs-cli/package.json | 2 +- packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-core/package.json | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs-http-gateway/package.json | 2 +- packages/ipfs-http-server/package.json | 2 +- packages/ipfs-message-port-protocol/package.json | 2 +- packages/ipfs-message-port-server/package.json | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index 7c3e7ad590..ec0df71dc6 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -34,7 +34,7 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "chai-subset": "^1.6.0", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "delay": "^4.4.0", "dirty-chai": "^2.0.1", "err-code": "^2.0.3", diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index 12c3a8cec5..5a07a23034 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -32,7 +32,7 @@ "bignumber.js": "^9.0.0", "byteman": "^1.3.5", "cid-tool": "^1.0.0", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "debug": "^4.1.1", "err-code": "^2.0.3", "execa": "^5.0.0", diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index d338d8b20a..db583a2ca9 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -41,7 +41,7 @@ "any-signal": "^2.0.0", "blob-to-it": "^1.0.1", "browser-readablestream-to-it": "^1.0.1", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "err-code": "^2.0.3", "ipfs-utils": "^5.0.0", "it-all": "^1.0.4", diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index c012edaebd..a4269322a5 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -57,7 +57,7 @@ "array-shuffle": "^1.0.1", "bignumber.js": "^9.0.0", "cbor": "^5.1.0", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "class-is": "^1.1.0", "dag-cbor-links": "^2.0.0", "datastore-core": "^2.0.0", diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index dd4ada6634..315abda5e0 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -52,7 +52,7 @@ "dependencies": { "any-signal": "^2.0.0", "bignumber.js": "^9.0.0", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "debug": "^4.1.1", "form-data": "^3.0.0", "ipfs-core-utils": "^0.5.3", diff --git a/packages/ipfs-http-gateway/package.json b/packages/ipfs-http-gateway/package.json index a52439751a..d5add58cc9 100644 --- a/packages/ipfs-http-gateway/package.json +++ b/packages/ipfs-http-gateway/package.json @@ -32,7 +32,7 @@ "@hapi/ammo": "^5.0.1", "@hapi/boom": "^9.1.0", "@hapi/hapi": "^20.0.0", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "debug": "^4.1.1", "hapi-pino": "^8.3.0", "ipfs-core-utils": "^0.5.3", diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index ba88d14bc9..23c1f2a4d5 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -32,7 +32,7 @@ "@hapi/boom": "^9.1.0", "@hapi/content": "^5.0.2", "@hapi/hapi": "^20.0.0", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "debug": "^4.1.1", "dlv": "^1.1.3", "err-code": "^2.0.3", diff --git a/packages/ipfs-message-port-protocol/package.json b/packages/ipfs-message-port-protocol/package.json index 2ee6ec8527..4ca7dafd92 100644 --- a/packages/ipfs-message-port-protocol/package.json +++ b/packages/ipfs-message-port-protocol/package.json @@ -42,7 +42,7 @@ "dep-check": "aegir dep-check -i typescript -i rimraf" }, "dependencies": { - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "ipld-block": "^0.11.0" }, "devDependencies": { diff --git a/packages/ipfs-message-port-server/package.json b/packages/ipfs-message-port-server/package.json index 84dbd33625..90cb15a2ee 100644 --- a/packages/ipfs-message-port-server/package.json +++ b/packages/ipfs-message-port-server/package.json @@ -50,7 +50,7 @@ "devDependencies": { "@types/it-all": "^1.0.0", "aegir": "^29.2.2", - "cids": "git://github.com/multiformats/js-cid#multicodec-210", + "cids": "^1.0.0", "ipfs-utils": "^5.0.0", "rimraf": "^3.0.2", "typescript": "4.0.x" From 01a75cd178c6a08d844e9c5f483b7bf30321f666 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 13:14:19 -0800 Subject: [PATCH 11/46] fix: regression introduced by new cid & multicodec --- packages/ipfs-http-client/src/lib/ipld-formats.js | 3 ++- packages/ipfs-http-server/src/api/resources/block.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/ipfs-http-client/src/lib/ipld-formats.js b/packages/ipfs-http-client/src/lib/ipld-formats.js index 1ef4c4e8c6..7348b8505a 100644 --- a/packages/ipfs-http-client/src/lib/ipld-formats.js +++ b/packages/ipfs-http-client/src/lib/ipld-formats.js @@ -36,10 +36,11 @@ module.exports = ({ formats = [], loadFormat = noop } = {}) => { /** * Attempts to load an IPLD format for the passed CID * - * @param {string} codec - The code to load the format for + * @param {import('multicodec').CodecName} codec - The code to load the format for * @returns {Promise} - An IPLD format */ const loadResolver = async (codec) => { + // @ts-ignore - codec is a string and not a CodecName const number = multicodec.getNumber(codec) const format = configuredFormats[number] || await loadFormat(codec) diff --git a/packages/ipfs-http-server/src/api/resources/block.js b/packages/ipfs-http-server/src/api/resources/block.js index 5d8d9c65fa..523066c72f 100644 --- a/packages/ipfs-http-server/src/api/resources/block.js +++ b/packages/ipfs-http-server/src/api/resources/block.js @@ -1,7 +1,7 @@ 'use strict' const multihash = require('multihashing-async').multihash -const codecs = require('multicodec/src/base-table.json') +const { baseTable: codecs } = require('multicodec/src/base-table.js') const multipart = require('../../utils/multipart-request-parser') const Joi = require('../../utils/joi') const Boom = require('@hapi/boom') From 9059fbd5ac079a9833fc205011c70a5239a48248 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 15:09:41 -0800 Subject: [PATCH 12/46] chore: switch to go-ipfs 0.8-rc --- examples/browser-ipns-publish/package.json | 2 +- examples/http-client-browser-pubsub/package.json | 2 +- examples/http-client-name-api/package.json | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/browser-ipns-publish/package.json b/examples/browser-ipns-publish/package.json index a1a930722b..7daa281fa6 100644 --- a/examples/browser-ipns-publish/package.json +++ b/examples/browser-ipns-publish/package.json @@ -28,7 +28,7 @@ "delay": "^4.4.0", "execa": "^4.0.3", "ipfsd-ctl": "^7.0.2", - "go-ipfs": "^0.7.0", + "go-ipfs": "0.8.0-rc1", "parcel-bundler": "^1.12.4", "path": "^0.12.7", "test-ipfs-example": "^2.0.3" diff --git a/examples/http-client-browser-pubsub/package.json b/examples/http-client-browser-pubsub/package.json index a3c27deacf..559df9ee98 100644 --- a/examples/http-client-browser-pubsub/package.json +++ b/examples/http-client-browser-pubsub/package.json @@ -19,7 +19,7 @@ ], "devDependencies": { "execa": "^4.0.3", - "go-ipfs": "^0.7.0", + "go-ipfs": "0.8.0-rc1", "ipfs": "^0.52.0", "ipfsd-ctl": "^7.0.2", "parcel-bundler": "^1.12.4", diff --git a/examples/http-client-name-api/package.json b/examples/http-client-name-api/package.json index d853d473ea..3a8ccd7d2e 100644 --- a/examples/http-client-name-api/package.json +++ b/examples/http-client-name-api/package.json @@ -17,7 +17,7 @@ }, "devDependencies": { "execa": "^4.0.3", - "go-ipfs": "^0.7.0", + "go-ipfs": "0.8.0-rc1", "ipfsd-ctl": "^7.0.2", "parcel-bundler": "^1.12.4", "test-ipfs-example": "^2.0.3" diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index 599229b116..2ea679f619 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -80,7 +80,7 @@ "devDependencies": { "aegir": "^28.0.0", "cross-env": "^7.0.0", - "go-ipfs": "^0.7.0", + "go-ipfs": "0.8.0-rc1", "interface-ipfs-core": "^0.142.0", "ipfs-core": "^0.2.0", "ipfsd-ctl": "^7.0.2", diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 898b49d350..694b979f8c 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -50,7 +50,7 @@ "cross-env": "^7.0.0", "delay": "^4.4.0", "form-data": "^3.0.0", - "go-ipfs": "^0.7.0", + "go-ipfs": "0.8.0-rc1", "interface-ipfs-core": "^0.142.0", "ipfs-http-client": "^48.1.0", "ipfs-interop": "^3.0.0", From a2ddf44393241a36f695a9e5f8b306de117bdcbe Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 15:16:46 -0800 Subject: [PATCH 13/46] fix: remove obsolete match fields --- packages/ipfs-http-client/src/pin/remote/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js index 1aac78b864..9252408e6b 100644 --- a/packages/ipfs-http-client/src/pin/remote/index.js +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -105,11 +105,10 @@ class Remote { * @param {Query & { all?: boolean }} query * @returns {URLSearchParams} */ - static encodeQuery ({ service, cid, name, match, status, all }) { + static encodeQuery ({ service, cid, name, status, all }) { return toUrlSearchParams({ service, name, - match, status, force: all ? true : undefined, cid: cid && cid.map(String) From 0c5d277c40f7996462ffc0dadbc3c32ec3bbe6d1 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 15:17:32 -0800 Subject: [PATCH 14/46] chore: rename type dir to types As per https://github.com/ipfs/js-ipfs/issues/3413#issuecomment-741726719 --- packages/interface-ipfs-core/tsconfig.json | 2 +- .../interface-ipfs-core/{type => types}/basic.ts | 0 .../{type => types}/pin/remote.ts | 0 .../{type => types}/pin/remote/service.ts | 0 packages/ipfs-http-client/src/pin/remote/index.js | 10 +++++----- packages/ipfs-http-client/src/pin/remote/service.js | 12 ++++++------ 6 files changed, 12 insertions(+), 12 deletions(-) rename packages/interface-ipfs-core/{type => types}/basic.ts (100%) rename packages/interface-ipfs-core/{type => types}/pin/remote.ts (100%) rename packages/interface-ipfs-core/{type => types}/pin/remote/service.ts (100%) diff --git a/packages/interface-ipfs-core/tsconfig.json b/packages/interface-ipfs-core/tsconfig.json index 82c9da695f..34b464add5 100644 --- a/packages/interface-ipfs-core/tsconfig.json +++ b/packages/interface-ipfs-core/tsconfig.json @@ -4,7 +4,7 @@ "outDir": "dist" }, "include": [ - "type", + "types", "package.json", ] } diff --git a/packages/interface-ipfs-core/type/basic.ts b/packages/interface-ipfs-core/types/basic.ts similarity index 100% rename from packages/interface-ipfs-core/type/basic.ts rename to packages/interface-ipfs-core/types/basic.ts diff --git a/packages/interface-ipfs-core/type/pin/remote.ts b/packages/interface-ipfs-core/types/pin/remote.ts similarity index 100% rename from packages/interface-ipfs-core/type/pin/remote.ts rename to packages/interface-ipfs-core/types/pin/remote.ts diff --git a/packages/interface-ipfs-core/type/pin/remote/service.ts b/packages/interface-ipfs-core/types/pin/remote/service.ts similarity index 100% rename from packages/interface-ipfs-core/type/pin/remote/service.ts rename to packages/interface-ipfs-core/types/pin/remote/service.ts diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js index 9252408e6b..b428f1a46e 100644 --- a/packages/ipfs-http-client/src/pin/remote/index.js +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -8,11 +8,11 @@ const toUrlSearchParams = require('../../lib/to-url-search-params') /** * @typedef {import('../..').HttpOptions} HttpOptions * @typedef {import('../../lib/core').ClientOptions} ClientOptions - * @typedef {import('interface-ipfs-core/type/basic').AbortOptions} AbortOptions - * @typedef {import('interface-ipfs-core/type/pin/remote').API} API - * @typedef {import('interface-ipfs-core/type/pin/remote').Pin} Pin - * @typedef {import('interface-ipfs-core/type/pin/remote').AddOptions} AddOptions - * @typedef {import('interface-ipfs-core/type/pin/remote').Query} Query + * @typedef {import('interface-ipfs-core/types/basic').AbortOptions} AbortOptions + * @typedef {import('interface-ipfs-core/types/pin/remote').API} API + * @typedef {import('interface-ipfs-core/types/pin/remote').Pin} Pin + * @typedef {import('interface-ipfs-core/types/pin/remote').AddOptions} AddOptions + * @typedef {import('interface-ipfs-core/types/pin/remote').Query} Query * * @implements {API} */ diff --git a/packages/ipfs-http-client/src/pin/remote/service.js b/packages/ipfs-http-client/src/pin/remote/service.js index 07f0c21051..fb5674ffad 100644 --- a/packages/ipfs-http-client/src/pin/remote/service.js +++ b/packages/ipfs-http-client/src/pin/remote/service.js @@ -6,11 +6,11 @@ const toUrlSearchParams = require('../../lib/to-url-search-params') /** * @typedef {import('../../lib/core').ClientOptions} ClientOptions * @typedef {import('../..').HttpOptions} HttpOptions - * @typedef {import('interface-ipfs-core/type/basic').AbortOptions} AbortOptions - * @typedef {import('interface-ipfs-core/type/pin/remote/service').API} API - * @typedef {import('interface-ipfs-core/type/pin/remote/service').Credentials} Credentials - * @typedef {import('interface-ipfs-core/type/pin/remote/service').RemotePinService} RemotePinService - * @typedef {import('interface-ipfs-core/type/pin/remote/service').RemotePinServiceWithStat} RemotePinServiceWithStat + * @typedef {import('interface-ipfs-core/types/basic').AbortOptions} AbortOptions + * @typedef {import('interface-ipfs-core/types/pin/remote/service').API} API + * @typedef {import('interface-ipfs-core/types/pin/remote/service').Credentials} Credentials + * @typedef {import('interface-ipfs-core/types/pin/remote/service').RemotePinService} RemotePinService + * @typedef {import('interface-ipfs-core/types/pin/remote/service').RemotePinServiceWithStat} RemotePinServiceWithStat * @implements {API} */ class Service { @@ -88,7 +88,7 @@ class Service { /** * @param {Object} json - * @returns {import('interface-ipfs-core/type/pin/remote/service').Stat} + * @returns {import('interface-ipfs-core/types/pin/remote/service').Stat} */ static decodeStat (json) { switch (json.Status) { From 5e2fed3afb50e285145077f226d9cfd23b05961b Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 11 Dec 2020 23:35:03 -0800 Subject: [PATCH 15/46] chore: add ipfs.pin.remote.service tests --- packages/interface-ipfs-core/src/index.js | 1 + .../src/pin/remote/index.js | 8 + .../src/pin/remote/service.js | 208 ++++++++++++++++++ packages/interface-ipfs-core/src/pin/utils.js | 6 + packages/ipfs-core/package.json | 2 +- .../src/pin/remote/service.js | 30 ++- packages/ipfs/.aegir.js | 12 +- packages/ipfs/package.json | 3 +- packages/ipfs/test/interface-http-go.js | 2 + .../ipfs/test/utils/mock-pinning-service.js | 44 ++++ 10 files changed, 308 insertions(+), 8 deletions(-) create mode 100644 packages/interface-ipfs-core/src/pin/remote/index.js create mode 100644 packages/interface-ipfs-core/src/pin/remote/service.js create mode 100644 packages/ipfs/test/utils/mock-pinning-service.js diff --git a/packages/interface-ipfs-core/src/index.js b/packages/interface-ipfs-core/src/index.js index 6ce8693ad5..239bcf60c7 100644 --- a/packages/interface-ipfs-core/src/index.js +++ b/packages/interface-ipfs-core/src/index.js @@ -20,6 +20,7 @@ exports.block = require('./block') exports.dag = require('./dag') exports.object = require('./object') exports.pin = require('./pin') +exports.pin.remote = require('./pin/remote') exports.bootstrap = require('./bootstrap') exports.dht = require('./dht') diff --git a/packages/interface-ipfs-core/src/pin/remote/index.js b/packages/interface-ipfs-core/src/pin/remote/index.js new file mode 100644 index 0000000000..4fe15f3694 --- /dev/null +++ b/packages/interface-ipfs-core/src/pin/remote/index.js @@ -0,0 +1,8 @@ +'use strict' +const { createSuite } = require('../../utils/suite') + +const tests = { + service: require('./service') +} + +module.exports = createSuite(tests) diff --git a/packages/interface-ipfs-core/src/pin/remote/service.js b/packages/interface-ipfs-core/src/pin/remote/service.js new file mode 100644 index 0000000000..b88d543de8 --- /dev/null +++ b/packages/interface-ipfs-core/src/pin/remote/service.js @@ -0,0 +1,208 @@ +/* eslint-env mocha */ +'use strict' + +const { clearServices } = require('../utils') +const { getDescribe, getIt, expect } = require('../../utils/mocha') + +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { + const describe = getDescribe(options) + const it = getIt(options) + + const ENDPOINT = new URL(process.env.PINNING_SERVICE_ENDPOINT || '') + const KEY = process.env.PINNING_SERVIEC_KEY + + describe('.pin.remote.service', function () { + this.timeout(50 * 1000) + + let ipfs + before(async () => { + ipfs = (await common.spawn()).api + }) + + after(() => { + common.clean() + }) + afterEach(() => clearServices(ipfs)) + + describe('.pin.remote.service.add', () => { + it('should add a service', async () => { + await ipfs.pin.remote.service.add('pinbot', { + endpoint: ENDPOINT, + key: KEY + }) + + const services = await ipfs.pin.remote.service.ls() + expect(services).to.deep.equal([{ + service: 'pinbot', + endpoint: ENDPOINT + }]) + }) + + it('service add requires endpoint', async () => { + const result = ipfs.pin.remote.service.add('noend', { key: 'token' }) + await expect(result).to.eventually.be.rejectedWith(/is required/) + }) + + it('service add requires key', async () => { + const result = ipfs.pin.remote.service.add('nokey', { + endpoint: ENDPOINT + }) + + await expect(result).to.eventually.be.rejectedWith(/is required/) + }) + + it('add multiple services', async () => { + await ipfs.pin.remote.service.add('pinbot', { + endpoint: ENDPOINT, + key: KEY + }) + + await ipfs.pin.remote.service.add('pinata', { + endpoint: new URL('https://api.pinata.cloud'), + key: 'somekey' + }) + + const services = await ipfs.pin.remote.service.ls() + expect(services.sort(byName)).to.deep.equal([ + { + service: 'pinbot', + endpoint: ENDPOINT + }, + { + service: 'pinata', + endpoint: new URL('https://api.pinata.cloud') + } + ].sort(byName)) + }) + + it('can not add service with existing name', async () => { + await ipfs.pin.remote.service.add('pinbot', { + endpoint: ENDPOINT, + key: KEY + }) + + const result = ipfs.pin.remote.service.add('pinbot', { + endpoint: 'http://pinbot.io/', + key: KEY + }) + + await expect(result).to.eventually.be.rejectedWith(/service already present/) + }) + }) + + describe('.pin.remote.service.ls', () => { + it('should list services', async () => { + const services = await ipfs.pin.remote.service.ls() + expect(services).to.deep.equal([]) + }) + + it('should list added service', async () => { + await ipfs.pin.remote.service.add('pinbot', { + endpoint: ENDPOINT, + key: KEY + }) + + const services = await ipfs.pin.remote.service.ls() + expect(services).to.deep.equal([{ + service: 'pinbot', + endpoint: ENDPOINT + }]) + }) + + it('should include service stats', async () => { + await ipfs.pin.remote.service.add('pinbot', { + endpoint: ENDPOINT, + key: KEY + }) + + const services = await ipfs.pin.remote.service.ls({ stat: true }) + + expect(services).to.deep.equal([{ + service: 'pinbot', + endpoint: ENDPOINT, + stat: { + status: 'valid', + pinCount: { + queued: 0, + pinning: 0, + pinned: 0, + failed: 0 + } + } + }]) + }) + + it('should report unreachable services', async () => { + await ipfs.pin.remote.service.add('pinbot', { + endpoint: ENDPOINT, + key: KEY + }) + await ipfs.pin.remote.service.add('boombot', { + endpoint: 'http://127.0.0.1:5555', + key: 'boom' + }) + + const services = await ipfs.pin.remote.service.ls({ stat: true }) + + expect(services.sort(byName)).to.deep.equal([ + { + service: 'pinbot', + endpoint: ENDPOINT, + stat: { + status: 'valid', + pinCount: { + queued: 0, + pinning: 0, + pinned: 0, + failed: 0 + } + } + }, + { + service: 'boombot', + endpoint: new URL('http://127.0.0.1:5555'), + stat: { + status: 'invalid' + } + } + ].sort(byName)) + }) + }) + + describe('.pin.remote.service.rm', () => { + it('should remove service', async () => { + await ipfs.pin.remote.service.add('pinbot', { + endpoint: ENDPOINT, + key: KEY + }) + + const services = await ipfs.pin.remote.service.ls() + expect(services).to.deep.equal([{ + service: 'pinbot', + endpoint: ENDPOINT + }]) + + await ipfs.pin.remote.service.rm('pinbot') + + expect(await ipfs.pin.remote.service.ls()).to.deep.equal([]) + }) + + it('should not fail if service does not registered', async () => { + expect(await ipfs.pin.remote.service.ls()).to.deep.equal([]) + expect(await ipfs.pin.remote.service.rm('pinbot')).to.equal(undefined) + }) + + it('expects service name', async () => { + const result = ipfs.pin.remote.service.rm() + await expect(result).to.eventually.be.rejectedWith(/is required/) + }) + }) + }) +} + +const byName = (a, b) => a.service > b.service ? 1 : -1 diff --git a/packages/interface-ipfs-core/src/pin/utils.js b/packages/interface-ipfs-core/src/pin/utils.js index 002f2fe26d..34b5144d74 100644 --- a/packages/interface-ipfs-core/src/pin/utils.js +++ b/packages/interface-ipfs-core/src/pin/utils.js @@ -41,6 +41,11 @@ const clearPins = async (ipfs) => { await drain(ipfs.pin.rmAll(map(ipfs.pin.ls({ type: pinTypes.direct }), ({ cid }) => cid))) } +const clearServices = async (ipfs) => { + const services = await ipfs.pin.remote.service.ls() + await Promise.all(services.map(({ service }) => ipfs.pin.remote.service.rm(service))) +} + const expectPinned = async (ipfs, cid, type = pinTypes.all, pinned = true) => { if (typeof type === 'boolean') { pinned = type @@ -69,6 +74,7 @@ async function isPinnedWithType (ipfs, cid, type) { module.exports = { fixtures, clearPins, + clearServices, expectPinned, expectNotPinned, isPinnedWithType, diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index a4269322a5..6803094094 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -119,7 +119,7 @@ "devDependencies": { "aegir": "^29.2.2", "delay": "^4.4.0", - "go-ipfs": "^0.7.0", + "go-ipfs": "0.8.0-rc1", "interface-ipfs-core": "^0.142.2", "ipfsd-ctl": "^7.1.1", "ipld-git": "^0.6.1", diff --git a/packages/ipfs-http-client/src/pin/remote/service.js b/packages/ipfs-http-client/src/pin/remote/service.js index fb5674ffad..91ffa580bb 100644 --- a/packages/ipfs-http-client/src/pin/remote/service.js +++ b/packages/ipfs-http-client/src/pin/remote/service.js @@ -29,23 +29,36 @@ class Service { */ static async add (client, name, options) { const { endpoint, key, headers, timeout, signal } = options - await client.post('pin/remote/servire/rm', { + await client.post('pin/remote/service/add', { timeout, signal, searchParams: toUrlSearchParams({ - arg: [name, endpoint, key] + arg: [name, Service.encodeEndpoint(endpoint), key] }), headers }) } + /** + * @param {URL} url + */ + static encodeEndpoint (url) { + const href = String(url) + if (href === 'undefined') { + throw Error('endpoint is required') + } + // Workaround trailing `/` issue in go-ipfs + // @see https://github.com/ipfs/go-ipfs/issues/7826 + return href[href.length - 1] === '/' ? href.slice(0, -1) : href + } + /** * @param {Client} client * @param {string} name * @param {AbortOptions & HttpOptions} [options] */ static async rm (client, name, { timeout, signal, headers } = {}) { - await client.post('pin/remote/add', { + await client.post('pin/remote/service/rm', { timeout, signal, headers, @@ -67,6 +80,7 @@ class Service { signal, headers }) + /** @type {{RemoteServices: Object[]}} */ const { RemoteServices } = await response.json() @@ -82,7 +96,7 @@ class Service { return { service: json.Service, endpoint: new URL(json.ApiEndpoint), - stat: json.stat && Service.decodeStat(json.stat) + ...(json.Stat && { stat: Service.decodeStat(json.Stat) }) } } @@ -93,9 +107,15 @@ class Service { static decodeStat (json) { switch (json.Status) { case 'valid': { + const { Pinning, Pinned, Queued, Failed } = json.PinCount return { status: 'valid', - pinCount: json.PinCount + pinCount: { + queued: Queued, + pinning: Pinning, + pinned: Pinned, + failed: Failed + } } } case 'invalid': { diff --git a/packages/ipfs/.aegir.js b/packages/ipfs/.aegir.js index 622a7ac601..17443f60d0 100644 --- a/packages/ipfs/.aegir.js +++ b/packages/ipfs/.aegir.js @@ -2,11 +2,13 @@ const { createServer } = require('ipfsd-ctl') const MockPreloadNode = require('./test/utils/mock-preload-node') +const PinningService = require('./test/utils/mock-pinning-service') const EchoServer = require('aegir/utils/echo-server') const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server') const path = require('path') let preloadNode +let pinningService let echoServer = new EchoServer() // the second signalling server is needed for the interface test 'should list peers only once even if they have multiple addresses' @@ -38,23 +40,28 @@ module.exports = { node: { pre: async () => { preloadNode = MockPreloadNode.createNode() + pinningService = await PinningService.start() await preloadNode.start(), await echoServer.start() return { env: { + PINNING_SERVICE_ENDPOINT: pinningService.endpoint, + PINNING_SERVIEC_KEY: pinningService.token, ECHO_SERVER: `http://${echoServer.host}:${echoServer.port}` } } }, post: async () => { - await preloadNode.stop(), + await preloadNode.stop() + await PinningService.stop(pinningService) await echoServer.stop() } }, browser: { pre: async () => { preloadNode = MockPreloadNode.createNode() + pinningService = await PinningService.start() await preloadNode.start() await echoServer.start() @@ -91,6 +98,8 @@ module.exports = { return { env: { + PINNING_SERVICE_ENDPOINT: pinningService.endpoint, + PINNING_SERVIEC_KEY: pinningService.token, ECHO_SERVER: `http://${echoServer.host}:${echoServer.port}` } } @@ -98,6 +107,7 @@ module.exports = { post: async () => { await ipfsdServer.stop() await preloadNode.stop() + await PinningService.stop(pinningService) await echoServer.stop() await sigServerA.stop() await sigServerB.stop() diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index a246038338..64454476f9 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -59,7 +59,8 @@ "merge-options": "^2.0.0", "rimraf": "^3.0.2", "typescript": "4.0.x", - "wrtc": "^0.4.6" + "wrtc": "^0.4.6", + "mock-ipfs-pinning-service": "git://github.com/ipfs-shipyard/js-mock-ipfs-pinning-service" }, "typesVersions": { "*": { diff --git a/packages/ipfs/test/interface-http-go.js b/packages/ipfs/test/interface-http-go.js index 6d56c3800b..25c44b318a 100644 --- a/packages/ipfs/test/interface-http-go.js +++ b/packages/ipfs/test/interface-http-go.js @@ -582,6 +582,8 @@ describe('interface-ipfs-core over ipfs-http-client tests against go-ipfs', () = ] }) + tests.pin.remote(commonFactory) + tests.ping(commonFactory, { skip: [ { diff --git a/packages/ipfs/test/utils/mock-pinning-service.js b/packages/ipfs/test/utils/mock-pinning-service.js new file mode 100644 index 0000000000..a968e0e294 --- /dev/null +++ b/packages/ipfs/test/utils/mock-pinning-service.js @@ -0,0 +1,44 @@ +'use strict' + +const http = require('http') +const { setup } = require('mock-ipfs-pinning-service') + +const defaultPort = 1139 +const defaultToken = 'secret' + +class PinningService { + /** + * @param {Object} options + * @param {number} [options.port] + * @param {string|null} [options.token] + * @returns {Promise} + */ + static async start ({ port = defaultPort, token = defaultToken } = {}) { + const service = await setup({ token }) + const server = http.createServer(service) + await new Promise(resolve => server.listen(port, resolve)) + + return new PinningService({ server, host: '127.0.0.1', port, token }) + } + + /** + * @param {PinningService} service + * @returns {Promise} + */ + static stop (service) { + return new Promise(resolve => service.server.close(resolve)) + } + + constructor ({ server, host, port, token }) { + this.server = server + this.host = host + this.port = port + this.token = token + } + + get endpoint () { + return `http://${this.host}:${this.port}` + } +} + +module.exports = PinningService From 96eb743dfc504924912edf1ecb36b727898ed7b7 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 14 Dec 2020 17:03:50 -0800 Subject: [PATCH 16/46] chore: add ipfs.remote.add tests --- .../interface-ipfs-core/src/pin/remote/add.js | 149 ++++++++++++++++++ .../src/pin/remote/index.js | 3 +- packages/interface-ipfs-core/src/pin/utils.js | 19 +++ .../interface-ipfs-core/types/pin/remote.ts | 2 +- .../ipfs-http-client/src/pin/remote/index.js | 9 ++ 5 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 packages/interface-ipfs-core/src/pin/remote/add.js diff --git a/packages/interface-ipfs-core/src/pin/remote/add.js b/packages/interface-ipfs-core/src/pin/remote/add.js new file mode 100644 index 0000000000..78457490f9 --- /dev/null +++ b/packages/interface-ipfs-core/src/pin/remote/add.js @@ -0,0 +1,149 @@ +/* eslint-env mocha */ +'use strict' + +const { fixtures, clearRemotePins, clearServices } = require('../utils') +const { getDescribe, getIt, expect } = require('../../utils/mocha') +const testTimeout = require('../../utils/test-timeout') +const CID = require('cids') + +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { + const describe = getDescribe(options) + const it = getIt(options) + + const ENDPOINT = new URL(process.env.PINNING_SERVICE_ENDPOINT || '') + const KEY = process.env.PINNING_SERVIEC_KEY + const SERVICE = 'pinbot' + + describe('.pin.remote.add', function () { + this.timeout(50 * 1000) + + let ipfs + before(async () => { + ipfs = (await common.spawn()).api + await ipfs.pin.remote.service.add(SERVICE, { + endpoint: ENDPOINT, + key: KEY + }) + }) + after(async () => { + await clearServices(ipfs) + await common.clean() + }) + + beforeEach(async () => { + await clearRemotePins(ipfs) + }) + + it('should add a CID and return the added CID', async () => { + const pin = await ipfs.pin.remote.add(fixtures.files[0].cid, { + name: 'fixtures-files-0', + background: true, + service: SERVICE + }) + + expect(pin).to.deep.equal({ + status: 'queued', + cid: fixtures.files[0].cid, + name: 'fixtures-files-0' + }) + }) + + it('should fail if service is not provided', async () => { + const result = ipfs.pin.remote.add(fixtures.files[0].cid, { + name: 'fixtures-files-0', + background: true + }) + + await expect(result).to.eventually.be.rejectedWith(/service name must be passed/) + }) + + it('if name is not provided defaults to ""', async () => { + const pin = await ipfs.pin.remote.add(fixtures.files[0].cid, { + background: true, + service: SERVICE + }) + + expect(pin).to.deep.equal({ + cid: fixtures.files[0].cid, + name: '', + status: 'queued' + }) + }) + + it('should default to blocking pin', async () => { + const { cid } = fixtures.files[0] + const result = ipfs.pin.remote.add(cid, { + service: SERVICE + }) + + const timeout = {} + + const winner = await Promise.race([ + result, + new Promise(resolve => setTimeout(resolve, 100, timeout)) + ]) + + expect(winner).to.equal(timeout) + + // trigger status change on the mock service + ipfs.pin.remote.add(cid, { + service: SERVICE, + name: 'pinned-block' + }) + + expect(await result).to.deep.equal({ + cid, + status: 'pinned', + name: '' + }) + }) + it('should pin dag-cbor', async () => { + const cid = await ipfs.dag.put({}, { + format: 'dag-cbor', + hashAlg: 'sha2-256' + }) + + const pin = await ipfs.pin.remote.add(cid, { + service: SERVICE, + name: 'cbor-pin', + background: true + }) + + expect(pin).to.deep.equal({ + cid, + name: 'cbor-pin', + status: 'queued' + }) + }) + + it('should pin raw', async () => { + const cid = await ipfs.dag.put(new Uint8Array(0), { + format: 'raw', + hashAlg: 'sha2-256' + }) + + const pin = await ipfs.pin.remote.add(cid, { + service: SERVICE, + background: true + }) + + expect(pin).to.deep.equal({ + cid, + status: 'queued', + name: '' + }) + }) + + it('should respect timeout option when pinning a block', () => { + return testTimeout(() => ipfs.pin.remote.add(new CID('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ'), { + timeout: 1, + service: SERVICE + })) + }) + }) +} diff --git a/packages/interface-ipfs-core/src/pin/remote/index.js b/packages/interface-ipfs-core/src/pin/remote/index.js index 4fe15f3694..f4a871fb30 100644 --- a/packages/interface-ipfs-core/src/pin/remote/index.js +++ b/packages/interface-ipfs-core/src/pin/remote/index.js @@ -2,7 +2,8 @@ const { createSuite } = require('../../utils/suite') const tests = { - service: require('./service') + service: require('./service'), + add: require('./add') } module.exports = createSuite(tests) diff --git a/packages/interface-ipfs-core/src/pin/utils.js b/packages/interface-ipfs-core/src/pin/utils.js index 34b5144d74..6d8485b354 100644 --- a/packages/interface-ipfs-core/src/pin/utils.js +++ b/packages/interface-ipfs-core/src/pin/utils.js @@ -41,6 +41,24 @@ const clearPins = async (ipfs) => { await drain(ipfs.pin.rmAll(map(ipfs.pin.ls({ type: pinTypes.direct }), ({ cid }) => cid))) } +const clearRemotePins = async (ipfs) => { + for (const { service } of await ipfs.pin.remote.service.ls()) { + const cids = [] + const status = ['queued', 'pinning', 'pinned', 'failed'] + for await (const pin of ipfs.pin.remote.ls({ status, service })) { + cids.push(pin.cid) + } + + if (cids.length > 0) { + await ipfs.pin.remote.rmAll({ + cid: cids, + status, + service + }) + } + } +} + const clearServices = async (ipfs) => { const services = await ipfs.pin.remote.service.ls() await Promise.all(services.map(({ service }) => ipfs.pin.remote.service.rm(service))) @@ -75,6 +93,7 @@ module.exports = { fixtures, clearPins, clearServices, + clearRemotePins, expectPinned, expectNotPinned, isPinnedWithType, diff --git a/packages/interface-ipfs-core/types/pin/remote.ts b/packages/interface-ipfs-core/types/pin/remote.ts index f9815ed33d..c148a42fb3 100644 --- a/packages/interface-ipfs-core/types/pin/remote.ts +++ b/packages/interface-ipfs-core/types/pin/remote.ts @@ -85,7 +85,7 @@ export interface RemoteServiceOptions { export interface Pin { status: Status cid: CID - name?: string + name: string } export type Status = diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js index b428f1a46e..cb53eabee5 100644 --- a/packages/ipfs-http-client/src/pin/remote/index.js +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -45,6 +45,15 @@ class Remote { */ static async add (client, cid, { timeout, signal, headers, ...options }) { const { name, origins, background, service } = options + + if (!CID.isCID(cid)) { + throw new TypeError(`CID instance expected instead of ${cid}`) + } + + if (typeof service !== 'string') { + throw new TypeError('service name must be passed') + } + const response = await client.post('pin/remote/add', { timeout, signal, From 17b47d4abfd76d7f5e3affd833f6c9e379d43b40 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 14 Dec 2020 22:15:23 -0800 Subject: [PATCH 17/46] chore: add tests for ipfs.remote.ls --- .../src/pin/remote/index.js | 3 +- .../interface-ipfs-core/src/pin/remote/ls.js | 434 ++++++++++++++++++ packages/interface-ipfs-core/src/pin/utils.js | 13 + .../ipfs-http-client/src/pin/remote/index.js | 46 +- 4 files changed, 482 insertions(+), 14 deletions(-) create mode 100644 packages/interface-ipfs-core/src/pin/remote/ls.js diff --git a/packages/interface-ipfs-core/src/pin/remote/index.js b/packages/interface-ipfs-core/src/pin/remote/index.js index f4a871fb30..11feed4d6c 100644 --- a/packages/interface-ipfs-core/src/pin/remote/index.js +++ b/packages/interface-ipfs-core/src/pin/remote/index.js @@ -3,7 +3,8 @@ const { createSuite } = require('../../utils/suite') const tests = { service: require('./service'), - add: require('./add') + add: require('./add'), + ls: require('./ls') } module.exports = createSuite(tests) diff --git a/packages/interface-ipfs-core/src/pin/remote/ls.js b/packages/interface-ipfs-core/src/pin/remote/ls.js new file mode 100644 index 0000000000..6b3524b93a --- /dev/null +++ b/packages/interface-ipfs-core/src/pin/remote/ls.js @@ -0,0 +1,434 @@ +/* eslint-env mocha */ +'use strict' + +const { clearRemotePins, addRemotePins, clearServices } = require('../utils') +const { getDescribe, getIt, expect } = require('../../utils/mocha') +const all = require('it-all') +const testTimeout = require('../../utils/test-timeout') +const CID = require('cids') + +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { + const describe = getDescribe(options) + const it = getIt(options) + + const ENDPOINT = new URL(process.env.PINNING_SERVICE_ENDPOINT || '') + const KEY = process.env.PINNING_SERVIEC_KEY + const SERVICE = 'pinbot' + + const cid1 = new CID('QmbKtKBrmeRHjNCwR4zAfCJdMVu6dgmwk9M9AE9pUM9RgG') + const cid2 = new CID('QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w') + const cid3 = new CID('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') + const cid4 = new CID('QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu') + + describe('.pin.remote.ls', function () { + this.timeout(50 * 1000) + + let ipfs + before(async () => { + ipfs = (await common.spawn()).api + await ipfs.pin.remote.service.add(SERVICE, { + endpoint: ENDPOINT, + key: KEY + }) + }) + after(async () => { + await clearServices(ipfs) + await common.clean() + }) + + beforeEach(async () => { + await clearRemotePins(ipfs) + }) + + it('requires service option', async () => { + const result = ipfs.pin.remote.ls({}) + await expect(all(result)).to.eventually.be.rejectedWith(/service name must be passed/) + }) + + it('list no pins', async () => { + const result = ipfs.pin.remote.ls({ service: SERVICE }) + const pins = await all(result) + expect(pins).to.deep.equal([]) + }) + + describe('list pins by status', () => { + it('list only pinned pins by default', async () => { + await addRemotePins(ipfs, SERVICE, { + one: cid1, + 'pinned-two': cid2, + 'pinning-three': cid3, + 'failed-four': cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'pinned', + cid: cid2, + name: 'pinned-two' + } + ]) + }) + + it('should list "queued" pins', async () => { + await addRemotePins(ipfs, SERVICE, { + one: cid1, + 'pinned-two': cid2, + 'pinning-three': cid3, + 'failed-four': cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'queued', + cid: cid1, + name: 'one' + } + ]) + }) + + it('should list "pinning" pins', async () => { + await addRemotePins(ipfs, SERVICE, { + one: cid1, + 'pinned-two': cid2, + 'pinning-three': cid3, + 'failed-four': cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['pinning'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'pinning', + cid: cid3, + name: 'pinning-three' + } + ]) + }) + + it('should list "failed" pins', async () => { + await addRemotePins(ipfs, SERVICE, { + one: cid1, + 'pinned-two': cid2, + 'pinning-three': cid3, + 'failed-four': cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['failed'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'failed', + cid: cid4, + name: 'failed-four' + } + ]) + }) + + it('should list queued+pinned pins', async () => { + await addRemotePins(ipfs, SERVICE, { + one: cid1, + 'pinned-two': cid2, + 'pinning-three': cid3, + 'failed-four': cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinned'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + status: 'queued', + cid: cid1, + name: 'one' + }, + { + status: 'pinned', + cid: cid2, + name: 'pinned-two' + } + ].sort(byCID)) + }) + + it('should list queued+pinned+pinning pins', async () => { + await addRemotePins(ipfs, SERVICE, { + one: cid1, + 'pinned-two': cid2, + 'pinning-three': cid3, + 'failed-four': cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinned', 'pinning'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + status: 'queued', + cid: cid1, + name: 'one' + }, + { + status: 'pinned', + cid: cid2, + name: 'pinned-two' + }, + { + status: 'pinning', + cid: cid3, + name: 'pinning-three' + } + ].sort(byCID)) + }) + + it('should list queued+pinned+pinning+failed pins', async () => { + await addRemotePins(ipfs, SERVICE, { + one: cid1, + 'pinned-two': cid2, + 'pinning-three': cid3, + 'failed-four': cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinned', 'pinning', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + status: 'queued', + cid: cid1, + name: 'one' + }, + { + status: 'pinned', + cid: cid2, + name: 'pinned-two' + }, + { + status: 'pinning', + cid: cid3, + name: 'pinning-three' + }, + { + status: 'failed', + cid: cid4, + name: 'failed-four' + } + ].sort(byCID)) + }) + }) + + describe('list pins by name', () => { + it('should list no pins when names do not match', async () => { + await addRemotePins(ipfs, SERVICE, { + a: cid1, + b: cid2, + c: cid3 + }) + + const list = await all(ipfs.pin.remote.ls({ + name: 'd', + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list).to.deep.equal([]) + }) + it('should list only pins with matchin names', async () => { + await addRemotePins(ipfs, SERVICE, { + a: cid1, + b: cid2 + }) + await addRemotePins(ipfs, SERVICE, { + a: cid3, + b: cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + name: 'a', + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + status: 'queued', + name: 'a', + cid: cid1 + }, + { + status: 'queued', + name: 'a', + cid: cid3 + } + ].sort(byCID)) + }) + + it('should list only pins with matchin names & status', async () => { + await addRemotePins(ipfs, SERVICE, { + a: cid1, + b: cid2 + }) + await addRemotePins(ipfs, SERVICE, { + a: cid3, + b: cid4 + }) + // update status + await addRemotePins(ipfs, SERVICE, { + 'pinned-a': cid3 + }) + + const list = await all(ipfs.pin.remote.ls({ + name: 'a', + status: ['pinned'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'pinned', + name: 'a', + cid: cid3 + } + ]) + }) + }) + + describe('list pins by cid', () => { + it('should pins with matching cid', async () => { + await addRemotePins(ipfs, SERVICE, { + a: cid1, + b: cid2, + c: cid3, + d: cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + cid: [cid1], + status: ['queued', 'pinned', 'pinning', 'failed'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'queued', + cid: cid1, + name: 'a' + } + ]) + }) + + it('should pins with matching cid', async () => { + await addRemotePins(ipfs, SERVICE, { + a: cid1, + b: cid2, + c: cid3, + d: cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + cid: [cid1, cid3], + status: ['queued', 'pinned', 'pinning', 'failed'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'queued', + cid: cid1, + name: 'a' + }, + { + status: 'queued', + cid: cid3, + name: 'c' + } + ]) + }) + + it('should pins with matching cid+status', async () => { + await addRemotePins(ipfs, SERVICE, { + 'pinned-a': cid1, + 'failed-b': cid2, + 'pinned-c': cid3, + d: cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + cid: [cid1, cid2], + status: ['pinned', 'failed'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'pinned', + cid: cid1, + name: 'pinned-a' + }, + { + status: 'failed', + cid: cid2, + name: 'failed-b' + } + ]) + }) + + it('should pins with matching cid+status+name', async () => { + await addRemotePins(ipfs, SERVICE, { + 'pinned-a': cid1, + 'failed-b': cid2, + 'pinned-c': cid3, + d: cid4 + }) + + const list = await all(ipfs.pin.remote.ls({ + cid: [cid4, cid1, cid2], + name: 'd', + status: ['queued', 'pinned'], + service: SERVICE + })) + + expect(list).to.deep.equal([ + { + status: 'queued', + cid: cid4, + name: 'd' + } + ]) + }) + }) + + it('should respect timeout option', () => { + return testTimeout(() => all(ipfs.pin.remote.ls({ + timeout: 1, + service: SERVICE + }))) + }) + }) +} + +const byCID = (a, b) => a.cid.toString() > b.cid.toString() ? 1 : -1 diff --git a/packages/interface-ipfs-core/src/pin/utils.js b/packages/interface-ipfs-core/src/pin/utils.js index 6d8485b354..4ecf661bf6 100644 --- a/packages/interface-ipfs-core/src/pin/utils.js +++ b/packages/interface-ipfs-core/src/pin/utils.js @@ -59,6 +59,18 @@ const clearRemotePins = async (ipfs) => { } } +const addRemotePins = async (ipfs, service, pins) => { + const requests = [] + for (const [name, cid] of Object.entries(pins)) { + requests.push(ipfs.pin.remote.add(cid, { + name, + service, + background: true + })) + } + await Promise.all(requests) +} + const clearServices = async (ipfs) => { const services = await ipfs.pin.remote.service.ls() await Promise.all(services.map(({ service }) => ipfs.pin.remote.service.rm(service))) @@ -94,6 +106,7 @@ module.exports = { clearPins, clearServices, clearRemotePins, + addRemotePins, expectPinned, expectNotPinned, isPinnedWithType, diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js index cb53eabee5..41831b9b3c 100644 --- a/packages/ipfs-http-client/src/pin/remote/index.js +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -13,6 +13,7 @@ const toUrlSearchParams = require('../../lib/to-url-search-params') * @typedef {import('interface-ipfs-core/types/pin/remote').Pin} Pin * @typedef {import('interface-ipfs-core/types/pin/remote').AddOptions} AddOptions * @typedef {import('interface-ipfs-core/types/pin/remote').Query} Query + * @typedef {import('interface-ipfs-core/types/pin/remote').Status} Status * * @implements {API} */ @@ -46,24 +47,16 @@ class Remote { static async add (client, cid, { timeout, signal, headers, ...options }) { const { name, origins, background, service } = options - if (!CID.isCID(cid)) { - throw new TypeError(`CID instance expected instead of ${cid}`) - } - - if (typeof service !== 'string') { - throw new TypeError('service name must be passed') - } - const response = await client.post('pin/remote/add', { timeout, signal, headers, searchParams: toUrlSearchParams({ - arg: cid.toString(), - service, + arg: encodeCID(cid), + service: encodeService(service), name, origins, - background + background: background ? true : undefined }) }) @@ -72,6 +65,9 @@ class Remote { /** * @param {Object} json + * @param {string} json.Name + * @param {string} json.Cid + * @param {Status} json.Status * @returns {Pin} */ static decodePin ({ Name: name, Status: status, Cid: cid }) { @@ -116,11 +112,11 @@ class Remote { */ static encodeQuery ({ service, cid, name, status, all }) { return toUrlSearchParams({ - service, + service: encodeService(service), name, status, force: all ? true : undefined, - cid: cid && cid.map(String) + cid: cid && cid.map(encodeCID) }) } @@ -160,4 +156,28 @@ class Remote { } } +/** + * @param {any} service + * @returns {string} + */ +const encodeService = (service) => { + if (typeof service === 'string' && service !== '') { + return service + } else { + throw new TypeError('service name must be passed') + } +} + +/** + * @param {any} cid + * @returns {string} + */ +const encodeCID = (cid) => { + if (CID.isCID(cid)) { + return cid.toString() + } else { + throw new TypeError(`CID instance expected instead of ${cid}`) + } +} + module.exports = Remote From 446da304a6a49e7843f4c9b3a322b3ca0a2e9e64 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 14 Dec 2020 22:58:02 -0800 Subject: [PATCH 18/46] Revert "chore: fixed cid and multicodec versions (#3445)" This reverts commit eceb0d4fc313f8b8c763f508c0fab25eaa91c10a. --- examples/custom-ipld-formats/package.json | 2 +- packages/interface-ipfs-core/package.json | 2 +- packages/ipfs-cli/package.json | 2 +- packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-core/.aegir.js | 2 +- packages/ipfs-core/package.json | 4 ++-- packages/ipfs-http-client/package.json | 4 ++-- packages/ipfs-http-gateway/package.json | 2 +- packages/ipfs-http-server/package.json | 2 +- packages/ipfs-message-port-protocol/package.json | 2 +- packages/ipfs-message-port-server/package.json | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/custom-ipld-formats/package.json b/examples/custom-ipld-formats/package.json index 44caaf8fbc..1eff93f731 100644 --- a/examples/custom-ipld-formats/package.json +++ b/examples/custom-ipld-formats/package.json @@ -11,7 +11,7 @@ "test-ipfs-example": "^2.0.3" }, "dependencies": { - "cids": "1.0.2", + "cids": "^1.0.0", "ipfs-cli": "^0.1.0", "ipfs-core": "^0.2.1", "ipfs-http-client": "^48.1.1", diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index 22deac5b3c..ec0df71dc6 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -34,7 +34,7 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "chai-subset": "^1.6.0", - "cids": "1.0.2", + "cids": "^1.0.0", "delay": "^4.4.0", "dirty-chai": "^2.0.1", "err-code": "^2.0.3", diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index 2939d078b4..5a07a23034 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -32,7 +32,7 @@ "bignumber.js": "^9.0.0", "byteman": "^1.3.5", "cid-tool": "^1.0.0", - "cids": "1.0.2", + "cids": "^1.0.0", "debug": "^4.1.1", "err-code": "^2.0.3", "execa": "^5.0.0", diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index 57e2aa3361..db583a2ca9 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -41,7 +41,7 @@ "any-signal": "^2.0.0", "blob-to-it": "^1.0.1", "browser-readablestream-to-it": "^1.0.1", - "cids": "1.0.2", + "cids": "^1.0.0", "err-code": "^2.0.3", "ipfs-utils": "^5.0.0", "it-all": "^1.0.4", diff --git a/packages/ipfs-core/.aegir.js b/packages/ipfs-core/.aegir.js index 5b46973aa3..a11af408f4 100644 --- a/packages/ipfs-core/.aegir.js +++ b/packages/ipfs-core/.aegir.js @@ -8,7 +8,7 @@ let preloadNode = MockPreloadNode.createNode() let ipfsdServer module.exports = { - bundlesize: { maxSize: '550kB' }, + bundlesize: { maxSize: '524kB' }, karma: { files: [{ pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*', diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 4266514814..a4269322a5 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -57,7 +57,7 @@ "array-shuffle": "^1.0.1", "bignumber.js": "^9.0.0", "cbor": "^5.1.0", - "cids": "1.0.2", + "cids": "^1.0.0", "class-is": "^1.1.0", "dag-cbor-links": "^2.0.0", "datastore-core": "^2.0.0", @@ -107,7 +107,7 @@ "multiaddr": "^8.0.0", "multiaddr-to-uri": "^6.0.0", "multibase": "^3.0.0", - "multicodec": "2.0.4", + "multicodec": "^2.0.1", "multihashing-async": "^2.0.1", "native-abort-controller": "~0.0.3", "p-queue": "^6.6.1", diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index 7bc9f9a1dc..315abda5e0 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -52,7 +52,7 @@ "dependencies": { "any-signal": "^2.0.0", "bignumber.js": "^9.0.0", - "cids": "1.0.2", + "cids": "^1.0.0", "debug": "^4.1.1", "form-data": "^3.0.0", "ipfs-core-utils": "^0.5.3", @@ -68,7 +68,7 @@ "merge-options": "^2.0.0", "multiaddr": "^8.0.0", "multibase": "^3.0.0", - "multicodec": "2.0.4", + "multicodec": "^2.0.1", "multihashes": "^3.0.1", "nanoid": "^3.1.12", "native-abort-controller": "~0.0.3", diff --git a/packages/ipfs-http-gateway/package.json b/packages/ipfs-http-gateway/package.json index bd12d8d24f..d5add58cc9 100644 --- a/packages/ipfs-http-gateway/package.json +++ b/packages/ipfs-http-gateway/package.json @@ -32,7 +32,7 @@ "@hapi/ammo": "^5.0.1", "@hapi/boom": "^9.1.0", "@hapi/hapi": "^20.0.0", - "cids": "1.0.2", + "cids": "^1.0.0", "debug": "^4.1.1", "hapi-pino": "^8.3.0", "ipfs-core-utils": "^0.5.3", diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index 25d2aae78b..23c1f2a4d5 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -32,7 +32,7 @@ "@hapi/boom": "^9.1.0", "@hapi/content": "^5.0.2", "@hapi/hapi": "^20.0.0", - "cids": "1.0.2", + "cids": "^1.0.0", "debug": "^4.1.1", "dlv": "^1.1.3", "err-code": "^2.0.3", diff --git a/packages/ipfs-message-port-protocol/package.json b/packages/ipfs-message-port-protocol/package.json index e413fc3cf2..4ca7dafd92 100644 --- a/packages/ipfs-message-port-protocol/package.json +++ b/packages/ipfs-message-port-protocol/package.json @@ -42,7 +42,7 @@ "dep-check": "aegir dep-check -i typescript -i rimraf" }, "dependencies": { - "cids": "1.0.2", + "cids": "^1.0.0", "ipld-block": "^0.11.0" }, "devDependencies": { diff --git a/packages/ipfs-message-port-server/package.json b/packages/ipfs-message-port-server/package.json index 80b0628369..90cb15a2ee 100644 --- a/packages/ipfs-message-port-server/package.json +++ b/packages/ipfs-message-port-server/package.json @@ -50,7 +50,7 @@ "devDependencies": { "@types/it-all": "^1.0.0", "aegir": "^29.2.2", - "cids": "1.0.2", + "cids": "^1.0.0", "ipfs-utils": "^5.0.0", "rimraf": "^3.0.2", "typescript": "4.0.x" From 2d3268f539b296660b0e74197b09a12051cdb013 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 15 Dec 2020 00:20:41 -0800 Subject: [PATCH 19/46] chore: fix remaning type missmatches --- packages/ipfs-cli/src/utils.js | 2 +- packages/ipfs-core-utils/src/cid.js | 2 +- packages/ipfs-core/src/components/resolve.js | 2 +- packages/ipfs-http-client/src/dag/put.js | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/ipfs-cli/src/utils.js b/packages/ipfs-cli/src/utils.js index 82f54a477c..0bb6320956 100644 --- a/packages/ipfs-cli/src/utils.js +++ b/packages/ipfs-cli/src/utils.js @@ -252,7 +252,7 @@ const escapeControlCharacters = (str) => { * CID properties * * @param {object} obj - all keys/values in this object will be have control characters stripped - * @param {string} cidBase - any encountered CIDs will be stringified using this base + * @param {import('cids').BaseNameOrCode} cidBase - any encountered CIDs will be stringified using this base * @returns {object} */ const makeEntriesPrintable = (obj, cidBase = 'base58btc') => { diff --git a/packages/ipfs-core-utils/src/cid.js b/packages/ipfs-core-utils/src/cid.js index b0578d375c..e9a3b6baef 100644 --- a/packages/ipfs-core-utils/src/cid.js +++ b/packages/ipfs-core-utils/src/cid.js @@ -12,7 +12,7 @@ const CID = require('cids') * * @param {CID|Uint8Array|string} input - The CID to encode * @param {Object} [options] - Optional options - * @param {string} [options.base] - Name of multibase codec to encode the CID with + * @param {import('cids').BaseNameOrCode} [options.base] - Name of multibase codec to encode the CID with * @param {boolean} [options.upgrade] - Automatically upgrade v0 CIDs to v1 when * necessary. Default: true. * @returns {string} - CID in string representation diff --git a/packages/ipfs-core/src/components/resolve.js b/packages/ipfs-core/src/components/resolve.js index 3336e4d7cf..9c6b0b3ef7 100644 --- a/packages/ipfs-core/src/components/resolve.js +++ b/packages/ipfs-core/src/components/resolve.js @@ -100,7 +100,7 @@ module.exports = ({ ipld, name }) => { * * @typedef {Object} ResolveSettings * @property {boolean} [recursive=true] - Resolve until result is an IPFS name. - * @property {string} [cidBase='base58btc'] - Multibase codec name the CID in the resolved path will be encoded with. + * @property {import('cids').BaseNameOrCode} [cidBase='base58btc'] - Multibase codec name the CID in the resolved path will be encoded with. * * @typedef {import('.').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-http-client/src/dag/put.js b/packages/ipfs-http-client/src/dag/put.js index 1f58b32278..c06e43f625 100644 --- a/packages/ipfs-http-client/src/dag/put.js +++ b/packages/ipfs-http-client/src/dag/put.js @@ -28,6 +28,7 @@ module.exports = configure((api, opts) => { const cid = new CID(options.cid) encodingOptions = { ...options, + // @ts-expect-error - https://github.com/multiformats/js-cid/pull/138 format: multicodec.getName(cid.code), hashAlg: multihash.decode(cid.multihash).name } From a51a6e5dc4397e843c4e7ef5ade0c5878724d393 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 15 Dec 2020 01:38:13 -0800 Subject: [PATCH 20/46] fix: regressions in examples --- examples/custom-ipld-formats/daemon-node.js | 2 +- examples/custom-ipld-formats/in-process-node.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/custom-ipld-formats/daemon-node.js b/examples/custom-ipld-formats/daemon-node.js index 939e6cd410..ef32b9131e 100644 --- a/examples/custom-ipld-formats/daemon-node.js +++ b/examples/custom-ipld-formats/daemon-node.js @@ -5,7 +5,7 @@ const codecName = 'dag-test' const codecNumber = 392091 -const baseTable = require('multicodec/src/base-table.json') +const { baseTable } = require('multicodec/src/base-table') baseTable[codecName] = codecNumber // now require modules as usual diff --git a/examples/custom-ipld-formats/in-process-node.js b/examples/custom-ipld-formats/in-process-node.js index 9fa19214ff..2e64229bcb 100644 --- a/examples/custom-ipld-formats/in-process-node.js +++ b/examples/custom-ipld-formats/in-process-node.js @@ -5,7 +5,7 @@ const codecName = 'dag-test' const codecNumber = 392091 -const baseTable = require('multicodec/src/base-table.json') +const { baseTable } = require('multicodec/src/base-table') baseTable[codecName] = codecNumber // now require modules as usual From 58d5d0c44cba97d02e7b5d982486a9b4db118c47 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 15 Dec 2020 01:40:17 -0800 Subject: [PATCH 21/46] chore: revert bundle size --- packages/ipfs-core/.aegir.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs-core/.aegir.js b/packages/ipfs-core/.aegir.js index a11af408f4..5b46973aa3 100644 --- a/packages/ipfs-core/.aegir.js +++ b/packages/ipfs-core/.aegir.js @@ -8,7 +8,7 @@ let preloadNode = MockPreloadNode.createNode() let ipfsdServer module.exports = { - bundlesize: { maxSize: '524kB' }, + bundlesize: { maxSize: '550kB' }, karma: { files: [{ pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*', From f032cbd98303638feb58d077e696ca6e24c77a3b Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 15 Dec 2020 13:31:37 +0000 Subject: [PATCH 22/46] chore: fix failing test --- examples/custom-ipld-formats/daemon-node.js | 8 ++++++-- examples/custom-ipld-formats/in-process-node.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/custom-ipld-formats/daemon-node.js b/examples/custom-ipld-formats/daemon-node.js index ef32b9131e..3a21a69db5 100644 --- a/examples/custom-ipld-formats/daemon-node.js +++ b/examples/custom-ipld-formats/daemon-node.js @@ -5,8 +5,12 @@ const codecName = 'dag-test' const codecNumber = 392091 -const { baseTable } = require('multicodec/src/base-table') -baseTable[codecName] = codecNumber +const table = require('multicodec/src/base-table') +// @ts-ignore +table.baseTable = { + ...table.baseTable, + [codecName]: codecNumber +} // now require modules as usual const IPFSDaemon = require('ipfs-cli/src/daemon') diff --git a/examples/custom-ipld-formats/in-process-node.js b/examples/custom-ipld-formats/in-process-node.js index 2e64229bcb..3bfcee48e2 100644 --- a/examples/custom-ipld-formats/in-process-node.js +++ b/examples/custom-ipld-formats/in-process-node.js @@ -5,8 +5,12 @@ const codecName = 'dag-test' const codecNumber = 392091 -const { baseTable } = require('multicodec/src/base-table') -baseTable[codecName] = codecNumber +const table = require('multicodec/src/base-table') +// @ts-ignore +table.baseTable = { + ...table.baseTable, + [codecName]: codecNumber +} // now require modules as usual const IPFS = require('ipfs-core') From 8b185ae9d470257c4626ec2a7ef17e42d24eb372 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 15 Dec 2020 13:45:48 +0000 Subject: [PATCH 23/46] chore: update require --- packages/ipfs-http-server/src/api/resources/block.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs-http-server/src/api/resources/block.js b/packages/ipfs-http-server/src/api/resources/block.js index 523066c72f..d3288587d1 100644 --- a/packages/ipfs-http-server/src/api/resources/block.js +++ b/packages/ipfs-http-server/src/api/resources/block.js @@ -1,7 +1,7 @@ 'use strict' const multihash = require('multihashing-async').multihash -const { baseTable: codecs } = require('multicodec/src/base-table.js') +const { baseTable: codecs } = require('multicodec/src/base-table') const multipart = require('../../utils/multipart-request-parser') const Joi = require('../../utils/joi') const Boom = require('@hapi/boom') From f5a37a658fe3bfb1c9be353d1e1b6c7d19418d7e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 15 Dec 2020 14:56:00 +0000 Subject: [PATCH 24/46] chore: update deps --- examples/custom-ipld-formats/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/custom-ipld-formats/package.json b/examples/custom-ipld-formats/package.json index 1eff93f731..5ee26180ff 100644 --- a/examples/custom-ipld-formats/package.json +++ b/examples/custom-ipld-formats/package.json @@ -12,9 +12,9 @@ }, "dependencies": { "cids": "^1.0.0", - "ipfs-cli": "^0.1.0", - "ipfs-core": "^0.2.1", - "ipfs-http-client": "^48.1.1", + "ipfs-cli": "^0.2.2", + "ipfs-core": "^0.3.0", + "ipfs-http-client": "^48.1.2", "multicodec": "^2.0.1", "multihashing-async": "^2.0.1", "uint8arrays": "^1.1.0" From b568e26cc9975f23384a1d2d26b4440e515b04a5 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 15 Dec 2020 16:52:27 +0000 Subject: [PATCH 25/46] chore: use daemon class instead of cli which does not have it any more --- examples/custom-ipld-formats/daemon-node.js | 2 +- examples/custom-ipld-formats/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/custom-ipld-formats/daemon-node.js b/examples/custom-ipld-formats/daemon-node.js index 3a21a69db5..fae244020f 100644 --- a/examples/custom-ipld-formats/daemon-node.js +++ b/examples/custom-ipld-formats/daemon-node.js @@ -13,7 +13,7 @@ table.baseTable = { } // now require modules as usual -const IPFSDaemon = require('ipfs-cli/src/daemon') +const IPFSDaemon = require('ipfs-daemon') const multihashing = require('multihashing-async') const multihash = multihashing.multihash const multicodec = require('multicodec') diff --git a/examples/custom-ipld-formats/package.json b/examples/custom-ipld-formats/package.json index 5ee26180ff..3e4b5f3c01 100644 --- a/examples/custom-ipld-formats/package.json +++ b/examples/custom-ipld-formats/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "cids": "^1.0.0", - "ipfs-cli": "^0.2.2", + "ipfs-daemon": "^0.3.1", "ipfs-core": "^0.3.0", "ipfs-http-client": "^48.1.2", "multicodec": "^2.0.1", From a699b9d5f5518af83a0392c896e5ba0e20dbcb1a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 15 Dec 2020 21:12:13 +0000 Subject: [PATCH 26/46] chore: align versions and remove ts-ignore --- examples/browser-add-readable-stream/package.json | 2 +- examples/browser-browserify/package.json | 2 +- examples/browser-create-react-app/package.json | 2 +- examples/browser-exchange-files/package.json | 4 ++-- examples/browser-http-client-upload-file/package.json | 4 ++-- examples/browser-ipns-publish/package.json | 4 ++-- examples/browser-mfs/package.json | 2 +- examples/browser-parceljs/package.json | 2 +- examples/browser-readablestream/package.json | 2 +- examples/browser-script-tag/package.json | 2 +- examples/browser-service-worker/package.json | 2 +- examples/browser-sharing-node-across-tabs/package.json | 2 +- examples/browser-video-streaming/package.json | 2 +- examples/browser-vue/package.json | 2 +- examples/browser-webpack/package.json | 2 +- examples/circuit-relaying/package.json | 4 ++-- examples/custom-ipfs-repo/package.json | 2 +- examples/custom-libp2p/package.json | 2 +- examples/explore-ethereum-blockchain/package.json | 4 ++-- examples/http-client-browser-pubsub/package.json | 4 ++-- examples/http-client-bundle-webpack/package.json | 4 ++-- examples/http-client-name-api/package.json | 2 +- examples/ipfs-101/package.json | 2 +- examples/run-in-electron/package.json | 2 +- examples/running-multiple-nodes/package.json | 2 +- examples/traverse-ipld-graphs/package.json | 2 +- examples/types-use-ipfs-from-ts/package.json | 2 +- examples/types-use-ipfs-from-ts/src/main.ts | 1 - examples/types-use-ipfs-from-typed-js/package.json | 2 +- examples/types-use-ipfs-from-typed-js/src/main.js | 1 - 30 files changed, 35 insertions(+), 37 deletions(-) diff --git a/examples/browser-add-readable-stream/package.json b/examples/browser-add-readable-stream/package.json index a4a9e16ec7..b7ad55a006 100644 --- a/examples/browser-add-readable-stream/package.json +++ b/examples/browser-add-readable-stream/package.json @@ -12,7 +12,7 @@ "keywords": [], "license": "MIT", "devDependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "test-ipfs-example": "^2.0.3" } } diff --git a/examples/browser-browserify/package.json b/examples/browser-browserify/package.json index 7992059dd0..44891ed73b 100644 --- a/examples/browser-browserify/package.json +++ b/examples/browser-browserify/package.json @@ -18,7 +18,7 @@ "concat-stream": "^2.0.0", "execa": "^4.0.3", "http-server": "^0.12.3", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "rimraf": "^3.0.2", "test-ipfs-example": "^2.0.3" }, diff --git a/examples/browser-create-react-app/package.json b/examples/browser-create-react-app/package.json index 6e58c264e3..e89e9ff04a 100644 --- a/examples/browser-create-react-app/package.json +++ b/examples/browser-create-react-app/package.json @@ -4,7 +4,7 @@ "private": true, "dependencies": { "dot-prop": "^5.0.0", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "ipfs-css": "^0.13.1", "react": "^16.8.6", "react-dom": "^16.8.6", diff --git a/examples/browser-exchange-files/package.json b/examples/browser-exchange-files/package.json index 4a4effe818..0f2458792d 100644 --- a/examples/browser-exchange-files/package.json +++ b/examples/browser-exchange-files/package.json @@ -14,11 +14,11 @@ "browserify": "^16.2.3", "execa": "^4.0.3", "http-server": "^0.12.3", - "ipfs-http-client": "^48.1.1", + "ipfs-http-client": "^48.1.2", "uint8arrays": "^1.1.0" }, "dependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "it-all": "^1.0.4", "rimraf": "^3.0.2", "test-ipfs-example": "^2.0.3" diff --git a/examples/browser-http-client-upload-file/package.json b/examples/browser-http-client-upload-file/package.json index 1fb5fb6596..8b7bfc666b 100644 --- a/examples/browser-http-client-upload-file/package.json +++ b/examples/browser-http-client-upload-file/package.json @@ -15,10 +15,10 @@ ], "license": "MIT", "dependencies": { - "ipfs-http-client": "^48.1.1" + "ipfs-http-client": "^48.1.2" }, "devDependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "parcel-bundler": "^1.12.4", "react": "^16.8.6", "react-dom": "^16.8.6", diff --git a/examples/browser-ipns-publish/package.json b/examples/browser-ipns-publish/package.json index fbdc1f0029..417b7edb8a 100644 --- a/examples/browser-ipns-publish/package.json +++ b/examples/browser-ipns-publish/package.json @@ -13,8 +13,8 @@ "license": "MIT", "dependencies": { "human-crypto-keys": "^0.1.4", - "ipfs": "^0.52.1", - "ipfs-http-client": "^48.1.1", + "ipfs": "^0.52.2", + "ipfs-http-client": "^48.1.2", "ipfs-utils": "^5.0.0", "ipns": "^0.8.0", "it-last": "^1.0.4", diff --git a/examples/browser-mfs/package.json b/examples/browser-mfs/package.json index d8b32d1bd3..77db2343af 100644 --- a/examples/browser-mfs/package.json +++ b/examples/browser-mfs/package.json @@ -22,7 +22,7 @@ "webpack-cli": "^3.3.11" }, "dependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "mime-sniffer": "~0.0.3" } } diff --git a/examples/browser-parceljs/package.json b/examples/browser-parceljs/package.json index 5161e96a86..dabbcd22f5 100644 --- a/examples/browser-parceljs/package.json +++ b/examples/browser-parceljs/package.json @@ -18,7 +18,7 @@ "author": "", "license": "ISC", "dependencies": { - "ipfs": "^0.52.1" + "ipfs": "^0.52.2" }, "devDependencies": { "@babel/cli": "^7.1.5", diff --git a/examples/browser-readablestream/package.json b/examples/browser-readablestream/package.json index a7f383f4d1..9499461604 100644 --- a/examples/browser-readablestream/package.json +++ b/examples/browser-readablestream/package.json @@ -21,7 +21,7 @@ "webpack": "^4.43.0" }, "dependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "it-to-stream": "^0.1.2", "videostream": "^3.2.0" } diff --git a/examples/browser-script-tag/package.json b/examples/browser-script-tag/package.json index 4947cff63b..f55711d7dc 100644 --- a/examples/browser-script-tag/package.json +++ b/examples/browser-script-tag/package.json @@ -16,6 +16,6 @@ "test-ipfs-example": "^2.0.3" }, "dependencies": { - "ipfs": "^0.52.1" + "ipfs": "^0.52.2" } } diff --git a/examples/browser-service-worker/package.json b/examples/browser-service-worker/package.json index 4e13489bca..9c7075b426 100644 --- a/examples/browser-service-worker/package.json +++ b/examples/browser-service-worker/package.json @@ -22,7 +22,7 @@ "webpack-dev-server": "3.11.0" }, "dependencies": { - "ipfs": "^0.51.0", + "ipfs": "^0.52.0", "ipfs-message-port-client": "^0.3.0", "ipfs-message-port-protocol": "^0.3.0", "ipfs-message-port-server": "^0.3.0", diff --git a/examples/browser-sharing-node-across-tabs/package.json b/examples/browser-sharing-node-across-tabs/package.json index 6fefe8a2c9..7b3ccc9ae8 100644 --- a/examples/browser-sharing-node-across-tabs/package.json +++ b/examples/browser-sharing-node-across-tabs/package.json @@ -24,7 +24,7 @@ "worker-plugin": "4.0.3" }, "dependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "ipfs-message-port-client": "^0.4.1", "ipfs-message-port-server": "^0.4.1" }, diff --git a/examples/browser-video-streaming/package.json b/examples/browser-video-streaming/package.json index 2444a67cba..3eab9b4f46 100644 --- a/examples/browser-video-streaming/package.json +++ b/examples/browser-video-streaming/package.json @@ -16,6 +16,6 @@ "test-ipfs-example": "^2.0.3" }, "dependencies": { - "ipfs": "^0.52.1" + "ipfs": "^0.52.2" } } diff --git a/examples/browser-vue/package.json b/examples/browser-vue/package.json index bd1d36a34b..b23680976a 100644 --- a/examples/browser-vue/package.json +++ b/examples/browser-vue/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "core-js": "^3.6.4", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "vue": "^2.6.11" }, "devDependencies": { diff --git a/examples/browser-webpack/package.json b/examples/browser-webpack/package.json index 3615ac770e..a879e62c8d 100644 --- a/examples/browser-webpack/package.json +++ b/examples/browser-webpack/package.json @@ -27,7 +27,7 @@ "webpack-dev-server": "^3.11.0" }, "dependencies": { - "ipfs": "^0.52.1" + "ipfs": "^0.52.2" }, "browserslist": [ ">1%", diff --git a/examples/circuit-relaying/package.json b/examples/circuit-relaying/package.json index 2ae2071b99..3a7a55bc05 100644 --- a/examples/circuit-relaying/package.json +++ b/examples/circuit-relaying/package.json @@ -15,14 +15,14 @@ "license": "MIT", "dependencies": { "delay": "^4.4.0", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "ipfs-pubsub-room": "^2.0.1", "uint8arrays": "^1.1.0" }, "devDependencies": { "execa": "^4.0.3", "ipfs-css": "^0.13.1", - "ipfs-http-client": "^48.1.1", + "ipfs-http-client": "^48.1.2", "parcel-bundler": "^1.12.4", "rimraf": "^3.0.2", "tachyons": "^4.11.1", diff --git a/examples/custom-ipfs-repo/package.json b/examples/custom-ipfs-repo/package.json index 8cfc596ef9..da2f9c0dc8 100644 --- a/examples/custom-ipfs-repo/package.json +++ b/examples/custom-ipfs-repo/package.json @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "datastore-fs": "^2.0.0", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "ipfs-repo": "^7.0.0", "it-all": "^1.0.4" }, diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index 8b18ac2411..0988f32889 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -10,7 +10,7 @@ }, "license": "MIT", "dependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "libp2p": "^0.29.3", "libp2p-bootstrap": "^0.12.1", "libp2p-kad-dht": "^0.20.1", diff --git a/examples/explore-ethereum-blockchain/package.json b/examples/explore-ethereum-blockchain/package.json index 097783c2f0..0d4ec63e96 100644 --- a/examples/explore-ethereum-blockchain/package.json +++ b/examples/explore-ethereum-blockchain/package.json @@ -10,8 +10,8 @@ "keywords": [], "license": "MIT", "devDependencies": { - "ipfs": "^0.52.1", - "ipfs-http-client": "^48.1.1", + "ipfs": "^0.52.2", + "ipfs-http-client": "^48.1.2", "ipfsd-ctl": "^7.1.1", "ipld-ethereum": "^5.0.1", "test-ipfs-example": "^2.0.3" diff --git a/examples/http-client-browser-pubsub/package.json b/examples/http-client-browser-pubsub/package.json index 36b9c8b1fd..a2620020c3 100644 --- a/examples/http-client-browser-pubsub/package.json +++ b/examples/http-client-browser-pubsub/package.json @@ -12,7 +12,7 @@ "author": "Alan Shaw", "license": "MIT", "dependencies": { - "ipfs-http-client": "^48.1.1" + "ipfs-http-client": "^48.1.2" }, "browserslist": [ "last 2 versions and not dead and > 2%" @@ -20,7 +20,7 @@ "devDependencies": { "execa": "^4.0.3", "go-ipfs": "^0.7.0", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "ipfsd-ctl": "^7.1.1", "parcel-bundler": "^1.12.4", "test-ipfs-example": "^2.0.3" diff --git a/examples/http-client-bundle-webpack/package.json b/examples/http-client-bundle-webpack/package.json index 6d9b00b922..92fd387d19 100644 --- a/examples/http-client-bundle-webpack/package.json +++ b/examples/http-client-bundle-webpack/package.json @@ -13,7 +13,7 @@ "license": "MIT", "keywords": [], "dependencies": { - "ipfs-http-client": "^48.1.1", + "ipfs-http-client": "^48.1.2", "react": "^16.8.6", "react-dom": "^16.8.6" }, @@ -24,7 +24,7 @@ "babel-loader": "^8.0.5", "copy-webpack-plugin": "^5.0.4", "execa": "^4.0.3", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "ipfsd-ctl": "^7.1.1", "react-hot-loader": "^4.12.21", "rimraf": "^3.0.2", diff --git a/examples/http-client-name-api/package.json b/examples/http-client-name-api/package.json index 90e0c1ab0c..f7e7bf9df2 100644 --- a/examples/http-client-name-api/package.json +++ b/examples/http-client-name-api/package.json @@ -13,7 +13,7 @@ "author": "Tara Vancil ", "license": "MIT", "dependencies": { - "ipfs-http-client": "^48.1.1" + "ipfs-http-client": "^48.1.2" }, "devDependencies": { "execa": "^4.0.3", diff --git a/examples/ipfs-101/package.json b/examples/ipfs-101/package.json index 3367d34bc9..6e0685d1a6 100644 --- a/examples/ipfs-101/package.json +++ b/examples/ipfs-101/package.json @@ -10,7 +10,7 @@ "author": "David Dias ", "license": "MIT", "dependencies": { - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "it-all": "^1.0.4", "uint8arrays": "^1.1.0" }, diff --git a/examples/run-in-electron/package.json b/examples/run-in-electron/package.json index 07121a55d2..25599fc1a4 100644 --- a/examples/run-in-electron/package.json +++ b/examples/run-in-electron/package.json @@ -18,7 +18,7 @@ "devDependencies": { "electron": "^6.0.0", "electron-rebuild": "^1.8.4", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "test-ipfs-example": "^2.0.3" }, "greenkeeper": { diff --git a/examples/running-multiple-nodes/package.json b/examples/running-multiple-nodes/package.json index 17b5806d42..930970cd19 100644 --- a/examples/running-multiple-nodes/package.json +++ b/examples/running-multiple-nodes/package.json @@ -13,6 +13,6 @@ "test-ipfs-example": "^2.0.3" }, "dependencies": { - "ipfs": "^0.52.1" + "ipfs": "^0.52.2" } } diff --git a/examples/traverse-ipld-graphs/package.json b/examples/traverse-ipld-graphs/package.json index 18a028d849..27747ba097 100644 --- a/examples/traverse-ipld-graphs/package.json +++ b/examples/traverse-ipld-graphs/package.json @@ -14,7 +14,7 @@ }, "dependencies": { "cids": "^1.0.0", - "ipfs": "^0.52.1", + "ipfs": "^0.52.2", "ipld-block": "^0.11.0", "ipld-dag-pb": "^0.20.0", "ipld-git": "^0.6.1", diff --git a/examples/types-use-ipfs-from-ts/package.json b/examples/types-use-ipfs-from-ts/package.json index f36edbd714..621c28d90c 100644 --- a/examples/types-use-ipfs-from-ts/package.json +++ b/examples/types-use-ipfs-from-ts/package.json @@ -2,7 +2,7 @@ "name": "example-types-use-ipfs-from-ts", "private": true, "dependencies": { - "ipfs": "^0.52.1" + "ipfs": "^0.52.2" }, "devDependencies": { "typescript": "4.0.x" diff --git a/examples/types-use-ipfs-from-ts/src/main.ts b/examples/types-use-ipfs-from-ts/src/main.ts index a6763cade9..29e1741602 100644 --- a/examples/types-use-ipfs-from-ts/src/main.ts +++ b/examples/types-use-ipfs-from-ts/src/main.ts @@ -14,7 +14,6 @@ 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) { diff --git a/examples/types-use-ipfs-from-typed-js/package.json b/examples/types-use-ipfs-from-typed-js/package.json index c5912b4e55..c49141ca16 100644 --- a/examples/types-use-ipfs-from-typed-js/package.json +++ b/examples/types-use-ipfs-from-typed-js/package.json @@ -2,7 +2,7 @@ "name": "example-types-use-ipfs-from-typed-js", "private": true, "dependencies": { - "ipfs": "^0.52.1" + "ipfs": "^0.52.2" }, "devDependencies": { "typescript": "4.0.x" diff --git a/examples/types-use-ipfs-from-typed-js/src/main.js b/examples/types-use-ipfs-from-typed-js/src/main.js index 0ff2166786..5e24546705 100644 --- a/examples/types-use-ipfs-from-typed-js/src/main.js +++ b/examples/types-use-ipfs-from-typed-js/src/main.js @@ -17,7 +17,6 @@ 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) { From c2ec9206f161a67dc0cc07936af38ed01c541dbe Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 15 Dec 2020 23:27:24 -0800 Subject: [PATCH 27/46] chore: factor out types into ipfs-interface --- packages/ipfs-core-utils/package.json | 1 + .../ipfs-core-utils/src/files/format-mode.js | 6 +- .../ipfs-core-utils/src/files/format-mtime.js | 10 +- .../files/normalise-input/index.browser.js | 4 +- .../src/files/normalise-input/index.js | 4 +- .../files/normalise-input/normalise-input.js | 50 +---- .../src/files/normalise-input/utils.js | 2 +- packages/ipfs-core/package.json | 1 + .../ipfs-core/src/components/add-all/index.js | 51 +---- packages/ipfs-core/src/components/add.js | 48 ++-- packages/ipfs-core/src/components/cat.js | 21 +- .../ipfs-core/src/components/files/mkdir.js | 14 +- .../ipfs-core/src/components/files/stat.js | 6 +- .../ipfs-core/src/components/files/touch.js | 12 +- .../ipfs-core/src/components/files/write.js | 6 +- packages/ipfs-core/src/components/get.js | 19 +- packages/ipfs-core/src/components/ls.js | 27 +-- packages/ipfs-core/src/components/root.js | 29 +-- packages/ipfs-core/src/utils.js | 92 +------- packages/ipfs-http-client/package.json | 1 + packages/ipfs-http-client/src/add-all.js | 6 +- packages/ipfs-interface/COPYRIGHT | 5 + packages/ipfs-interface/LICENSE-APACHE | 5 + packages/ipfs-interface/LICENSE-MIT | 19 ++ packages/ipfs-interface/README.md | 82 +++++++ packages/ipfs-interface/package.json | 44 ++++ packages/ipfs-interface/src/basic.ts | 31 +++ packages/ipfs-interface/src/files.ts | 211 ++++++++++++++++++ packages/ipfs-interface/src/index.ts | 10 + packages/ipfs-interface/src/preload.ts | 3 + packages/ipfs-interface/src/root.ts | 143 ++++++++++++ packages/ipfs-interface/tsconfig.json | 9 + .../ipfs-message-port-client/package.json | 3 +- packages/ipfs-message-port-client/src/core.js | 2 +- tsconfig.json | 2 +- 35 files changed, 645 insertions(+), 334 deletions(-) create mode 100644 packages/ipfs-interface/COPYRIGHT create mode 100644 packages/ipfs-interface/LICENSE-APACHE create mode 100644 packages/ipfs-interface/LICENSE-MIT create mode 100644 packages/ipfs-interface/README.md create mode 100644 packages/ipfs-interface/package.json create mode 100644 packages/ipfs-interface/src/basic.ts create mode 100644 packages/ipfs-interface/src/files.ts create mode 100644 packages/ipfs-interface/src/index.ts create mode 100644 packages/ipfs-interface/src/preload.ts create mode 100644 packages/ipfs-interface/src/root.ts create mode 100644 packages/ipfs-interface/tsconfig.json diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index db583a2ca9..24009e3a9a 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -44,6 +44,7 @@ "cids": "^1.0.0", "err-code": "^2.0.3", "ipfs-utils": "^5.0.0", + "ipfs-interface": "^0.1.0", "it-all": "^1.0.4", "it-map": "^1.0.4", "it-peekable": "^1.0.1", diff --git a/packages/ipfs-core-utils/src/files/format-mode.js b/packages/ipfs-core-utils/src/files/format-mode.js index 452aa182b5..79f739e68a 100644 --- a/packages/ipfs-core-utils/src/files/format-mode.js +++ b/packages/ipfs-core-utils/src/files/format-mode.js @@ -26,7 +26,7 @@ function checkPermission (mode, perm, type, output) { /** * - * @param {Mode} mode + * @param {import('ipfs-interface/src/files').Mode} mode * @param {boolean} isDirectory * @returns {string} */ @@ -70,7 +70,3 @@ function formatMode (mode, isDirectory) { } module.exports = formatMode - -/** - * @typedef {number} Mode - */ diff --git a/packages/ipfs-core-utils/src/files/format-mtime.js b/packages/ipfs-core-utils/src/files/format-mtime.js index 13f6e9e2d3..64048792fa 100644 --- a/packages/ipfs-core-utils/src/files/format-mtime.js +++ b/packages/ipfs-core-utils/src/files/format-mtime.js @@ -1,7 +1,7 @@ 'use strict' /** - * @param {MTime} mtime + * @param {import('ipfs-interface/src/files').MTime} mtime * @returns {string} */ function formatMtime (mtime) { @@ -22,12 +22,4 @@ function formatMtime (mtime) { }) } -/** - * @typedef {object} MTime - * @property {number} secs - the number of seconds since (positive) or before - * (negative) the Unix Epoch began - * @property {number} nsecs - the number of nanoseconds since the last full - * second. - */ - module.exports = formatMtime diff --git a/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js b/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js index 98e4145dce..02dd7f3270 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js @@ -12,7 +12,7 @@ const normaliseInput = require('./normalise-input') * * See https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsadddata-options * - * @param {import('./normalise-input').Source} input - * @returns {AsyncIterable>} + * @param {import('ipfs-interface/src/files').ImportSource} input + * @returns {AsyncIterable>} */ module.exports = (input) => normaliseInput(input, normaliseContent) diff --git a/packages/ipfs-core-utils/src/files/normalise-input/index.js b/packages/ipfs-core-utils/src/files/normalise-input/index.js index d6b987807c..3c70f7394e 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/index.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/index.js @@ -12,7 +12,7 @@ const normaliseInput = require('./normalise-input') * * See https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsadddata-options * - * @param {import('./normalise-input').Source} input - * @returns {AsyncIterable>>} + * @param {import('ipfs-interface/src/files').ImportSource} input + * @returns {AsyncIterable>>} */ module.exports = (input) => normaliseInput(input, normaliseContent) diff --git a/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js b/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js index 4a6e8c6d82..cf006e76dd 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js @@ -15,11 +15,14 @@ const { // eslint-disable-next-line complexity +/** + * @typedef {import('ipfs-interface/src/files').ToContent} ToContent + */ /** * @template {Blob|AsyncIterable} Content - * @param {Source} input + * @param {import('ipfs-interface/src/files').ImportSource} input * @param {(content:ToContent) => Content|Promise} normaliseContent - * @returns {AsyncIterable>} + * @returns {AsyncIterable>} */ // eslint-disable-next-line complexity module.exports = async function * normaliseInput (input, normaliseContent) { @@ -100,9 +103,9 @@ module.exports = async function * normaliseInput (input, normaliseContent) { /** * @template {Blob|AsyncIterable} Content - * @param {ToFile} input + * @param {import('ipfs-interface/src/files').ToEntry} input * @param {(content:ToContent) => Content|Promise} normaliseContent - * @returns {Promise>} + * @returns {Promise>} */ async function toFileObject (input, normaliseContent) { // @ts-ignore - Those properties don't exist on most input types @@ -119,42 +122,3 @@ async function toFileObject (input, normaliseContent) { return file } - -/** - * @typedef {import('../format-mtime').MTime} MTime - * @typedef {import('../format-mode').Mode} Mode - * @typedef {Object} Directory - * @property {string} path - * @property {Mode} [mode] - * @property {MTime} [mtime] - * @property {undefined} [content] - * - * @typedef {Object} FileInput - * @property {string} [path] - * @property {ToContent} [content] - * @property {number | string} [mode] - * @property {UnixTime} [mtime] - * - * @typedef {Date | MTime | HRTime} UnixTime - * - * Time representation as tuple of two integers, as per the output of - * [`process.hrtime()`](https://nodejs.org/dist/latest/docs/api/process.html#process_process_hrtime_time). - * @typedef {[number, number]} HRTime - * - * @typedef {string|InstanceType|ArrayBufferView|ArrayBuffer|Blob|Iterable | AsyncIterable | ReadableStream} ToContent - * @typedef {ToContent|FileInput} ToFile - * @typedef {Iterable | AsyncIterable | ReadableStream} Source - */ -/** - * @template {AsyncIterable|Blob} Content - * @typedef {Object} File - * @property {string} path - * @property {Mode} [mode] - * @property {MTime} [mtime] - * @property {Content} [content] - */ - -/** - * @template {AsyncIterable|Blob} Content - * @typedef {File|Directory} Entry - */ diff --git a/packages/ipfs-core-utils/src/files/normalise-input/utils.js b/packages/ipfs-core-utils/src/files/normalise-input/utils.js index dabc6e5a6f..06f26096f9 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/utils.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/utils.js @@ -22,7 +22,7 @@ function isBlob (obj) { * An object with a path or content property * * @param {any} obj - * @returns {obj is import('./normalise-input').FileInput} + * @returns {obj is import('ipfs-interface/src/files').ToEntry} */ function isFileObject (obj) { return typeof obj === 'object' && (obj.path || obj.content) diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index a4269322a5..054f459610 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -71,6 +71,7 @@ "ipfs-bitswap": "^4.0.0", "ipfs-block-service": "^0.18.0", "ipfs-core-utils": "^0.5.3", + "ipfs-interface": "^0.1.0", "ipfs-repo": "^7.0.0", "ipfs-unixfs": "^2.0.3", "ipfs-unixfs-exporter": "^3.0.4", diff --git a/packages/ipfs-core/src/components/add-all/index.js b/packages/ipfs-core/src/components/add-all/index.js index eb5077c824..5c163f944d 100644 --- a/packages/ipfs-core/src/components/add-all/index.js +++ b/packages/ipfs-core/src/components/add-all/index.js @@ -13,17 +13,12 @@ const mergeOptions = require('merge-options').bind({ ignoreUndefined: true }) * @param {import('..').GCLock} config.gcLock * @param {import('..').Preload} config.preload * @param {import('..').Pin} config.pin - * @param {ShardingOptions} [config.options] + * @param {import('ipfs-interface/src/root').ShardingOptions} [config.options] */ module.exports = ({ block, gcLock, preload, pin, options }) => { const isShardingEnabled = options && options.sharding - /** - * Import multiple files and data into IPFS. - * - * @param {FileStream} source - * @param {AddAllOptions & AbortOptions} [options] - * @returns {AsyncIterable} - */ + + /** @type {import('ipfs-interface/src/root').AddAll} */ async function * addAll (source, options = {}) { const opts = mergeOptions({ shardSplitThreshold: isShardingEnabled ? 1000 : Infinity, @@ -169,43 +164,3 @@ function pinFile (pin, opts) { } } } - -/** - * @typedef {object} UnixFSEntry - * @property {string} path - * @property {CID} cid - * @property {number} [mode] - * @property {MTime} [mtime] - * @property {number} size - * - * @typedef {Object} AddAllOptions - * @property {string} [chunker='size-262144'] - Chunking algorithm used to build - * ipfs DAGs. - * @property {0|1} [cidVersion=0] - The CID version to use when storing the data. - * @property {boolean} [enableShardingExperiment=false] - Allows to create - * directories with an unlimited number of entries currently size of unixfs - * directories is limited by the maximum block size. **Note** that this is an - * experimental feature. - * @property {string} [hashAlg='sha2-256'] - Multihash hashing algorithm to use. - * @property {boolean} [onlyHash=false] - If true, will not add blocks to the - * blockstore. - * @property {boolean} [pin=true] - Pin this object when adding. - * @property {(bytes:number, path:string) => void} [progress] - a function that will be called with the number of bytes added as a file is added to ipfs and the path of the file being added - * @property {boolean} [rawLeaves=false] - If true, DAG leaves will contain raw - * file data and not be wrapped in a protobuf. - * @property {number} [shardSplitThreshold=1000] - Directories with more than this - * number of files will be created as HAMT-sharded directories. - * @property {boolean} [trickle=false] - If true will use the - * [trickle DAG](https://godoc.org/github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-unixfs/importer/trickle) - * format for DAG generation. - * @property {boolean} [wrapWithDirectory=false] - Adds a wrapping node around - * the content. - * - * @typedef {import('ipfs-core-utils/src/files/normalise-input/normalise-input').Source} FileStream - * @typedef {import('../../utils').MTime} MTime - * @typedef {import('../../utils').AbortOptions} AbortOptions - * @typedef {import('..').CID} CID - * - * @typedef {Object} ShardingOptions - * @property {boolean} [sharding] - */ diff --git a/packages/ipfs-core/src/components/add.js b/packages/ipfs-core/src/components/add.js index 7334071e7c..b71ea1d596 100644 --- a/packages/ipfs-core/src/components/add.js +++ b/packages/ipfs-core/src/components/add.js @@ -2,39 +2,25 @@ const last = require('it-last') +/** + * @param {Object} config + * @param {import('ipfs-interface/src/root').AddAll} config.addAll + */ module.exports = ({ addAll }) => { - /** - * Import a file or data into IPFS. - * - * @param {Source} source - * @param {AddOptions & AbortOptions} [options] - * @returns {AddResult} - */ - async function add (source, options) { // eslint-disable-line require-await - /** @type {UnixFSEntry} - Could be undefined if empty */ - const result = (await last(addAll(source, options))) + /** @type {import('ipfs-interface/src/root').Add} */ + async function add (entry, options) { + /** @type {import('ipfs-interface/src/files').ImportSource} */ + 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 + // throw an error in case it does happen. + if (result == null) { + throw Error('Failed to add a file, if you see this please report a bug') + } + return result } + return add } - -/** - * @typedef {object} AddOptions - * @property {string} [chunker] - chunking algorithm used to build ipfs DAGs (default: `'size-262144'`) - * @property {number} [cidVersion] - the CID version to use when storing the data (default: `0`) - * @property {string} [hashAlg] - multihash hashing algorithm to use (default: `'sha2-256'`) - * @property {boolean} [onlyHash] - If true, will not add blocks to the blockstore (default: `false`) - * @property {boolean} [pin] - pin this object when adding (default: `true`) - * @property {(bytes:number, path:string) => void} [progress] - a function that will be called with the number of bytes added as a file is added to ipfs and the path of the file being added - * @property {boolean} [rawLeaves] - if true, DAG leaves will contain raw file data and not be wrapped in a protobuf (default: `false`) - * @property {boolean} [trickle] - if true will use the [trickle DAG](https://godoc.org/github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-unixfs/importer/trickle) format for DAG generation (default: `false`) - * @property {boolean} [wrapWithDirectory] - Adds a wrapping node around the content (default: `false`) - * - * @typedef {Promise} AddResult - * - * @typedef {import('ipfs-core-utils/src/files/normalise-input/normalise-input').FileInput} Source - * - * @typedef {import('./add-all').UnixFSEntry} UnixFSEntry - * - * @typedef {import('../utils').AbortOptions} AbortOptions - */ diff --git a/packages/ipfs-core/src/components/cat.js b/packages/ipfs-core/src/components/cat.js index 6c47032286..c76029b5ce 100644 --- a/packages/ipfs-core/src/components/cat.js +++ b/packages/ipfs-core/src/components/cat.js @@ -10,13 +10,7 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option') * @param {import('.').Preload} config.preload */ module.exports = function ({ ipld, preload }) { - /** - * Returns content of the file addressed by a valid IPFS Path or CID. - * - * @param {CID|string} ipfsPath - An IPFS path or CID to export - * @param {Options} [options] - * @returns {AsyncIterable} - */ + /** @type {import('ipfs-interface/src/root').Cat} */ async function * cat (ipfsPath, options = {}) { ipfsPath = normalizeCidPath(ipfsPath) @@ -41,16 +35,3 @@ module.exports = function ({ ipld, preload }) { return withTimeoutOption(cat) } - -/** - * @typedef {CatOptions & AbortOptions} Options - * - * @typedef {Object} CatOptions - * @property {number} [offset] - An offset to start reading the file from - * @property {number} [length] - An optional max length to read from the file - * @property {boolean} [preload] - * - * @typedef {import('../utils').AbortOptions} AbortOptions - * - * @typedef {import('.').CID} CID - */ diff --git a/packages/ipfs-core/src/components/files/mkdir.js b/packages/ipfs-core/src/components/files/mkdir.js index 22f0b8cfc1..b44ed06a14 100644 --- a/packages/ipfs-core/src/components/files/mkdir.js +++ b/packages/ipfs-core/src/components/files/mkdir.js @@ -143,14 +143,16 @@ const addEmptyDir = async (context, childName, emptyDir, parent, trail, options) /** * @typedef {Object} MkdirOptions * @property {boolean} [parents=false] - If true, create intermediate directories - * @property {number} [mode] - An integer that represents the file mode - * @property {Mtime|Hrtime|Date} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime() + * @property {ToMode} [mode] - An integer that represents the file mode + * @property {ToMTime} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime() * @property {boolean} [flush] - If true the changes will be immediately flushed to disk * @property {string} [hashAlg='sha2-256'] - The hash algorithm to use for any updated entries - * @property {0|1} [cidVersion=0] - The CID version to use for any updated entries + * @property {CIDVersion} [cidVersion=0] - The CID version to use for any updated entries * * @typedef {import('cids')} CID - * @typedef {import('../../utils').AbortOptions} AbortOptions - * @typedef {import('../../utils').Mtime} Mtime - * @typedef {import('../../utils').Hrtime} Hrtime + * @typedef {import('cids').CIDVersion} CIDVersion + * @typedef {import('ipfs-interface/src/basic').AbortOptions} AbortOptions + * @typedef {import('ipfs-interface/src/files').MTime} Mtime + * @typedef {import('ipfs-interface/src/files').ToMTime} ToMTime + * @typedef {import('ipfs-interface/src/files').ToMode} ToMode */ diff --git a/packages/ipfs-core/src/components/files/stat.js b/packages/ipfs-core/src/components/files/stat.js index 4b83a664ff..c35c6eb761 100644 --- a/packages/ipfs-core/src/components/files/stat.js +++ b/packages/ipfs-core/src/components/files/stat.js @@ -180,8 +180,8 @@ const statters = { * @property {number} [sizeLocal] - An integer indicating the cumulative size of * the data present locally. * @property {number} [mode] - File mode - * @property {import('../add-all').MTime} [mtime] - Modification time + * @property {import('ipfs-interface/src/files').MTime} [mtime] - Modification time * - * @typedef {import('..').CID} CID - * @typedef {import('../../utils').AbortOptions} AbortOptions + * @typedef {import('cids')} CID + * @typedef {import('ipfs-interface/src/basic').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-core/src/components/files/touch.js b/packages/ipfs-core/src/components/files/touch.js index 6d889ba07b..0a4b5769cd 100644 --- a/packages/ipfs-core/src/components/files/touch.js +++ b/packages/ipfs-core/src/components/files/touch.js @@ -15,7 +15,7 @@ const mh = require('multihashing-async').multihash const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option') const defaultOptions = { - /** @type {UnixTime|undefined} */ + /** @type {ToMTime|undefined} */ mtime: undefined, flush: true, shardSplitThreshold: 1000, @@ -121,14 +121,12 @@ module.exports = (context) => { /** * @typedef {Object} TouchOptions - * @property {UnixTime} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime()` + * @property {ToMTime} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime()` * @property {boolean} [flush=false] - If true the changes will be immediately flushed to disk * @property {string} [hashAlg='sha2-256'] - The hash algorithm to use for any updated entries - * @property {0|1} [cidVersion] - The CID version to use for any updated entries + * @property {import('cids').CIDVersion} [cidVersion] - The CID version to use for any updated entries * * @typedef {import('cids')} CID - * @typedef {import('../../utils').AbortOptions} AbortOptions - * @typedef {import('../../utils').Mtime} Mtime - * @typedef {import('../../utils').Hrtime} Hrtime - * @typedef {import('ipfs-core-utils/src/files/normalise-input/normalise-input').UnixTime} UnixTime + * @typedef {import('ipfs-interface/src/basic').AbortOptions} AbortOptions + * @typedef {import('ipfs-interface/src/files').ToMTime} ToMTime */ diff --git a/packages/ipfs-core/src/components/files/write.js b/packages/ipfs-core/src/components/files/write.js index f65987c7a7..a8940d93c3 100644 --- a/packages/ipfs-core/src/components/files/write.js +++ b/packages/ipfs-core/src/components/files/write.js @@ -299,13 +299,11 @@ const countBytesStreamed = async function * (source, notify) { * @property {boolean} [parents=false] - Create intermediate MFS paths if they do not exist * @property {boolean} [truncate=false] - Truncate the file at the MFS path if it would have been larger than the passed content * @property {boolean} [rawLeaves=false] - If true, DAG leaves will contain raw file data and not be wrapped in a protobuf - * @property {number} [mode] - An integer that represents the file mode - * @property {Mtime|Hrtime|Date} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime() + * @property {import('ipfs-interface/src/files').ToMode} [mode] - An integer that represents the file mode + * @property {import('ipfs-interface/src/files').ToMTime} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime() * @property {boolean} [flush] - If true the changes will be immediately flushed to disk * @property {string} [hashAlg='sha2-256'] - The hash algorithm to use for any updated entries * @property {0|1} [cidVersion=0] - The CID version to use for any updated entries * * @typedef {import('../../utils').AbortOptions} AbortOptions - * @typedef {import('../../utils').Mtime} Mtime - * @typedef {import('../../utils').Hrtime} Hrtime */ diff --git a/packages/ipfs-core/src/components/get.js b/packages/ipfs-core/src/components/get.js index 1b614136c9..166427557a 100644 --- a/packages/ipfs-core/src/components/get.js +++ b/packages/ipfs-core/src/components/get.js @@ -11,13 +11,7 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option') * @param {import('.').Preload} config.preload */ module.exports = function ({ ipld, preload }) { - /** - * Fetch a file or an entire directory tree from IPFS that is addressed by a valid IPFS Path. - * - * @param {CID|string} ipfsPath - An IPFS path or CID to export - * @param {Options} [options] - * @returns {AsyncIterable} - */ + /** @type {import('ipfs-interface/src/root').Get} */ async function * get (ipfsPath, options = {}) { if (options.preload !== false) { let pathComponents @@ -41,14 +35,3 @@ module.exports = function ({ ipld, preload }) { return withTimeoutOption(get) } - -/** - * @typedef {GetOptions & AbortOptions} Options - * - * @typedef {Object} GetOptions - * @property {boolean} [preload] - * - * @typedef {import('.').CID} CID - * @typedef {import('../utils').AbortOptions} AbortOptions - * @typedef {import('../utils').IPFSEntry} IPFSEntry - */ diff --git a/packages/ipfs-core/src/components/ls.js b/packages/ipfs-core/src/components/ls.js index 1fe0234f2c..ae661f7f30 100644 --- a/packages/ipfs-core/src/components/ls.js +++ b/packages/ipfs-core/src/components/ls.js @@ -7,17 +7,11 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option') /** * @param {Object} config - * @param {import('./root').IPLD} config.ipld - * @param {import('./root').Preload} config.preload + * @param {import('.').IPLD} config.ipld + * @param {import('.').Preload} config.preload */ module.exports = function ({ ipld, preload }) { - /** - * Lists a directory from IPFS that is addressed by a valid IPFS Path. - * - * @param {string|CID} ipfsPath - An IPFS path or CID to list - * @param {Options} options - * @returns {AsyncIterable} - */ + /** @type {import('ipfs-interface/src/root').List} */ async function * ls (ipfsPath, options = {}) { const path = normalizeCidPath(ipfsPath) const recursive = options.recursive @@ -66,18 +60,3 @@ module.exports = function ({ ipld, preload }) { return withTimeoutOption(ls) } - -/** - * @typedef {import('../utils').IPFSEntry} LSEntry - * - * @typedef {LSOptions & AbortOptions} Options - * - * @typedef {Object} LSOptions - * @property {boolean} [recursive] - * @property {boolean} [preload] - * @property {boolean} [includeContent] - * - * @typedef {import('../utils').AbortOptions} AbortOptions - * - * @typedef {import('.').CID} CID - */ diff --git a/packages/ipfs-core/src/components/root.js b/packages/ipfs-core/src/components/root.js index bb89644d4f..ed2c9ebac5 100644 --- a/packages/ipfs-core/src/components/root.js +++ b/packages/ipfs-core/src/components/root.js @@ -6,15 +6,19 @@ const createCatAPI = require('./cat') const createGetAPI = require('./get') const createLsAPI = require('./ls') -class RootAPI { +/** + * @typedef {import('ipfs-interface').RootAPI} RootAPI + * @implements {RootAPI} + */ +class Root { /** * @param {Object} config - * @param {Block} config.block - * @param {Pin} config.pin - * @param {GCLock} config.gcLock - * @param {Preload} config.preload - * @param {IPLD} config.ipld - * @param {ShardingOptions} [config.options] + * @param {import('.').Block} config.block + * @param {import('.').Pin} config.pin + * @param {import('.').GCLock} config.gcLock + * @param {import('.').Preload} config.preload + * @param {import('.').IPLD} config.ipld + * @param {import('ipfs-interface/src/root').ShardingOptions} [config.options] */ constructor ({ preload, gcLock, pin, block, ipld, options }) { const addAll = createAddAllAPI({ @@ -33,13 +37,4 @@ class RootAPI { } } -module.exports = RootAPI - -/** - * @typedef {import('.').Block} Block - * @typedef {import('.').Pin} Pin - * @typedef {import('.').GCLock} GCLock - * @typedef {import('.').IPLD} IPLD - * @typedef {import('.').Preload} Preload - * @typedef {import('./add-all').ShardingOptions} ShardingOptions - */ +module.exports = Root diff --git a/packages/ipfs-core/src/utils.js b/packages/ipfs-core/src/utils.js index 6846006bf6..7b20fe79f1 100644 --- a/packages/ipfs-core/src/utils.js +++ b/packages/ipfs-core/src/utils.js @@ -97,6 +97,11 @@ const resolvePath = async function (dag, ipfsPath, options = {}) { } /** + * @typedef {import('ipfs-interface/src/files').InputFile} InputFile + * @typedef {import('ipfs-interface/src/files').UnixFSFile} UnixFSFile + * @typedef {import('ipfs-interface/src/files').IPFSEntry} IPFSEntry + * @typedef {import('ipfs-interface').AbortOptions} AbortOptions + * * @param {InputFile|UnixFSFile} file * @param {Object} [options] * @param {boolean} [options.includeContent] @@ -121,6 +126,7 @@ const mapFile = (file, options = {}) => { output.size = file.unixfs.fileSize() if (options.includeContent) { + // @ts-expect-error - content is readonly output.content = file.content() } } @@ -132,92 +138,6 @@ const mapFile = (file, options = {}) => { return output } -/** - * @typedef {Object} File - * @property {'file'} type - * @property {CID} cid - * @property {string} name - * @property {string} path - File path - * @property {AsyncIterable} [content] - File content - * @property {number} [mode] - * @property {MTime} [mtime] - * @property {number} size - * @property {number} depth - * - * @typedef {Object} Directory - * @property {'dir'} type - * @property {CID} cid - * @property {string} name - * @property {string} path - Directory path - * @property {number} [mode] - * @property {MTime} [mtime] - * @property {number} size - * @property {number} depth - * - * @typedef {File|Directory} IPFSEntry - * - * @typedef {Object} BaseFile - * @property {CID} cid - * @property {string} path - * @property {string} name - * - * @typedef {Object} InputFileExt - * @property {undefined} [unixfs] - * - * @typedef {BaseFile & InputFileExt} InputFile - * - * @typedef {Object} UnixFSeExt - * @property {() => AsyncIterable} content - * @property {UnixFS} unixfs - * - * @typedef {BaseFile & UnixFSeExt} UnixFSFile - * - * - * @typedef {Object} UnixFS - * @property {'directory'|'file'|'dir'} type - * @property {() => number} fileSize - * @property {() => AsyncIterable} content - * @property {number} mode - * @property {MTime} mtime - * - * @typedef {object} MTime - * @property {number} secs - the number of seconds since (positive) or before - * (negative) the Unix Epoch began - * @property {number} [nsecs] - the number of nanoseconds since the last full - * second. - */ - -/** - * @template {any[]} ARGS - * @template R - * @typedef {(...args: ARGS) => R} Fn - */ - -/** - * @typedef {object} AbortOptions - * @property {number} [timeout] - A timeout in ms - * @property {AbortSignal} [signal] - Can be used to cancel any long running requests started as a result of this call - */ - -/** - * @typedef {Object} Mtime - * @property {number} [secs] - * @property {number} [nsecs] - */ - -/** - * @typedef {[number, number]} Hrtime - */ - -/** - * @typedef {Object} PreloadOptions - * @property {boolean} [preload=true] - */ - -/** - * @template {Record} ExtraOptions - */ - const withTimeout = withTimeoutOption( /** * @template T diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index 315abda5e0..b131c5f682 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -57,6 +57,7 @@ "form-data": "^3.0.0", "ipfs-core-utils": "^0.5.3", "ipfs-utils": "^5.0.0", + "ipfs-interface": "^0.1.0", "ipld-block": "^0.11.0", "ipld-dag-cbor": "^0.17.0", "ipld-dag-pb": "^0.20.0", diff --git a/packages/ipfs-http-client/src/add-all.js b/packages/ipfs-http-client/src/add-all.js index 49be9c7530..d4bd6b3a6f 100644 --- a/packages/ipfs-http-client/src/add-all.js +++ b/packages/ipfs-http-client/src/add-all.js @@ -98,7 +98,7 @@ const createOnUploadPrgress = (size, parts, progress) => { /** * @param {any} input - * @returns {UnixFSEntry} + * @returns {import('ipfs-interface/src/files').UnixFSEntry} */ function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) { const output = { @@ -121,7 +121,3 @@ function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) { // @ts-ignore return output } - -/** - * @typedef {import('ipfs-core/src/components/add-all/index').UnixFSEntry} UnixFSEntry - */ diff --git a/packages/ipfs-interface/COPYRIGHT b/packages/ipfs-interface/COPYRIGHT new file mode 100644 index 0000000000..e085a877e2 --- /dev/null +++ b/packages/ipfs-interface/COPYRIGHT @@ -0,0 +1,5 @@ +This project is transitioning from an MIT-only license to a dual MIT/Apache-2.0 license. +Unless otherwise noted, all code contributed prior to 2019-11-21 and not contributed by +a user listed in [this signoff issue](https://github.com/ipfs/js-ipfs/issues/2624) is +licensed under MIT-only. All new contributions (and past contributions since 2019-11-21) +are licensed under a dual MIT/Apache-2.0 license. diff --git a/packages/ipfs-interface/LICENSE-APACHE b/packages/ipfs-interface/LICENSE-APACHE new file mode 100644 index 0000000000..14478a3b60 --- /dev/null +++ b/packages/ipfs-interface/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/ipfs-interface/LICENSE-MIT b/packages/ipfs-interface/LICENSE-MIT new file mode 100644 index 0000000000..749aa1ecd9 --- /dev/null +++ b/packages/ipfs-interface/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/packages/ipfs-interface/README.md b/packages/ipfs-interface/README.md new file mode 100644 index 0000000000..56a97538fa --- /dev/null +++ b/packages/ipfs-interface/README.md @@ -0,0 +1,82 @@ +# ipfs-interface + +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) +[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) +[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) +[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) +[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?style=flat-square&path=packages/interface-ipfs-core)](https://david-dm.org/ipfs/js-ipfs?path=packages/interface-ipfs-core) + +> IPFS interface definitions used by implementations for API compatibility. + +## Lead Maintainer + +[Alex Potsides](http://github.com/achingbrain) + +## Table of Contents + +- [Background](#background) +- [Install](#install) +- [Usage](#usage) +- [Validation](#validation) +- [Contribute](#contribute) + - [Want to hack on IPFS?](#want-to-hack-on-ipfs) +- [License](#license) + +## Background + +The primary goal of this module is to define and ensure that IPFS core implementations and their respective HTTP client libraries implement the same interface, so that developers can quickly change between a local and a remote node without having to change their applications. + +It offers set of typescript interface definitions that implementations can claim compatibility with and use typescript to validate those claims. + +## Install + +In JavaScript land: + +```console +$ npm install ipfs-interface +``` + +## Usage + +Install `ipfs-interface` as one of the dependencies of your project and use it to ensure your implementations API compatibility: + +### In [JSDoc syntax](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html) + +```js +/** + * @implements {import('ipfs-interface').RootAPI} + */ +class Root { + // your implementation goes here +} +``` + +### In Typescript + +```ts +import { RootAPI } from 'ipfs-interface' +class Root implements RootAPI { + // your implementation goes here +} +``` + +## Validation + +In order to validate API compatibility you can run [typescript](https://www.typescriptlang.org/) over your implementation which will point out all the API compatibilities if there are some. + + +## Contribute + +Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs/issues)! + +This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +### Want to hack on IPFS? + +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) + +## License + +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large) + +[![](https://github.com/ipfs/js-ipfs/raw/master/packages/ipfs-interface/img/badge.png)](https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-interface) diff --git a/packages/ipfs-interface/package.json b/packages/ipfs-interface/package.json new file mode 100644 index 0000000000..2703960bcb --- /dev/null +++ b/packages/ipfs-interface/package.json @@ -0,0 +1,44 @@ +{ + "name": "ipfs-interface", + "version": "0.1.0", + "description": "IPFS interface definitions used by implementations for API compatibility.", + "leadMaintainer": "Alex Potsides ", + "types": "src/index.ts", + "homepage": "https://github.com/ipfs/js-ipfs/tree/master/packages/interface-ipfs-core#readme", + "bugs": "https://github.com/ipfs/js-ipfs/issues", + "scripts": { + "lint": "aegir lint", + "test": "aegir ts -p check", + "dep-check": "aegir dep-check" + }, + "types": "src/index.ts", + "files": [ + "src" + ], + "eslintConfig": { + "extends": "ipfs" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/js-ipfs.git" + }, + "keywords": [ + "IPFS", + "types", + "interface", + "API" + ], + "license": "(Apache-2.0 OR MIT)", + "dependencies": { + "cids": "^1.0.0", + "multiaddr": "^8.0.0", + "peer-id": "^0.14.1" + }, + "devDependencies": { + "aegir": "^29.2.2", + "typescript": "4.0.x" + }, + "contributors": [ + "Irakli Gozalishvili " + ] +} diff --git a/packages/ipfs-interface/src/basic.ts b/packages/ipfs-interface/src/basic.ts new file mode 100644 index 0000000000..fa7db76086 --- /dev/null +++ b/packages/ipfs-interface/src/basic.ts @@ -0,0 +1,31 @@ +/** + * Common options across all cancellable requests. + */ +export interface AbortOptions { + /** + * Can be provided to a function that starts a long running task, which will + * be aborted when signal is triggered. + */ + signal?: AbortSignal + /** + * Can be provided to a function that starts a long running task, which will + * be aborted after provided timeout (in ms). + */ + timeout?: number +} + +/** + * Represents a value that you can await on, which is either value or a promise + * of one. + */ +export type Await = + | T + | Promise + +/** + * Represents an iterable that can be used in `for await` loops, that is either + * iterable or an async iterable. + */ +export type AwaitIterable = + | Iterable + | AsyncIterable diff --git a/packages/ipfs-interface/src/files.ts b/packages/ipfs-interface/src/files.ts new file mode 100644 index 0000000000..ad13810d62 --- /dev/null +++ b/packages/ipfs-interface/src/files.ts @@ -0,0 +1,211 @@ +import CID from 'cids' +import { AwaitIterable } from './basic' + +export type Entry|Blob> = + | FileEntry + | DirectoryEntry + +export interface BaseEntry { + path: string + mode?: Mode + mtime?: MTime +} +export interface FileEntry |Blob> extends BaseEntry { + content?: Content +} + +export interface DirectoryEntry extends BaseEntry { + content?: void +} + +export type ImportSource = +| AwaitIterable +| ReadableStream + +export type ToEntry = + | ToFile + | ToDirectory + | ToContent + +export interface ToFile extends ToFileMetadata { + path?: string + content: ToContent +} + +export interface ToDirectory extends ToFileMetadata { + path: string + content?: void +} + +export interface ToFileMetadata { + mode?: ToMode + mtime?: ToMTime +} + +/** + * File content in arbitrary (supported) represenation. It is used in input + * positions and is usually normalized to `Blob` in browser contexts and + * `AsyncIterable` in node. + */ +export type ToContent = + | string + | InstanceType + | ArrayBufferView + | ArrayBuffer + | Blob + | AwaitIterable + | ReadableStream + +/** + * Timestamp representation in arbitrary (supported) in representations. It is + * used in input positions and usurally get's normalised to `MTime` before use. + */ +export type ToMTime = + | Date + | HRTime + | MTimeLike + +export type ToMode = + | string + | number + +export interface File { + readonly type: 'file' + readonly cid: CID + readonly name: string + + /** + * File path + */ + readonly path: string + /** + * File content + */ + readonly content?: AsyncIterable + mode?: Mode + mtime?: MTime + size?: number + depth?: number +} + +export interface Directory { + type: 'dir', + cid: CID + name: string + /** + * Directory path + */ + path: string + mode?: Mode + mtime?: MTime + size?: number + depth?: number +} + +export type IPFSEntry = File | Directory + +export interface BaseFile { + cid: CID + path: string + name: string +} + +export interface InputFile extends BaseFile { + unixfs: void +} + +export interface UnixFSFile extends BaseFile { + content(): AsyncIterable + unixfs: UnixFS +} + +export interface UnixFSEntry { + path: string + cid: CID + mode: Mode + mtime: MTime + size: number +} + +export interface MTime { + /** + * The number of seconds since(positive) or before (negative) the Unix Epoch + * began. + */ + readonly secs: number + + /** + * The number of nanoseconds since the last full second + */ + readonly nsecs: number +} + +export interface MTimeLike { + /** + * The number of seconds since(positive) or before (negative) the Unix Epoch + * began. + */ + secs: number + + /** + * The number of nanoseconds since the last full second + */ + nsecs?: number +} + +interface UnixFS { + readonly type: 'directory' | 'file' | 'dir' + readonly mode: Mode + readonly mtime: MTime + + fileSize(): number + content(): AsyncIterable +} + +/** + * Time representation as tuple of two integers, as per the output of + * [`process.hrtime()`](https://nodejs.org/dist/latest/docs/api/process.html#process_process_hrtime_time). + */ +type HRTime = [number, number] + +// It's just a named type alias, but it better captures intent. +export type Mode = number + +/** + * @typedef {import('../format-mtime').MTime} MTime + * @typedef {import('../format-mode').Mode} Mode + * @typedef {Object} Directory + * @property {string} path + * @property {Mode} [mode] + * @property {MTime} [mtime] + * @property {undefined} [content] + * + * @typedef {Object} FileInput + * @property {string} [path] + * @property {ToContent} [content] + * @property {number | string} [mode] + * @property {UnixTime} [mtime] + * + * @typedef {Date | MTime | HRTime} UnixTime + * + * Time representation as tuple of two integers, as per the output of + * [`process.hrtime()`](https://nodejs.org/dist/latest/docs/api/process.html#process_process_hrtime_time). + * @typedef {[number, number]} HRTime + * + * @typedef {string|InstanceType|ArrayBufferView|ArrayBuffer|Blob|Iterable | AsyncIterable | ReadableStream} ToContent + * @typedef {ToContent|FileInput} ToFile + * @typedef {Iterable | AsyncIterable | ReadableStream} Source + */ +/** + * @template {AsyncIterable|Blob} Content + * @typedef {Object} File + * @property {string} path + * @property {Mode} [mode] + * @property {MTime} [mtime] + * @property {Content} [content] + */ + +/** + * @template {AsyncIterable|Blob} Content + * @typedef {File|Directory} Entry + */ diff --git a/packages/ipfs-interface/src/index.ts b/packages/ipfs-interface/src/index.ts new file mode 100644 index 0000000000..c9be30e9cc --- /dev/null +++ b/packages/ipfs-interface/src/index.ts @@ -0,0 +1,10 @@ +import { RootAPI } from './root' +import { AbortOptions, Await, AwaitIterable } from './basic' + +export { + RootAPI, + + AbortOptions, + Await, + AwaitIterable +} diff --git a/packages/ipfs-interface/src/preload.ts b/packages/ipfs-interface/src/preload.ts new file mode 100644 index 0000000000..ea62ac506d --- /dev/null +++ b/packages/ipfs-interface/src/preload.ts @@ -0,0 +1,3 @@ +export interface Options { + preload?: boolean +} diff --git a/packages/ipfs-interface/src/root.ts b/packages/ipfs-interface/src/root.ts new file mode 100644 index 0000000000..5cc4dca4e5 --- /dev/null +++ b/packages/ipfs-interface/src/root.ts @@ -0,0 +1,143 @@ +import { AbortOptions } from './basic' +import { Options as PreloadOptions } from './preload' +import { ImportSource, IPFSEntry, ToEntry, UnixFSEntry } from './files' +import CID, { CIDVersion } from 'cids' + +export interface RootAPI { + add: Add + addAll: AddAll + cat: Cat + get: Get +} + +/** + * Import a file or data into IPFS. + */ +export interface Add { + (entry: ToEntry, options?: AddOptions): Promise +} + +export interface AddOptions extends AbortOptions { + /** + * Chunking algorithm used to build ipfs DAGs. (defaults to 'size-262144') + */ + chunker?: string + /** + * The CID version to use when storing the data + */ + cidVersion?: CIDVersion + + /** + * Multihash hashing algorithm to use. (Defaults to 'sha2-256') + */ + hashAlg?: string + + /** + * If true, will not add blocks to the blockstore. (Defaults to `false`) + */ + onlyHash?: boolean + + /** + * Pin this object when adding. (Defaults to `true`) + */ + pin?: boolean + + /** + * A function that will be called with the number of bytes added as a file is + * added to ipfs and the path of the file being added. + * + * **Note** It will not be called for directory entries. + */ + progress?: (bytes: number, path: string) => void + + /** + * If true, DAG leaves will contain raw file data and not be wrapped in a + * protobuf. (Defaults to `false`) + */ + rawLeaves?: boolean + + /** + * If true will use the + * [trickle DAG](https://godoc.org/github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-unixfs/importer/trickle) + * format for DAG generation. (Defaults to `false`). + */ + trickle?: boolean + + /** + * Adds a wrapping node around the content. (Defaults to `false`) + */ + wrapWithDirectory?: boolean + +} + +/** + * Import multiple files and data into IPFS. + */ +export interface AddAll { + (source: ImportSource, options?: AddAllOptions & AbortOptions): AsyncIterable +} + +export interface AddAllOptions extends AddOptions { + + /** + * Allows to create directories with an unlimited number of entries currently + * size of unixfs directories is limited by the maximum block size. + * ** Note ** that this is an experimental feature. (Defaults to `false`) + */ + enableShardingExperiment?: boolean + + /** + * Directories with more than this number of files will be created as HAMT - + * sharded directories. (Defaults to 1000) + */ + shardSplitThreshold?: number +} + +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 +} + +export interface CatOptions extends AbortOptions, PreloadOptions { + /** + * An offset to start reading the file from + */ + offset?: number + /** + * An optional max length to read from the file + */ + 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 +} + +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 +} + +export interface ListOptions extends AbortOptions, PreloadOptions { + recursive?: boolean, + includeContent?: boolean +} + +/** + * An IPFS path or CID + */ +export type IPFSPath = CID | string diff --git a/packages/ipfs-interface/tsconfig.json b/packages/ipfs-interface/tsconfig.json new file mode 100644 index 0000000000..f090f172de --- /dev/null +++ b/packages/ipfs-interface/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noImplicitAny": true + }, + "include": [ + "src" + ] +} diff --git a/packages/ipfs-message-port-client/package.json b/packages/ipfs-message-port-client/package.json index 6319b4d411..af99e59b27 100644 --- a/packages/ipfs-message-port-client/package.json +++ b/packages/ipfs-message-port-client/package.json @@ -43,7 +43,8 @@ }, "dependencies": { "browser-readablestream-to-it": "^1.0.1", - "ipfs-message-port-protocol": "^0.4.2" + "ipfs-message-port-protocol": "^0.4.2", + "ipfs-interface": "^0.1.0" }, "devDependencies": { "aegir": "^29.2.2", diff --git a/packages/ipfs-message-port-client/src/core.js b/packages/ipfs-message-port-client/src/core.js index cddac962a2..deb840973d 100644 --- a/packages/ipfs-message-port-client/src/core.js +++ b/packages/ipfs-message-port-client/src/core.js @@ -161,7 +161,7 @@ class CoreClient extends Client { * Decodes values yield by `ipfs.add`. * * @param {AddedEntry} data - * @returns {import('ipfs-core/src/components/add-all').UnixFSEntry} + * @returns {import('ipfs-interface/src/files').UnixFSEntry} */ const decodeAddedData = ({ path, cid, mode, mtime, size }) => { return { diff --git a/tsconfig.json b/tsconfig.json index a5f6d1a969..79830608ac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,7 +24,7 @@ "stripInternal": true, "resolveJsonModule": true, "incremental": true, - "baseUrl": "packages", + "baseUrl": ".", "paths": { "interface-ipfs-core/*": [ "interface-ipfs-core/*" From 7dd1e725f1fcd9563687dc8c4283f97c3112ada3 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Wed, 16 Dec 2020 00:30:32 -0800 Subject: [PATCH 28/46] chore: revert ts-expect-error --- examples/types-use-ipfs-from-ts/src/main.ts | 1 + .../types-use-ipfs-from-typed-js/src/main.js | 1 + .../ipfs-core/src/components/add-all/index.js | 22 +++++++--- packages/ipfs-core/src/components/add.js | 16 +++++-- packages/ipfs-core/src/components/cat.js | 16 +++++-- packages/ipfs-core/src/components/get.js | 17 +++++-- packages/ipfs-core/src/components/ls.js | 16 +++++-- packages/ipfs-interface/src/root.ts | 44 +++---------------- 8 files changed, 71 insertions(+), 62 deletions(-) diff --git a/examples/types-use-ipfs-from-ts/src/main.ts b/examples/types-use-ipfs-from-ts/src/main.ts index 29e1741602..5f84fd8408 100644 --- a/examples/types-use-ipfs-from-ts/src/main.ts +++ b/examples/types-use-ipfs-from-ts/src/main.ts @@ -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) { diff --git a/examples/types-use-ipfs-from-typed-js/src/main.js b/examples/types-use-ipfs-from-typed-js/src/main.js index 5e24546705..c5279b646c 100644 --- a/examples/types-use-ipfs-from-typed-js/src/main.js +++ b/examples/types-use-ipfs-from-typed-js/src/main.js @@ -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) { diff --git a/packages/ipfs-core/src/components/add-all/index.js b/packages/ipfs-core/src/components/add-all/index.js index 5c163f944d..ad9f6a012a 100644 --- a/packages/ipfs-core/src/components/add-all/index.js +++ b/packages/ipfs-core/src/components/add-all/index.js @@ -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} + */ async function * addAll (source, options = {}) { const opts = mergeOptions({ shardSplitThreshold: isShardingEnabled ? 1000 : Infinity, diff --git a/packages/ipfs-core/src/components/add.js b/packages/ipfs-core/src/components/add.js index b71ea1d596..d9ac014c6c 100644 --- a/packages/ipfs-core/src/components/add.js +++ b/packages/ipfs-core/src/components/add.js @@ -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} 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} + */ 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 diff --git a/packages/ipfs-core/src/components/cat.js b/packages/ipfs-core/src/components/cat.js index c76029b5ce..26aeac3f87 100644 --- a/packages/ipfs-core/src/components/cat.js +++ b/packages/ipfs-core/src/components/cat.js @@ -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} + */ async function * cat (ipfsPath, options = {}) { ipfsPath = normalizeCidPath(ipfsPath) diff --git a/packages/ipfs-core/src/components/get.js b/packages/ipfs-core/src/components/get.js index 166427557a..6dd6fdddba 100644 --- a/packages/ipfs-core/src/components/get.js +++ b/packages/ipfs-core/src/components/get.js @@ -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} + */ async function * get (ipfsPath, options = {}) { if (options.preload !== false) { let pathComponents diff --git a/packages/ipfs-core/src/components/ls.js b/packages/ipfs-core/src/components/ls.js index ae661f7f30..ff761ac0c4 100644 --- a/packages/ipfs-core/src/components/ls.js +++ b/packages/ipfs-core/src/components/ls.js @@ -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} + */ async function * ls (ipfsPath, options = {}) { const path = normalizeCidPath(ipfsPath) const recursive = options.recursive diff --git a/packages/ipfs-interface/src/root.ts b/packages/ipfs-interface/src/root.ts index 5cc4dca4e5..e9a5055d32 100644 --- a/packages/ipfs-interface/src/root.ts +++ b/packages/ipfs-interface/src/root.ts @@ -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 + addAll(source: ImportSource, options?: AddAllOptions & AbortOptions): AsyncIterable + cat(ipfsPath: IPFSPath, options?: CatOptions): AsyncIterable + get(ipfsPath: IPFSPath, options?: GetOptions): AsyncIterable -/** - * Import a file or data into IPFS. - */ -export interface Add { - (entry: ToEntry, options?: AddOptions): Promise + ls(ipfsPath: IPFSPath, options?: ListOptions): AsyncIterable } export interface AddOptions extends AbortOptions { @@ -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 -} - export interface AddAllOptions extends AddOptions { /** @@ -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 -} - export interface CatOptions extends AbortOptions, PreloadOptions { /** * An offset to start reading the file from @@ -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 -} - 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 -} - export interface ListOptions extends AbortOptions, PreloadOptions { recursive?: boolean, includeContent?: boolean From 0cd45dcecb4edcfbdf190cf83aef5edaf5df4bb9 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Wed, 16 Dec 2020 00:34:33 -0800 Subject: [PATCH 29/46] chore: consolidate all the types in one place --- packages/ipfs-core/src/components/config.js | 2 +- packages/ipfs-core/src/components/index.js | 4 +- packages/ipfs-core/src/components/ipld.js | 8 ++-- packages/ipfs-core/src/components/network.js | 2 +- packages/ipfs-core/src/components/root.js | 13 +++---- packages/ipfs-core/src/components/storage.js | 2 +- packages/ipfs-core/src/interface/basic.ts | 28 ------------- packages/ipfs-core/src/runtime/repo-nodejs.js | 2 +- packages/ipfs-core/src/utils/service.js | 2 +- packages/ipfs-interface/src/basic.ts | 38 +++++++++++------- .../src}/bitswap.ts | 8 +++- .../src/bitswap}/moving-avarage.ts | 0 .../src}/block-service.ts | 8 +++- .../src}/datastore.ts | 0 packages/ipfs-interface/src/files.ts | 39 ------------------- .../interface => ipfs-interface/src}/ipld.ts | 5 ++- .../src/ipld}/format.ts | 3 +- .../interface => ipfs-interface/src}/repo.ts | 4 +- .../interface => ipfs-interface/src}/store.ts | 0 19 files changed, 61 insertions(+), 107 deletions(-) delete mode 100644 packages/ipfs-core/src/interface/basic.ts rename packages/{ipfs-core/src/interface => ipfs-interface/src}/bitswap.ts (88%) rename packages/{ipfs-core/src/interface => ipfs-interface/src/bitswap}/moving-avarage.ts (100%) rename packages/{ipfs-core/src/interface => ipfs-interface/src}/block-service.ts (78%) rename packages/{ipfs-core/src/interface => ipfs-interface/src}/datastore.ts (100%) rename packages/{ipfs-core/src/interface => ipfs-interface/src}/ipld.ts (88%) rename packages/{ipfs-core/src/interface => ipfs-interface/src/ipld}/format.ts (93%) rename packages/{ipfs-core/src/interface => ipfs-interface/src}/repo.ts (94%) rename packages/{ipfs-core/src/interface => ipfs-interface/src}/store.ts (100%) diff --git a/packages/ipfs-core/src/components/config.js b/packages/ipfs-core/src/components/config.js index ee45ce5c39..7eaef35ba0 100644 --- a/packages/ipfs-core/src/components/config.js +++ b/packages/ipfs-core/src/components/config.js @@ -505,6 +505,6 @@ module.exports.profiles = profiles * @typedef {Object} RoutingConfig * @property {string} [Type] * - * @typedef {import('../interface/basic').ToJSON} ToJSON + * @typedef {import('ipfs-interface/src/basic').ToJSON} ToJSON * @typedef {import('.').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-core/src/components/index.js b/packages/ipfs-core/src/components/index.js index f2d8b06759..51d76dbce2 100644 --- a/packages/ipfs-core/src/components/index.js +++ b/packages/ipfs-core/src/components/index.js @@ -362,8 +362,8 @@ const getDefaultOptions = () => ({ * @typedef {import('peer-id')} PeerId * @typedef {import('./libp2p').LibP2P} LibP2P * @typedef {import('./pin/pin-manager')} PinManager - * @typedef {import('../interface/block-service').BlockService} BlockService - * @typedef {import('../interface/bitswap').Bitswap} BitSwap + * @typedef {import('ipfs-interface/src/block-service').BlockService} BlockService + * @typedef {import('ipfs-interface/src/bitswap').Bitswap} BitSwap * @typedef {import('./ipld').IPLD} IPLD * @typedef {import('./gc-lock').GCLock} GCLock * @typedef {import('../preload').Preload} Preload diff --git a/packages/ipfs-core/src/components/ipld.js b/packages/ipfs-core/src/components/ipld.js index a8b465bc08..68fdcc0926 100644 --- a/packages/ipfs-core/src/components/ipld.js +++ b/packages/ipfs-core/src/components/ipld.js @@ -15,9 +15,9 @@ const createIPLD = ({ blockService, print, options }) => module.exports = createIPLD /** - * @typedef {import('../interface/ipld').IPLD} IPLD - * @typedef {import('../interface/ipld').Options} Options - * @typedef {import('../interface/block-service').BlockService} BlockService - * @typedef {import('../interface/basic').Block} Block + * @typedef {import('ipfs-interface/src/ipld').IPLD} IPLD + * @typedef {import('ipfs-interface/src/ipld').Options} Options + * @typedef {import('ipfs-interface/src/block-service').BlockService} BlockService + * @typedef {import('ipfs-interface/src/block-service').Block} Block * @typedef {import('.').Print} Print */ diff --git a/packages/ipfs-core/src/components/network.js b/packages/ipfs-core/src/components/network.js index 8da890a3d5..745984fcc0 100644 --- a/packages/ipfs-core/src/components/network.js +++ b/packages/ipfs-core/src/components/network.js @@ -117,7 +117,7 @@ const WEBSOCKET_STAR_PROTO_CODE = 479 * @typedef {import('.').Repo} Repo * @typedef {import('.').Print} Print * @typedef {import('.').LibP2P} LibP2P - * @typedef {import('../interface/bitswap').Bitswap} BitSwap + * @typedef {import('ipfs-interface/src/bitswap').Bitswap} BitSwap * @typedef {import('.').PeerId} PeerId * @typedef {import('.').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-core/src/components/root.js b/packages/ipfs-core/src/components/root.js index ed2c9ebac5..2c09b9e82c 100644 --- a/packages/ipfs-core/src/components/root.js +++ b/packages/ipfs-core/src/components/root.js @@ -7,18 +7,17 @@ const createGetAPI = require('./get') const createLsAPI = require('./ls') /** + * @typedef {AddAllContext & CatContext & GetContext & ListContext } Context + * @typedef {import('./add-all').Context} AddAllContext + * @typedef {import('./cat').Context} CatContext + * @typedef {import('./get').Context} GetContext + * @typedef {import('./ls').Context} ListContext * @typedef {import('ipfs-interface').RootAPI} RootAPI * @implements {RootAPI} */ class Root { /** - * @param {Object} config - * @param {import('.').Block} config.block - * @param {import('.').Pin} config.pin - * @param {import('.').GCLock} config.gcLock - * @param {import('.').Preload} config.preload - * @param {import('.').IPLD} config.ipld - * @param {import('ipfs-interface/src/root').ShardingOptions} [config.options] + * @param {Context} context */ constructor ({ preload, gcLock, pin, block, ipld, options }) { const addAll = createAddAllAPI({ diff --git a/packages/ipfs-core/src/components/storage.js b/packages/ipfs-core/src/components/storage.js index 4152d3bd24..3f1f370c3b 100644 --- a/packages/ipfs-core/src/components/storage.js +++ b/packages/ipfs-core/src/components/storage.js @@ -295,7 +295,7 @@ const applyProfiles = (config, profiles) => { * @typedef {import('.').IPLDOptions} IPLDOptions * @typedef {import('.').Print} Print * @typedef {import('.').IPFSConfig} IPFSConfig - * @typedef {import('../interface/repo').Repo} Repo + * @typedef {import('ipfs-interface/src/repo').Repo} Repo * @typedef {import('libp2p-crypto').KeyType} KeyType * @typedef {import('libp2p').LibP2PKeychain} Keychain */ diff --git a/packages/ipfs-core/src/interface/basic.ts b/packages/ipfs-core/src/interface/basic.ts deleted file mode 100644 index 41dea96426..0000000000 --- a/packages/ipfs-core/src/interface/basic.ts +++ /dev/null @@ -1,28 +0,0 @@ -import CID from 'cids' -import PeerId from 'peer-id' -import BigInteger from 'bignumber.js' -export type Await = - | T - | Promise - -export type AwaitIterable = - | Iterable - | AsyncIterable - -export interface AbortOptions { - signal?: AbortSignal -} -export type ToJSON = - | null - | string - | number - | boolean - | ToJSON[] - | { toJSON?: () => ToJSON } & {[key:string]: ToJSON} - -export interface Block { - cid: CID - data: Uint8Array -} - -export type { CID, PeerId, BigInteger } diff --git a/packages/ipfs-core/src/runtime/repo-nodejs.js b/packages/ipfs-core/src/runtime/repo-nodejs.js index a5f3ec99d8..b10c2af41b 100644 --- a/packages/ipfs-core/src/runtime/repo-nodejs.js +++ b/packages/ipfs-core/src/runtime/repo-nodejs.js @@ -32,6 +32,6 @@ module.exports = (options = {}) => { } /** - * @typedef {import('../interface/repo').Repo} Repo + * @typedef {import('ipfs-interface/src/repo').Repo} Repo * @typedef {import('../components/config').IPFSConfig} IPFSConfig */ diff --git a/packages/ipfs-core/src/utils/service.js b/packages/ipfs-core/src/utils/service.js index fda5020b84..a5d118fbfe 100644 --- a/packages/ipfs-core/src/utils/service.js +++ b/packages/ipfs-core/src/utils/service.js @@ -212,7 +212,7 @@ module.exports = Service /** * @template T - * @typedef {import('../interface/basic').Await} Await + * @typedef {import('ipfs-interface/src/basic').Await} Await */ /** * @template {(options:any) => any} T diff --git a/packages/ipfs-interface/src/basic.ts b/packages/ipfs-interface/src/basic.ts index fa7db76086..f492bb853a 100644 --- a/packages/ipfs-interface/src/basic.ts +++ b/packages/ipfs-interface/src/basic.ts @@ -1,3 +1,19 @@ +/** + * Represents a value that you can await on, which is either value or a promise + * of one. + */ +export type Await = + | T + | Promise + +/** + * Represents an iterable that can be used in `for await` loops, that is either + * iterable or an async iterable. + */ +export type AwaitIterable = + | Iterable + | AsyncIterable + /** * Common options across all cancellable requests. */ @@ -14,18 +30,10 @@ export interface AbortOptions { timeout?: number } -/** - * Represents a value that you can await on, which is either value or a promise - * of one. - */ -export type Await = - | T - | Promise - -/** - * Represents an iterable that can be used in `for await` loops, that is either - * iterable or an async iterable. - */ -export type AwaitIterable = - | Iterable - | AsyncIterable +export type ToJSON = + | null + | string + | number + | boolean + | ToJSON[] + | { toJSON?: () => ToJSON } & { [key: string]: ToJSON } diff --git a/packages/ipfs-core/src/interface/bitswap.ts b/packages/ipfs-interface/src/bitswap.ts similarity index 88% rename from packages/ipfs-core/src/interface/bitswap.ts rename to packages/ipfs-interface/src/bitswap.ts index 456a232adc..03600e7b83 100644 --- a/packages/ipfs-core/src/interface/bitswap.ts +++ b/packages/ipfs-interface/src/bitswap.ts @@ -1,5 +1,9 @@ -import { PeerId, CID, Block, Await, BigInteger, AbortOptions } from './basic' -import { MovingAverage } from './moving-avarage' +import BigInteger from 'bignumber.js' +import PeerId from 'peer-id' +import CID from 'cids' +import { Block } from './block-service' +import { AbortOptions, Await } from './basic' +import { MovingAverage } from './bitswap/moving-avarage' import { StoreReader, StoreExporter, StoreImporter } from './store' export interface Bitswap extends diff --git a/packages/ipfs-core/src/interface/moving-avarage.ts b/packages/ipfs-interface/src/bitswap/moving-avarage.ts similarity index 100% rename from packages/ipfs-core/src/interface/moving-avarage.ts rename to packages/ipfs-interface/src/bitswap/moving-avarage.ts diff --git a/packages/ipfs-core/src/interface/block-service.ts b/packages/ipfs-interface/src/block-service.ts similarity index 78% rename from packages/ipfs-core/src/interface/block-service.ts rename to packages/ipfs-interface/src/block-service.ts index aa206edc4d..e547c30ed3 100644 --- a/packages/ipfs-core/src/interface/block-service.ts +++ b/packages/ipfs-interface/src/block-service.ts @@ -1,4 +1,5 @@ -import { Block, CID, Await, AbortOptions } from './basic' +import CID from 'cids' +import { Await, AbortOptions } from './basic' import { StoreReader, StoreImporter, StoreExporter, StoreEraser } from './store' import { Bitswap } from './bitswap' @@ -18,3 +19,8 @@ export interface BlockService extends */ put(block: Block, options?:AbortOptions): Await } + +export interface Block { + cid: CID + data: Uint8Array +} diff --git a/packages/ipfs-core/src/interface/datastore.ts b/packages/ipfs-interface/src/datastore.ts similarity index 100% rename from packages/ipfs-core/src/interface/datastore.ts rename to packages/ipfs-interface/src/datastore.ts diff --git a/packages/ipfs-interface/src/files.ts b/packages/ipfs-interface/src/files.ts index ad13810d62..7c7dd0af7b 100644 --- a/packages/ipfs-interface/src/files.ts +++ b/packages/ipfs-interface/src/files.ts @@ -170,42 +170,3 @@ type HRTime = [number, number] // It's just a named type alias, but it better captures intent. export type Mode = number - -/** - * @typedef {import('../format-mtime').MTime} MTime - * @typedef {import('../format-mode').Mode} Mode - * @typedef {Object} Directory - * @property {string} path - * @property {Mode} [mode] - * @property {MTime} [mtime] - * @property {undefined} [content] - * - * @typedef {Object} FileInput - * @property {string} [path] - * @property {ToContent} [content] - * @property {number | string} [mode] - * @property {UnixTime} [mtime] - * - * @typedef {Date | MTime | HRTime} UnixTime - * - * Time representation as tuple of two integers, as per the output of - * [`process.hrtime()`](https://nodejs.org/dist/latest/docs/api/process.html#process_process_hrtime_time). - * @typedef {[number, number]} HRTime - * - * @typedef {string|InstanceType|ArrayBufferView|ArrayBuffer|Blob|Iterable | AsyncIterable | ReadableStream} ToContent - * @typedef {ToContent|FileInput} ToFile - * @typedef {Iterable | AsyncIterable | ReadableStream} Source - */ -/** - * @template {AsyncIterable|Blob} Content - * @typedef {Object} File - * @property {string} path - * @property {Mode} [mode] - * @property {MTime} [mtime] - * @property {Content} [content] - */ - -/** - * @template {AsyncIterable|Blob} Content - * @typedef {File|Directory} Entry - */ diff --git a/packages/ipfs-core/src/interface/ipld.ts b/packages/ipfs-interface/src/ipld.ts similarity index 88% rename from packages/ipfs-core/src/interface/ipld.ts rename to packages/ipfs-interface/src/ipld.ts index c168e38f61..f31ae7c6bb 100644 --- a/packages/ipfs-core/src/interface/ipld.ts +++ b/packages/ipfs-interface/src/ipld.ts @@ -1,7 +1,8 @@ import { BlockService } from './block-service' -import { Await, CID, AwaitIterable, AbortOptions } from './basic' +import CID from 'cids' +import { Await, AwaitIterable, AbortOptions } from './basic' import { StoreReader, StoreExporter, StoreEraser } from './store' -import { ResolveResult, Format } from './format' +import { ResolveResult, Format } from './ipld/format' export interface IPLD extends StoreReader, diff --git a/packages/ipfs-core/src/interface/format.ts b/packages/ipfs-interface/src/ipld/format.ts similarity index 93% rename from packages/ipfs-core/src/interface/format.ts rename to packages/ipfs-interface/src/ipld/format.ts index 4c0da87482..9613d3af70 100644 --- a/packages/ipfs-core/src/interface/format.ts +++ b/packages/ipfs-interface/src/ipld/format.ts @@ -1,5 +1,6 @@ -import { Await, CID } from './basic' +import CID from 'cids' +import { Await } from '../basic' export interface Format { util: Util diff --git a/packages/ipfs-core/src/interface/repo.ts b/packages/ipfs-interface/src/repo.ts similarity index 94% rename from packages/ipfs-core/src/interface/repo.ts rename to packages/ipfs-interface/src/repo.ts index efe003516a..4bf544d0ec 100644 --- a/packages/ipfs-core/src/interface/repo.ts +++ b/packages/ipfs-interface/src/repo.ts @@ -1,4 +1,6 @@ -import { CID, Block, ToJSON, Await, AbortOptions } from './basic' +import CID from 'cids' +import { Block } from './block-service' +import { ToJSON, Await, AbortOptions } from './basic' import { DataStore, Key } from './datastore' import { ValueStore, StoreReader, Resource, StoreLookup, diff --git a/packages/ipfs-core/src/interface/store.ts b/packages/ipfs-interface/src/store.ts similarity index 100% rename from packages/ipfs-core/src/interface/store.ts rename to packages/ipfs-interface/src/store.ts From 777f18ebd3bdb0b3b6dbc9cc588d19671d9fe086 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Wed, 16 Dec 2020 14:39:45 -0800 Subject: [PATCH 30/46] chore: rename ipfs-interface to ipfs-core-types --- .../{ipfs-interface => ipfs-core-types}/COPYRIGHT | 0 .../LICENSE-APACHE | 0 .../{ipfs-interface => ipfs-core-types}/LICENSE-MIT | 0 .../{ipfs-interface => ipfs-core-types}/README.md | 12 ++++++------ .../{ipfs-interface => ipfs-core-types}/package.json | 2 +- .../{ipfs-interface => ipfs-core-types}/src/basic.ts | 0 .../src/bitswap.ts | 0 .../src/bitswap/moving-avarage.ts | 0 .../src/block-service.ts | 0 .../src/datastore.ts | 0 .../{ipfs-interface => ipfs-core-types}/src/files.ts | 0 .../{ipfs-interface => ipfs-core-types}/src/index.ts | 0 .../{ipfs-interface => ipfs-core-types}/src/ipld.ts | 0 .../src/ipld/format.ts | 0 .../src/preload.ts | 0 .../{ipfs-interface => ipfs-core-types}/src/repo.ts | 0 .../{ipfs-interface => ipfs-core-types}/src/root.ts | 0 .../{ipfs-interface => ipfs-core-types}/src/store.ts | 0 .../tsconfig.json | 0 packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-core-utils/src/files/format-mode.js | 2 +- packages/ipfs-core-utils/src/files/format-mtime.js | 2 +- .../src/files/normalise-input/index.browser.js | 4 ++-- .../src/files/normalise-input/index.js | 4 ++-- .../src/files/normalise-input/normalise-input.js | 10 +++++----- .../src/files/normalise-input/utils.js | 2 +- packages/ipfs-core/package.json | 2 +- packages/ipfs-core/src/components/add-all/index.js | 8 ++++---- packages/ipfs-core/src/components/add.js | 8 ++++---- packages/ipfs-core/src/components/cat.js | 4 ++-- packages/ipfs-core/src/components/config.js | 2 +- packages/ipfs-core/src/components/files/mkdir.js | 8 ++++---- packages/ipfs-core/src/components/files/stat.js | 4 ++-- packages/ipfs-core/src/components/files/touch.js | 4 ++-- packages/ipfs-core/src/components/files/write.js | 4 ++-- packages/ipfs-core/src/components/get.js | 6 +++--- packages/ipfs-core/src/components/index.js | 4 ++-- packages/ipfs-core/src/components/ipld.js | 8 ++++---- packages/ipfs-core/src/components/ls.js | 6 +++--- packages/ipfs-core/src/components/network.js | 2 +- packages/ipfs-core/src/components/root.js | 2 +- packages/ipfs-core/src/components/storage.js | 2 +- packages/ipfs-core/src/runtime/repo-nodejs.js | 2 +- packages/ipfs-core/src/utils.js | 8 ++++---- packages/ipfs-core/src/utils/service.js | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs-http-client/src/add-all.js | 2 +- packages/ipfs-message-port-client/package.json | 2 +- packages/ipfs-message-port-client/src/core.js | 2 +- 49 files changed, 67 insertions(+), 67 deletions(-) rename packages/{ipfs-interface => ipfs-core-types}/COPYRIGHT (100%) rename packages/{ipfs-interface => ipfs-core-types}/LICENSE-APACHE (100%) rename packages/{ipfs-interface => ipfs-core-types}/LICENSE-MIT (100%) rename packages/{ipfs-interface => ipfs-core-types}/README.md (85%) rename packages/{ipfs-interface => ipfs-core-types}/package.json (97%) rename packages/{ipfs-interface => ipfs-core-types}/src/basic.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/bitswap.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/bitswap/moving-avarage.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/block-service.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/datastore.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/files.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/index.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/ipld.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/ipld/format.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/preload.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/repo.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/root.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/src/store.ts (100%) rename packages/{ipfs-interface => ipfs-core-types}/tsconfig.json (100%) diff --git a/packages/ipfs-interface/COPYRIGHT b/packages/ipfs-core-types/COPYRIGHT similarity index 100% rename from packages/ipfs-interface/COPYRIGHT rename to packages/ipfs-core-types/COPYRIGHT diff --git a/packages/ipfs-interface/LICENSE-APACHE b/packages/ipfs-core-types/LICENSE-APACHE similarity index 100% rename from packages/ipfs-interface/LICENSE-APACHE rename to packages/ipfs-core-types/LICENSE-APACHE diff --git a/packages/ipfs-interface/LICENSE-MIT b/packages/ipfs-core-types/LICENSE-MIT similarity index 100% rename from packages/ipfs-interface/LICENSE-MIT rename to packages/ipfs-core-types/LICENSE-MIT diff --git a/packages/ipfs-interface/README.md b/packages/ipfs-core-types/README.md similarity index 85% rename from packages/ipfs-interface/README.md rename to packages/ipfs-core-types/README.md index 56a97538fa..831e49bf1f 100644 --- a/packages/ipfs-interface/README.md +++ b/packages/ipfs-core-types/README.md @@ -1,4 +1,4 @@ -# ipfs-interface +# ipfs-core-types [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) @@ -33,18 +33,18 @@ It offers set of typescript interface definitions that implementations can claim In JavaScript land: ```console -$ npm install ipfs-interface +$ npm install ipfs-core-types ``` ## Usage -Install `ipfs-interface` as one of the dependencies of your project and use it to ensure your implementations API compatibility: +Install `ipfs-core-types` as one of the dependencies of your project and use it to ensure your implementations API compatibility: ### In [JSDoc syntax](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html) ```js /** - * @implements {import('ipfs-interface').RootAPI} + * @implements {import('ipfs-core-types').RootAPI} */ class Root { // your implementation goes here @@ -54,7 +54,7 @@ class Root { ### In Typescript ```ts -import { RootAPI } from 'ipfs-interface' +import { RootAPI } from 'ipfs-core-types' class Root implements RootAPI { // your implementation goes here } @@ -79,4 +79,4 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large) -[![](https://github.com/ipfs/js-ipfs/raw/master/packages/ipfs-interface/img/badge.png)](https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-interface) +[![](https://github.com/ipfs/js-ipfs/raw/master/ipfs-core-types/img/badge.png)](https://github.com/ipfs/js-ipfs/tree/master/ipfs-core-types) diff --git a/packages/ipfs-interface/package.json b/packages/ipfs-core-types/package.json similarity index 97% rename from packages/ipfs-interface/package.json rename to packages/ipfs-core-types/package.json index 2703960bcb..2cdb7f1c05 100644 --- a/packages/ipfs-interface/package.json +++ b/packages/ipfs-core-types/package.json @@ -1,5 +1,5 @@ { - "name": "ipfs-interface", + "name": "ipfs-core-types", "version": "0.1.0", "description": "IPFS interface definitions used by implementations for API compatibility.", "leadMaintainer": "Alex Potsides ", diff --git a/packages/ipfs-interface/src/basic.ts b/packages/ipfs-core-types/src/basic.ts similarity index 100% rename from packages/ipfs-interface/src/basic.ts rename to packages/ipfs-core-types/src/basic.ts diff --git a/packages/ipfs-interface/src/bitswap.ts b/packages/ipfs-core-types/src/bitswap.ts similarity index 100% rename from packages/ipfs-interface/src/bitswap.ts rename to packages/ipfs-core-types/src/bitswap.ts diff --git a/packages/ipfs-interface/src/bitswap/moving-avarage.ts b/packages/ipfs-core-types/src/bitswap/moving-avarage.ts similarity index 100% rename from packages/ipfs-interface/src/bitswap/moving-avarage.ts rename to packages/ipfs-core-types/src/bitswap/moving-avarage.ts diff --git a/packages/ipfs-interface/src/block-service.ts b/packages/ipfs-core-types/src/block-service.ts similarity index 100% rename from packages/ipfs-interface/src/block-service.ts rename to packages/ipfs-core-types/src/block-service.ts diff --git a/packages/ipfs-interface/src/datastore.ts b/packages/ipfs-core-types/src/datastore.ts similarity index 100% rename from packages/ipfs-interface/src/datastore.ts rename to packages/ipfs-core-types/src/datastore.ts diff --git a/packages/ipfs-interface/src/files.ts b/packages/ipfs-core-types/src/files.ts similarity index 100% rename from packages/ipfs-interface/src/files.ts rename to packages/ipfs-core-types/src/files.ts diff --git a/packages/ipfs-interface/src/index.ts b/packages/ipfs-core-types/src/index.ts similarity index 100% rename from packages/ipfs-interface/src/index.ts rename to packages/ipfs-core-types/src/index.ts diff --git a/packages/ipfs-interface/src/ipld.ts b/packages/ipfs-core-types/src/ipld.ts similarity index 100% rename from packages/ipfs-interface/src/ipld.ts rename to packages/ipfs-core-types/src/ipld.ts diff --git a/packages/ipfs-interface/src/ipld/format.ts b/packages/ipfs-core-types/src/ipld/format.ts similarity index 100% rename from packages/ipfs-interface/src/ipld/format.ts rename to packages/ipfs-core-types/src/ipld/format.ts diff --git a/packages/ipfs-interface/src/preload.ts b/packages/ipfs-core-types/src/preload.ts similarity index 100% rename from packages/ipfs-interface/src/preload.ts rename to packages/ipfs-core-types/src/preload.ts diff --git a/packages/ipfs-interface/src/repo.ts b/packages/ipfs-core-types/src/repo.ts similarity index 100% rename from packages/ipfs-interface/src/repo.ts rename to packages/ipfs-core-types/src/repo.ts diff --git a/packages/ipfs-interface/src/root.ts b/packages/ipfs-core-types/src/root.ts similarity index 100% rename from packages/ipfs-interface/src/root.ts rename to packages/ipfs-core-types/src/root.ts diff --git a/packages/ipfs-interface/src/store.ts b/packages/ipfs-core-types/src/store.ts similarity index 100% rename from packages/ipfs-interface/src/store.ts rename to packages/ipfs-core-types/src/store.ts diff --git a/packages/ipfs-interface/tsconfig.json b/packages/ipfs-core-types/tsconfig.json similarity index 100% rename from packages/ipfs-interface/tsconfig.json rename to packages/ipfs-core-types/tsconfig.json diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index d5d8450806..3c5b1b3fad 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -44,7 +44,7 @@ "cids": "^1.0.0", "err-code": "^2.0.3", "ipfs-utils": "^5.0.0", - "ipfs-interface": "^0.1.0", + "ipfs-core-types": "^0.1.0", "it-all": "^1.0.4", "it-map": "^1.0.4", "it-peekable": "^1.0.1", diff --git a/packages/ipfs-core-utils/src/files/format-mode.js b/packages/ipfs-core-utils/src/files/format-mode.js index 79f739e68a..304ccc3464 100644 --- a/packages/ipfs-core-utils/src/files/format-mode.js +++ b/packages/ipfs-core-utils/src/files/format-mode.js @@ -26,7 +26,7 @@ function checkPermission (mode, perm, type, output) { /** * - * @param {import('ipfs-interface/src/files').Mode} mode + * @param {import('ipfs-core-types/src/files').Mode} mode * @param {boolean} isDirectory * @returns {string} */ diff --git a/packages/ipfs-core-utils/src/files/format-mtime.js b/packages/ipfs-core-utils/src/files/format-mtime.js index 64048792fa..8195600efa 100644 --- a/packages/ipfs-core-utils/src/files/format-mtime.js +++ b/packages/ipfs-core-utils/src/files/format-mtime.js @@ -1,7 +1,7 @@ 'use strict' /** - * @param {import('ipfs-interface/src/files').MTime} mtime + * @param {import('ipfs-core-types/src/files').MTime} mtime * @returns {string} */ function formatMtime (mtime) { diff --git a/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js b/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js index 02dd7f3270..e937dd1fbd 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/index.browser.js @@ -12,7 +12,7 @@ const normaliseInput = require('./normalise-input') * * See https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsadddata-options * - * @param {import('ipfs-interface/src/files').ImportSource} input - * @returns {AsyncIterable>} + * @param {import('ipfs-core-types/src/files').ImportSource} input + * @returns {AsyncIterable>} */ module.exports = (input) => normaliseInput(input, normaliseContent) diff --git a/packages/ipfs-core-utils/src/files/normalise-input/index.js b/packages/ipfs-core-utils/src/files/normalise-input/index.js index 3c70f7394e..3e30de6ce4 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/index.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/index.js @@ -12,7 +12,7 @@ const normaliseInput = require('./normalise-input') * * See https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsadddata-options * - * @param {import('ipfs-interface/src/files').ImportSource} input - * @returns {AsyncIterable>>} + * @param {import('ipfs-core-types/src/files').ImportSource} input + * @returns {AsyncIterable>>} */ module.exports = (input) => normaliseInput(input, normaliseContent) diff --git a/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js b/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js index cf006e76dd..6054808bfb 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js @@ -16,13 +16,13 @@ const { // eslint-disable-next-line complexity /** - * @typedef {import('ipfs-interface/src/files').ToContent} ToContent + * @typedef {import('ipfs-core-types/src/files').ToContent} ToContent */ /** * @template {Blob|AsyncIterable} Content - * @param {import('ipfs-interface/src/files').ImportSource} input + * @param {import('ipfs-core-types/src/files').ImportSource} input * @param {(content:ToContent) => Content|Promise} normaliseContent - * @returns {AsyncIterable>} + * @returns {AsyncIterable>} */ // eslint-disable-next-line complexity module.exports = async function * normaliseInput (input, normaliseContent) { @@ -103,9 +103,9 @@ module.exports = async function * normaliseInput (input, normaliseContent) { /** * @template {Blob|AsyncIterable} Content - * @param {import('ipfs-interface/src/files').ToEntry} input + * @param {import('ipfs-core-types/src/files').ToEntry} input * @param {(content:ToContent) => Content|Promise} normaliseContent - * @returns {Promise>} + * @returns {Promise>} */ async function toFileObject (input, normaliseContent) { // @ts-ignore - Those properties don't exist on most input types diff --git a/packages/ipfs-core-utils/src/files/normalise-input/utils.js b/packages/ipfs-core-utils/src/files/normalise-input/utils.js index 06f26096f9..a7de4b186b 100644 --- a/packages/ipfs-core-utils/src/files/normalise-input/utils.js +++ b/packages/ipfs-core-utils/src/files/normalise-input/utils.js @@ -22,7 +22,7 @@ function isBlob (obj) { * An object with a path or content property * * @param {any} obj - * @returns {obj is import('ipfs-interface/src/files').ToEntry} + * @returns {obj is import('ipfs-core-types/src/files').ToEntry} */ function isFileObject (obj) { return typeof obj === 'object' && (obj.path || obj.content) diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 8dd7e56e42..e1e87a7aa9 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -71,7 +71,7 @@ "ipfs-bitswap": "^4.0.0", "ipfs-block-service": "^0.18.0", "ipfs-core-utils": "^0.5.4", - "ipfs-interface": "^0.1.0", + "ipfs-core-types": "^0.1.0", "ipfs-repo": "^7.0.0", "ipfs-unixfs": "^2.0.3", "ipfs-unixfs-exporter": "^3.0.4", diff --git a/packages/ipfs-core/src/components/add-all/index.js b/packages/ipfs-core/src/components/add-all/index.js index ad9f6a012a..9de540a7d6 100644 --- a/packages/ipfs-core/src/components/add-all/index.js +++ b/packages/ipfs-core/src/components/add-all/index.js @@ -13,7 +13,7 @@ const mergeOptions = require('merge-options').bind({ ignoreUndefined: true }) * @property {import('..').GCLock} gcLock * @property {import('..').Preload} preload * @property {import('..').Pin} pin - * @property {import('ipfs-interface/src/root').ShardingOptions} [options] + * @property {import('ipfs-core-types/src/root').ShardingOptions} [options] * * @param {Context} context */ @@ -23,9 +23,9 @@ module.exports = ({ block, gcLock, preload, pin, options }) => { /** * 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} + * @param {import('ipfs-core-types/src/files').ImportSource} source + * @param {import('ipfs-core-types/src/root').AddAllOptions} [options] + * @returns {AsyncIterable} */ async function * addAll (source, options = {}) { const opts = mergeOptions({ diff --git a/packages/ipfs-core/src/components/add.js b/packages/ipfs-core/src/components/add.js index d9ac014c6c..15fe4ca229 100644 --- a/packages/ipfs-core/src/components/add.js +++ b/packages/ipfs-core/src/components/add.js @@ -12,12 +12,12 @@ module.exports = ({ addAll }) => { /** * 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} + * @param {import('ipfs-core-types/src/files').ToEntry} entry + * @param {import('ipfs-core-types/src/root').AddAllOptions} [options] + * @returns {Promise} */ async function add (entry, options) { - /** @type {import('ipfs-interface/src/files').ImportSource} */ + /** @type {import('ipfs-core-types/src/files').ImportSource} */ const source = (entry) const result = await last(addAll(source, options)) // Note this should never happen as `addAll` should yield at least one item diff --git a/packages/ipfs-core/src/components/cat.js b/packages/ipfs-core/src/components/cat.js index 26aeac3f87..8146ec4119 100644 --- a/packages/ipfs-core/src/components/cat.js +++ b/packages/ipfs-core/src/components/cat.js @@ -15,8 +15,8 @@ module.exports = function ({ ipld, preload }) { /** * 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] + * @param {import('ipfs-core-types/src/root').IPFSPath} ipfsPath + * @param {import('ipfs-core-types/src/root').CatOptions} [options] * @returns {AsyncIterable} */ async function * cat (ipfsPath, options = {}) { diff --git a/packages/ipfs-core/src/components/config.js b/packages/ipfs-core/src/components/config.js index 7eaef35ba0..970c51206d 100644 --- a/packages/ipfs-core/src/components/config.js +++ b/packages/ipfs-core/src/components/config.js @@ -505,6 +505,6 @@ module.exports.profiles = profiles * @typedef {Object} RoutingConfig * @property {string} [Type] * - * @typedef {import('ipfs-interface/src/basic').ToJSON} ToJSON + * @typedef {import('ipfs-core-types/src/basic').ToJSON} ToJSON * @typedef {import('.').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-core/src/components/files/mkdir.js b/packages/ipfs-core/src/components/files/mkdir.js index b44ed06a14..0763dcb8f7 100644 --- a/packages/ipfs-core/src/components/files/mkdir.js +++ b/packages/ipfs-core/src/components/files/mkdir.js @@ -151,8 +151,8 @@ const addEmptyDir = async (context, childName, emptyDir, parent, trail, options) * * @typedef {import('cids')} CID * @typedef {import('cids').CIDVersion} CIDVersion - * @typedef {import('ipfs-interface/src/basic').AbortOptions} AbortOptions - * @typedef {import('ipfs-interface/src/files').MTime} Mtime - * @typedef {import('ipfs-interface/src/files').ToMTime} ToMTime - * @typedef {import('ipfs-interface/src/files').ToMode} ToMode + * @typedef {import('ipfs-core-types/src/basic').AbortOptions} AbortOptions + * @typedef {import('ipfs-core-types/src/files').MTime} Mtime + * @typedef {import('ipfs-core-types/src/files').ToMTime} ToMTime + * @typedef {import('ipfs-core-types/src/files').ToMode} ToMode */ diff --git a/packages/ipfs-core/src/components/files/stat.js b/packages/ipfs-core/src/components/files/stat.js index c35c6eb761..e1a3690f8f 100644 --- a/packages/ipfs-core/src/components/files/stat.js +++ b/packages/ipfs-core/src/components/files/stat.js @@ -180,8 +180,8 @@ const statters = { * @property {number} [sizeLocal] - An integer indicating the cumulative size of * the data present locally. * @property {number} [mode] - File mode - * @property {import('ipfs-interface/src/files').MTime} [mtime] - Modification time + * @property {import('ipfs-core-types/src/files').MTime} [mtime] - Modification time * * @typedef {import('cids')} CID - * @typedef {import('ipfs-interface/src/basic').AbortOptions} AbortOptions + * @typedef {import('ipfs-core-types/src/basic').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-core/src/components/files/touch.js b/packages/ipfs-core/src/components/files/touch.js index 0a4b5769cd..6c6dbc3d7d 100644 --- a/packages/ipfs-core/src/components/files/touch.js +++ b/packages/ipfs-core/src/components/files/touch.js @@ -127,6 +127,6 @@ module.exports = (context) => { * @property {import('cids').CIDVersion} [cidVersion] - The CID version to use for any updated entries * * @typedef {import('cids')} CID - * @typedef {import('ipfs-interface/src/basic').AbortOptions} AbortOptions - * @typedef {import('ipfs-interface/src/files').ToMTime} ToMTime + * @typedef {import('ipfs-core-types/src/basic').AbortOptions} AbortOptions + * @typedef {import('ipfs-core-types/src/files').ToMTime} ToMTime */ diff --git a/packages/ipfs-core/src/components/files/write.js b/packages/ipfs-core/src/components/files/write.js index a8940d93c3..330043ca8a 100644 --- a/packages/ipfs-core/src/components/files/write.js +++ b/packages/ipfs-core/src/components/files/write.js @@ -299,8 +299,8 @@ const countBytesStreamed = async function * (source, notify) { * @property {boolean} [parents=false] - Create intermediate MFS paths if they do not exist * @property {boolean} [truncate=false] - Truncate the file at the MFS path if it would have been larger than the passed content * @property {boolean} [rawLeaves=false] - If true, DAG leaves will contain raw file data and not be wrapped in a protobuf - * @property {import('ipfs-interface/src/files').ToMode} [mode] - An integer that represents the file mode - * @property {import('ipfs-interface/src/files').ToMTime} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime() + * @property {import('ipfs-core-types/src/files').ToMode} [mode] - An integer that represents the file mode + * @property {import('ipfs-core-types/src/files').ToMTime} [mtime] - A Date object, an object with `{ secs, nsecs }` properties where secs is the number of seconds since (positive) or before (negative) the Unix Epoch began and nsecs is the number of nanoseconds since the last full second, or the output of `process.hrtime() * @property {boolean} [flush] - If true the changes will be immediately flushed to disk * @property {string} [hashAlg='sha2-256'] - The hash algorithm to use for any updated entries * @property {0|1} [cidVersion=0] - The CID version to use for any updated entries diff --git a/packages/ipfs-core/src/components/get.js b/packages/ipfs-core/src/components/get.js index 6dd6fdddba..f183dc37a2 100644 --- a/packages/ipfs-core/src/components/get.js +++ b/packages/ipfs-core/src/components/get.js @@ -17,9 +17,9 @@ module.exports = function ({ ipld, preload }) { * 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} + * @param {import('ipfs-core-types/src/root').IPFSPath} ipfsPath + * @param {import('ipfs-core-types/src/root').GetOptions} [options] + * @returns {AsyncIterable} */ async function * get (ipfsPath, options = {}) { if (options.preload !== false) { diff --git a/packages/ipfs-core/src/components/index.js b/packages/ipfs-core/src/components/index.js index 51d76dbce2..1b344e38fc 100644 --- a/packages/ipfs-core/src/components/index.js +++ b/packages/ipfs-core/src/components/index.js @@ -362,8 +362,8 @@ const getDefaultOptions = () => ({ * @typedef {import('peer-id')} PeerId * @typedef {import('./libp2p').LibP2P} LibP2P * @typedef {import('./pin/pin-manager')} PinManager - * @typedef {import('ipfs-interface/src/block-service').BlockService} BlockService - * @typedef {import('ipfs-interface/src/bitswap').Bitswap} BitSwap + * @typedef {import('ipfs-core-types/src/block-service').BlockService} BlockService + * @typedef {import('ipfs-core-types/src/bitswap').Bitswap} BitSwap * @typedef {import('./ipld').IPLD} IPLD * @typedef {import('./gc-lock').GCLock} GCLock * @typedef {import('../preload').Preload} Preload diff --git a/packages/ipfs-core/src/components/ipld.js b/packages/ipfs-core/src/components/ipld.js index 68fdcc0926..a4505424d5 100644 --- a/packages/ipfs-core/src/components/ipld.js +++ b/packages/ipfs-core/src/components/ipld.js @@ -15,9 +15,9 @@ const createIPLD = ({ blockService, print, options }) => module.exports = createIPLD /** - * @typedef {import('ipfs-interface/src/ipld').IPLD} IPLD - * @typedef {import('ipfs-interface/src/ipld').Options} Options - * @typedef {import('ipfs-interface/src/block-service').BlockService} BlockService - * @typedef {import('ipfs-interface/src/block-service').Block} Block + * @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD + * @typedef {import('ipfs-core-types/src/ipld').Options} Options + * @typedef {import('ipfs-core-types/src/block-service').BlockService} BlockService + * @typedef {import('ipfs-core-types/src/block-service').Block} Block * @typedef {import('.').Print} Print */ diff --git a/packages/ipfs-core/src/components/ls.js b/packages/ipfs-core/src/components/ls.js index ff761ac0c4..c97985d9e0 100644 --- a/packages/ipfs-core/src/components/ls.js +++ b/packages/ipfs-core/src/components/ls.js @@ -16,9 +16,9 @@ module.exports = function ({ ipld, preload }) { /** * 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} + * @param {import('ipfs-core-types/src/root').IPFSPath} ipfsPath + * @param {import('ipfs-core-types/src/root').ListOptions} [options] + * @returns {AsyncIterable} */ async function * ls (ipfsPath, options = {}) { const path = normalizeCidPath(ipfsPath) diff --git a/packages/ipfs-core/src/components/network.js b/packages/ipfs-core/src/components/network.js index 745984fcc0..b22855ec6b 100644 --- a/packages/ipfs-core/src/components/network.js +++ b/packages/ipfs-core/src/components/network.js @@ -117,7 +117,7 @@ const WEBSOCKET_STAR_PROTO_CODE = 479 * @typedef {import('.').Repo} Repo * @typedef {import('.').Print} Print * @typedef {import('.').LibP2P} LibP2P - * @typedef {import('ipfs-interface/src/bitswap').Bitswap} BitSwap + * @typedef {import('ipfs-core-types/src/bitswap').Bitswap} BitSwap * @typedef {import('.').PeerId} PeerId * @typedef {import('.').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-core/src/components/root.js b/packages/ipfs-core/src/components/root.js index 2c09b9e82c..9be83d8169 100644 --- a/packages/ipfs-core/src/components/root.js +++ b/packages/ipfs-core/src/components/root.js @@ -12,7 +12,7 @@ const createLsAPI = require('./ls') * @typedef {import('./cat').Context} CatContext * @typedef {import('./get').Context} GetContext * @typedef {import('./ls').Context} ListContext - * @typedef {import('ipfs-interface').RootAPI} RootAPI + * @typedef {import('ipfs-core-types/src').RootAPI} RootAPI * @implements {RootAPI} */ class Root { diff --git a/packages/ipfs-core/src/components/storage.js b/packages/ipfs-core/src/components/storage.js index 3f1f370c3b..4da7483c57 100644 --- a/packages/ipfs-core/src/components/storage.js +++ b/packages/ipfs-core/src/components/storage.js @@ -295,7 +295,7 @@ const applyProfiles = (config, profiles) => { * @typedef {import('.').IPLDOptions} IPLDOptions * @typedef {import('.').Print} Print * @typedef {import('.').IPFSConfig} IPFSConfig - * @typedef {import('ipfs-interface/src/repo').Repo} Repo + * @typedef {import('ipfs-core-types/src/repo').Repo} Repo * @typedef {import('libp2p-crypto').KeyType} KeyType * @typedef {import('libp2p').LibP2PKeychain} Keychain */ diff --git a/packages/ipfs-core/src/runtime/repo-nodejs.js b/packages/ipfs-core/src/runtime/repo-nodejs.js index b10c2af41b..78bae2d565 100644 --- a/packages/ipfs-core/src/runtime/repo-nodejs.js +++ b/packages/ipfs-core/src/runtime/repo-nodejs.js @@ -32,6 +32,6 @@ module.exports = (options = {}) => { } /** - * @typedef {import('ipfs-interface/src/repo').Repo} Repo + * @typedef {import('ipfs-core-types/src/repo').Repo} Repo * @typedef {import('../components/config').IPFSConfig} IPFSConfig */ diff --git a/packages/ipfs-core/src/utils.js b/packages/ipfs-core/src/utils.js index 7b20fe79f1..c32e3abaf0 100644 --- a/packages/ipfs-core/src/utils.js +++ b/packages/ipfs-core/src/utils.js @@ -97,10 +97,10 @@ const resolvePath = async function (dag, ipfsPath, options = {}) { } /** - * @typedef {import('ipfs-interface/src/files').InputFile} InputFile - * @typedef {import('ipfs-interface/src/files').UnixFSFile} UnixFSFile - * @typedef {import('ipfs-interface/src/files').IPFSEntry} IPFSEntry - * @typedef {import('ipfs-interface').AbortOptions} AbortOptions + * @typedef {import('ipfs-core-types/src/files').InputFile} InputFile + * @typedef {import('ipfs-core-types/src/files').UnixFSFile} UnixFSFile + * @typedef {import('ipfs-core-types/src/files').IPFSEntry} IPFSEntry + * @typedef {import('ipfs-core-types/src').AbortOptions} AbortOptions * * @param {InputFile|UnixFSFile} file * @param {Object} [options] diff --git a/packages/ipfs-core/src/utils/service.js b/packages/ipfs-core/src/utils/service.js index a5d118fbfe..33473d9e2e 100644 --- a/packages/ipfs-core/src/utils/service.js +++ b/packages/ipfs-core/src/utils/service.js @@ -212,7 +212,7 @@ module.exports = Service /** * @template T - * @typedef {import('ipfs-interface/src/basic').Await} Await + * @typedef {import('ipfs-core-types/src/basic').Await} Await */ /** * @template {(options:any) => any} T diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index d0d45918c7..e904420be8 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -57,7 +57,7 @@ "form-data": "^3.0.0", "ipfs-core-utils": "^0.5.4", "ipfs-utils": "^5.0.0", - "ipfs-interface": "^0.1.0", + "ipfs-core-types": "^0.1.0", "ipld-block": "^0.11.0", "ipld-dag-cbor": "^0.17.0", "ipld-dag-pb": "^0.20.0", diff --git a/packages/ipfs-http-client/src/add-all.js b/packages/ipfs-http-client/src/add-all.js index d4bd6b3a6f..4689d10915 100644 --- a/packages/ipfs-http-client/src/add-all.js +++ b/packages/ipfs-http-client/src/add-all.js @@ -98,7 +98,7 @@ const createOnUploadPrgress = (size, parts, progress) => { /** * @param {any} input - * @returns {import('ipfs-interface/src/files').UnixFSEntry} + * @returns {import('ipfs-core-types/src/files').UnixFSEntry} */ function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) { const output = { diff --git a/packages/ipfs-message-port-client/package.json b/packages/ipfs-message-port-client/package.json index b794940e7d..99c31e4dcf 100644 --- a/packages/ipfs-message-port-client/package.json +++ b/packages/ipfs-message-port-client/package.json @@ -44,7 +44,7 @@ "dependencies": { "browser-readablestream-to-it": "^1.0.1", "ipfs-message-port-protocol": "^0.4.3", - "ipfs-interface": "^0.1.0" + "ipfs-core-types": "^0.1.0" }, "devDependencies": { "aegir": "^29.2.2", diff --git a/packages/ipfs-message-port-client/src/core.js b/packages/ipfs-message-port-client/src/core.js index deb840973d..352c24d412 100644 --- a/packages/ipfs-message-port-client/src/core.js +++ b/packages/ipfs-message-port-client/src/core.js @@ -161,7 +161,7 @@ class CoreClient extends Client { * Decodes values yield by `ipfs.add`. * * @param {AddedEntry} data - * @returns {import('ipfs-interface/src/files').UnixFSEntry} + * @returns {import('ipfs-core-types/src/files').UnixFSEntry} */ const decodeAddedData = ({ path, cid, mode, mtime, size }) => { return { From ec4b5c8575c7f27cd126843d8e62969697ba90ab Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 17 Dec 2020 08:41:26 -0800 Subject: [PATCH 31/46] chore: disable dep-check --- packages/ipfs-core-types/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ipfs-core-types/package.json b/packages/ipfs-core-types/package.json index 2cdb7f1c05..5330b4b88b 100644 --- a/packages/ipfs-core-types/package.json +++ b/packages/ipfs-core-types/package.json @@ -8,8 +8,7 @@ "bugs": "https://github.com/ipfs/js-ipfs/issues", "scripts": { "lint": "aegir lint", - "test": "aegir ts -p check", - "dep-check": "aegir dep-check" + "test": "aegir ts -p check" }, "types": "src/index.ts", "files": [ From f370ddd9bc9f883f521db71be6dd20a5995915a2 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 17 Dec 2020 10:48:26 -0800 Subject: [PATCH 32/46] chore: ignore ipfs-core-types in dep checks --- packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-core/package.json | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs-message-port-client/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index 3c5b1b3fad..617b0462dc 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -34,7 +34,7 @@ "build:js": "aegir build", "build:types": "tsc --build", "clean": "rimraf ./dist", - "dep-check": "aegir dep-check -i typescript -i rimraf" + "dep-check": "aegir dep-check -i typescript -i rimraf -i ipfs-core-types" }, "license": "MIT", "dependencies": { diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index e1e87a7aa9..02fb7c328b 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -51,7 +51,7 @@ "test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js", "coverage": "nyc --reporter=text --reporter=lcov npm run test:node", "clean": "rimraf ./dist", - "dep-check": "aegir dep-check -i typescript -i interface-ipfs-core" + "dep-check": "aegir dep-check -i typescript -i interface-ipfs-core -i ipfs-core-types" }, "dependencies": { "array-shuffle": "^1.0.1", diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index e904420be8..adb5908a4a 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -47,7 +47,7 @@ "build:types": "tsc --build", "coverage": "npx nyc -r html npm run test:node -- --bail", "clean": "rimraf ./dist", - "dep-check": "aegir dep-check -i typescript -i ipfs-core -i rimraf" + "dep-check": "aegir dep-check -i typescript -i ipfs-core -i rimraf -i ipfs-core-types" }, "dependencies": { "any-signal": "^2.0.0", diff --git a/packages/ipfs-message-port-client/package.json b/packages/ipfs-message-port-client/package.json index 99c31e4dcf..bddeab1230 100644 --- a/packages/ipfs-message-port-client/package.json +++ b/packages/ipfs-message-port-client/package.json @@ -39,7 +39,7 @@ "build:types": "tsc --build", "coverage": "npx nyc -r html npm run test:node -- --bail", "clean": "rimraf ./dist", - "dep-check": "aegir dep-check -i typescript -i ipfs-core -i rimraf" + "dep-check": "aegir dep-check -i typescript -i ipfs-core -i rimraf -i ipfs-core-types" }, "dependencies": { "browser-readablestream-to-it": "^1.0.1", From 54320009db56285e1c72736d3e6f1e33d373d724 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 17 Dec 2020 14:17:23 -0800 Subject: [PATCH 33/46] chore: add more tests --- .../src/pin/remote/index.js | 3 +- .../interface-ipfs-core/src/pin/remote/ls.js | 16 +- .../interface-ipfs-core/src/pin/remote/rm.js | 179 ++++++++++++++++++ 3 files changed, 189 insertions(+), 9 deletions(-) create mode 100644 packages/interface-ipfs-core/src/pin/remote/rm.js diff --git a/packages/interface-ipfs-core/src/pin/remote/index.js b/packages/interface-ipfs-core/src/pin/remote/index.js index 11feed4d6c..01f77d47a6 100644 --- a/packages/interface-ipfs-core/src/pin/remote/index.js +++ b/packages/interface-ipfs-core/src/pin/remote/index.js @@ -4,7 +4,8 @@ const { createSuite } = require('../../utils/suite') const tests = { service: require('./service'), add: require('./add'), - ls: require('./ls') + ls: require('./ls'), + rm: require('./rm') } module.exports = createSuite(tests) diff --git a/packages/interface-ipfs-core/src/pin/remote/ls.js b/packages/interface-ipfs-core/src/pin/remote/ls.js index 6b3524b93a..b3a92f4177 100644 --- a/packages/interface-ipfs-core/src/pin/remote/ls.js +++ b/packages/interface-ipfs-core/src/pin/remote/ls.js @@ -318,7 +318,7 @@ module.exports = (common, options) => { }) describe('list pins by cid', () => { - it('should pins with matching cid', async () => { + it('should list pins with matching cid', async () => { await addRemotePins(ipfs, SERVICE, { a: cid1, b: cid2, @@ -341,7 +341,7 @@ module.exports = (common, options) => { ]) }) - it('should pins with matching cid', async () => { + it('should list pins with any matching cid', async () => { await addRemotePins(ipfs, SERVICE, { a: cid1, b: cid2, @@ -355,7 +355,7 @@ module.exports = (common, options) => { service: SERVICE })) - expect(list).to.deep.equal([ + expect(list.sort(byCID)).to.deep.equal([ { status: 'queued', cid: cid1, @@ -366,10 +366,10 @@ module.exports = (common, options) => { cid: cid3, name: 'c' } - ]) + ].sort(byCID)) }) - it('should pins with matching cid+status', async () => { + it('should list pins with matching cid+status', async () => { await addRemotePins(ipfs, SERVICE, { 'pinned-a': cid1, 'failed-b': cid2, @@ -383,7 +383,7 @@ module.exports = (common, options) => { service: SERVICE })) - expect(list).to.deep.equal([ + expect(list.sort(byCID)).to.deep.equal([ { status: 'pinned', cid: cid1, @@ -394,10 +394,10 @@ module.exports = (common, options) => { cid: cid2, name: 'failed-b' } - ]) + ].sort(byCID)) }) - it('should pins with matching cid+status+name', async () => { + it('should list pins with matching cid+status+name', async () => { await addRemotePins(ipfs, SERVICE, { 'pinned-a': cid1, 'failed-b': cid2, diff --git a/packages/interface-ipfs-core/src/pin/remote/rm.js b/packages/interface-ipfs-core/src/pin/remote/rm.js new file mode 100644 index 0000000000..2cbe876873 --- /dev/null +++ b/packages/interface-ipfs-core/src/pin/remote/rm.js @@ -0,0 +1,179 @@ +/* eslint-env mocha */ +'use strict' + +const { clearRemotePins, addRemotePins, clearServices } = require('../utils') +const { getDescribe, getIt, expect } = require('../../utils/mocha') +const testTimeout = require('../../utils/test-timeout') +const CID = require('cids') +const all = require('it-all') + +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { + const describe = getDescribe(options) + const it = getIt(options) + + const ENDPOINT = new URL(process.env.PINNING_SERVICE_ENDPOINT || '') + const KEY = process.env.PINNING_SERVIEC_KEY + const SERVICE = 'pinbot' + + const cid1 = new CID('QmbKtKBrmeRHjNCwR4zAfCJdMVu6dgmwk9M9AE9pUM9RgG') + const cid2 = new CID('QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w') + const cid3 = new CID('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') + const cid4 = new CID('QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu') + + describe('.pin.remote.rm(All)', function () { + this.timeout(50 * 1000) + + let ipfs + before(async () => { + ipfs = (await common.spawn()).api + await ipfs.pin.remote.service.add(SERVICE, { + endpoint: ENDPOINT, + key: KEY + }) + }) + after(async () => { + await clearServices(ipfs) + await common.clean() + }) + + beforeEach(async () => { + await addRemotePins(ipfs, SERVICE, { + 'queued-a': cid1, + 'pinning-b': cid2, + 'pinned-c': cid3, + 'failed-d': cid4 + }) + }) + afterEach(async () => { + await clearRemotePins(ipfs) + }) + + it('.rm requires service option', async () => { + const result = ipfs.pin.remote.rm({}) + await expect(result).to.eventually.be.rejectedWith(/service name must be passed/) + }) + + it('.rmAll requires service option', async () => { + const result = ipfs.pin.remote.rmAll({}) + await expect(result).to.eventually.be.rejectedWith(/service name must be passed/) + }) + + it('noop if there is no match', async () => { + await ipfs.pin.remote.rm({ + cid: [cid1], + status: ['pinned', 'failed'], + service: SERVICE + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + cid: cid1, + status: 'queued', + name: 'queued-a' + }, + { + cid: cid2, + status: 'pinning', + name: 'pinning-b' + }, + { + cid: cid3, + status: 'pinned', + name: 'pinned-c' + }, + { + cid: cid4, + status: 'failed', + name: 'failed-d' + } + ].sort(byCID)) + }) + + it('removes matching pin', async () => { + await ipfs.pin.remote.rm({ + cid: [cid1], + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + cid: cid2, + status: 'pinning', + name: 'pinning-b' + }, + { + cid: cid3, + status: 'pinned', + name: 'pinned-c' + }, + { + cid: cid4, + status: 'failed', + name: 'failed-d' + } + ].sort(byCID)) + }) + + it('fails on multiple matches', async () => { + const result = ipfs.pin.remote.rm({ + cid: [cid1, cid2], + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + }) + await expect(result).to.eventually.be.rejectedWith(/service name must be passed/) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + cid: cid1, + status: 'queued', + name: 'queued-a' + }, + { + cid: cid2, + status: 'pinning', + name: 'pinning-b' + }, + { + cid: cid3, + status: 'pinned', + name: 'pinned-c' + }, + { + cid: cid4, + status: 'failed', + name: 'failed-d' + } + ].sort(byCID)) + }) + + it('should respect timeout option', () => { + return testTimeout(() => ipfs.pin.remote.rm({ + timeout: 1, + service: SERVICE + })) + }) + }) +} + +const byCID = (a, b) => a.cid.toString() > b.cid.toString() ? 1 : -1 From 2f5e08ca85844c4f76fbc0ec745cf5e5cfbaa0fd Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 17 Dec 2020 14:28:05 -0800 Subject: [PATCH 34/46] chore: migrate types to ipfs-core-types --- packages/interface-ipfs-core/tsconfig.json | 10 ---------- packages/interface-ipfs-core/types/basic.ts | 15 --------------- .../types => ipfs-core-types/src}/pin/remote.ts | 0 .../src}/pin/remote/service.ts | 0 packages/ipfs-http-client/src/pin/remote/index.js | 12 ++++++------ .../ipfs-http-client/src/pin/remote/service.js | 12 ++++++------ packages/ipfs-http-client/tsconfig.json | 3 --- 7 files changed, 12 insertions(+), 40 deletions(-) delete mode 100644 packages/interface-ipfs-core/tsconfig.json delete mode 100644 packages/interface-ipfs-core/types/basic.ts rename packages/{interface-ipfs-core/types => ipfs-core-types/src}/pin/remote.ts (100%) rename packages/{interface-ipfs-core/types => ipfs-core-types/src}/pin/remote/service.ts (100%) diff --git a/packages/interface-ipfs-core/tsconfig.json b/packages/interface-ipfs-core/tsconfig.json deleted file mode 100644 index 34b464add5..0000000000 --- a/packages/interface-ipfs-core/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "dist" - }, - "include": [ - "types", - "package.json", - ] -} diff --git a/packages/interface-ipfs-core/types/basic.ts b/packages/interface-ipfs-core/types/basic.ts deleted file mode 100644 index 5695c90c31..0000000000 --- a/packages/interface-ipfs-core/types/basic.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Common options across all cancellable requests. - */ -export interface AbortOptions { - /** - * Can be provided to a function that starts a long running task, which will - * be aborted when signal is triggered. - */ - signal?: AbortSignal - /** - * Can be provided to a function that starts a long running task, which will - * be aborted after provided timeout (in ms). - */ - timeout?: number -} diff --git a/packages/interface-ipfs-core/types/pin/remote.ts b/packages/ipfs-core-types/src/pin/remote.ts similarity index 100% rename from packages/interface-ipfs-core/types/pin/remote.ts rename to packages/ipfs-core-types/src/pin/remote.ts diff --git a/packages/interface-ipfs-core/types/pin/remote/service.ts b/packages/ipfs-core-types/src/pin/remote/service.ts similarity index 100% rename from packages/interface-ipfs-core/types/pin/remote/service.ts rename to packages/ipfs-core-types/src/pin/remote/service.ts diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js index 41831b9b3c..befcb84c67 100644 --- a/packages/ipfs-http-client/src/pin/remote/index.js +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -8,12 +8,12 @@ const toUrlSearchParams = require('../../lib/to-url-search-params') /** * @typedef {import('../..').HttpOptions} HttpOptions * @typedef {import('../../lib/core').ClientOptions} ClientOptions - * @typedef {import('interface-ipfs-core/types/basic').AbortOptions} AbortOptions - * @typedef {import('interface-ipfs-core/types/pin/remote').API} API - * @typedef {import('interface-ipfs-core/types/pin/remote').Pin} Pin - * @typedef {import('interface-ipfs-core/types/pin/remote').AddOptions} AddOptions - * @typedef {import('interface-ipfs-core/types/pin/remote').Query} Query - * @typedef {import('interface-ipfs-core/types/pin/remote').Status} Status + * @typedef {import('ipfs-core-types/src/basic').AbortOptions} AbortOptions + * @typedef {import('ipfs-core-types/src/pin/remote').API} API + * @typedef {import('ipfs-core-types/src/pin/remote').Pin} Pin + * @typedef {import('ipfs-core-types/src/pin/remote').AddOptions} AddOptions + * @typedef {import('ipfs-core-types/src/pin/remote').Query} Query + * @typedef {import('ipfs-core-types/src/pin/remote').Status} Status * * @implements {API} */ diff --git a/packages/ipfs-http-client/src/pin/remote/service.js b/packages/ipfs-http-client/src/pin/remote/service.js index 91ffa580bb..9a718e8475 100644 --- a/packages/ipfs-http-client/src/pin/remote/service.js +++ b/packages/ipfs-http-client/src/pin/remote/service.js @@ -6,11 +6,11 @@ const toUrlSearchParams = require('../../lib/to-url-search-params') /** * @typedef {import('../../lib/core').ClientOptions} ClientOptions * @typedef {import('../..').HttpOptions} HttpOptions - * @typedef {import('interface-ipfs-core/types/basic').AbortOptions} AbortOptions - * @typedef {import('interface-ipfs-core/types/pin/remote/service').API} API - * @typedef {import('interface-ipfs-core/types/pin/remote/service').Credentials} Credentials - * @typedef {import('interface-ipfs-core/types/pin/remote/service').RemotePinService} RemotePinService - * @typedef {import('interface-ipfs-core/types/pin/remote/service').RemotePinServiceWithStat} RemotePinServiceWithStat + * @typedef {import('ipfs-core-types/src/basic').AbortOptions} AbortOptions + * @typedef {import('ipfs-core-types/src/pin/remote/service').API} API + * @typedef {import('ipfs-core-types/src/pin/remote/service').Credentials} Credentials + * @typedef {import('ipfs-core-types/src/pin/remote/service').RemotePinService} RemotePinService + * @typedef {import('ipfs-core-types/src/pin/remote/service').RemotePinServiceWithStat} RemotePinServiceWithStat * @implements {API} */ class Service { @@ -102,7 +102,7 @@ class Service { /** * @param {Object} json - * @returns {import('interface-ipfs-core/types/pin/remote/service').Stat} + * @returns {import('ipfs-core-types/src/pin/remote/service').Stat} */ static decodeStat (json) { switch (json.Status) { diff --git a/packages/ipfs-http-client/tsconfig.json b/packages/ipfs-http-client/tsconfig.json index 7d1242110c..bbdcd5851e 100644 --- a/packages/ipfs-http-client/tsconfig.json +++ b/packages/ipfs-http-client/tsconfig.json @@ -13,9 +13,6 @@ }, { "path": "../ipfs-core" - }, - { - "path": "../interface-ipfs-core" } ] } From 5dd8dad4471873739d6e209909c067929cfb549e Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 18 Dec 2020 11:32:50 -0800 Subject: [PATCH 35/46] chore: bump ipfs-interop dep --- packages/ipfs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 1c700c0ec0..91656930e0 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -53,7 +53,7 @@ "interface-ipfs-core": "^0.142.3", "ipfs-client": "^0.1.0", "ipfs-http-client": "^48.1.3", - "ipfs-interop": "^3.0.0", + "ipfs-interop": "^4.0.1", "ipfs-utils": "^5.0.0", "ipfsd-ctl": "^7.2.0", "iso-url": "^1.0.0", From 84b853701a869f9145e462a7f3b862fdb41b5470 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 19 Jan 2021 12:52:47 -0800 Subject: [PATCH 36/46] fix: broken test --- packages/interface-ipfs-core/src/pin/remote/rm.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/interface-ipfs-core/src/pin/remote/rm.js b/packages/interface-ipfs-core/src/pin/remote/rm.js index 2cbe876873..8236a11ead 100644 --- a/packages/interface-ipfs-core/src/pin/remote/rm.js +++ b/packages/interface-ipfs-core/src/pin/remote/rm.js @@ -25,7 +25,7 @@ module.exports = (common, options) => { const cid3 = new CID('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') const cid4 = new CID('QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu') - describe('.pin.remote.rm(All)', function () { + describe('.pin.remote.rm()', function () { this.timeout(50 * 1000) let ipfs @@ -136,7 +136,9 @@ module.exports = (common, options) => { status: ['queued', 'pinning', 'pinned', 'failed'], service: SERVICE }) - await expect(result).to.eventually.be.rejectedWith(/service name must be passed/) + await expect(result).to.eventually.be.rejectedWith( + /multiple remote pins are matching this query/ + ); const list = await all(ipfs.pin.remote.ls({ status: ['queued', 'pinning', 'pinned', 'failed'], From 7ae51aaa92f5503069e7ca41f3caf2619a79dea5 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 19 Jan 2021 13:17:21 -0800 Subject: [PATCH 37/46] chore: add pin.remote.rmAll tests --- .../src/pin/remote/index.js | 3 +- .../src/pin/remote/rm-all.js | 164 ++++++++++++++++++ 2 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 packages/interface-ipfs-core/src/pin/remote/rm-all.js diff --git a/packages/interface-ipfs-core/src/pin/remote/index.js b/packages/interface-ipfs-core/src/pin/remote/index.js index 01f77d47a6..81029db664 100644 --- a/packages/interface-ipfs-core/src/pin/remote/index.js +++ b/packages/interface-ipfs-core/src/pin/remote/index.js @@ -5,7 +5,8 @@ const tests = { service: require('./service'), add: require('./add'), ls: require('./ls'), - rm: require('./rm') + rm: require('./rm'), + rmAll: require('./rm-all') } module.exports = createSuite(tests) diff --git a/packages/interface-ipfs-core/src/pin/remote/rm-all.js b/packages/interface-ipfs-core/src/pin/remote/rm-all.js new file mode 100644 index 0000000000..9b80f37921 --- /dev/null +++ b/packages/interface-ipfs-core/src/pin/remote/rm-all.js @@ -0,0 +1,164 @@ +/* eslint-env mocha */ +'use strict' + +const { clearRemotePins, addRemotePins, clearServices } = require('../utils') +const { getDescribe, getIt, expect } = require('../../utils/mocha') +const testTimeout = require('../../utils/test-timeout') +const CID = require('cids') +const all = require('it-all') + +/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ +/** + * @param {Factory} common + * @param {Object} options + */ +module.exports = (common, options) => { + const describe = getDescribe(options) + const it = getIt(options) + + const ENDPOINT = new URL(process.env.PINNING_SERVICE_ENDPOINT || '') + const KEY = process.env.PINNING_SERVIEC_KEY + const SERVICE = 'pinbot' + + const cid1 = new CID('QmbKtKBrmeRHjNCwR4zAfCJdMVu6dgmwk9M9AE9pUM9RgG') + const cid2 = new CID('QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w') + const cid3 = new CID('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') + const cid4 = new CID('QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu') + + describe('.pin.remote.rmAll()', function () { + this.timeout(50 * 1000) + + let ipfs + before(async () => { + ipfs = (await common.spawn()).api + await ipfs.pin.remote.service.add(SERVICE, { + endpoint: ENDPOINT, + key: KEY + }) + }) + after(async () => { + await clearServices(ipfs) + await common.clean() + }) + + beforeEach(async () => { + await addRemotePins(ipfs, SERVICE, { + 'queued-a': cid1, + 'pinning-b': cid2, + 'pinned-c': cid3, + 'failed-d': cid4 + }) + }) + afterEach(async () => { + await clearRemotePins(ipfs) + }) + + it('.rmAll requires service option', async () => { + const result = ipfs.pin.remote.rmAll({}) + await expect(result).to.eventually.be.rejectedWith(/service name must be passed/) + }) + + it('noop if there is no match', async () => { + await ipfs.pin.remote.rmAll({ + cid: [cid1], + status: ['pinned', 'failed'], + service: SERVICE + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + cid: cid1, + status: 'queued', + name: 'queued-a' + }, + { + cid: cid2, + status: 'pinning', + name: 'pinning-b' + }, + { + cid: cid3, + status: 'pinned', + name: 'pinned-c' + }, + { + cid: cid4, + status: 'failed', + name: 'failed-d' + } + ].sort(byCID)) + }) + + it('removes matching pin', async () => { + await ipfs.pin.remote.rmAll({ + cid: [cid1], + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + }) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + cid: cid2, + status: 'pinning', + name: 'pinning-b' + }, + { + cid: cid3, + status: 'pinned', + name: 'pinned-c' + }, + { + cid: cid4, + status: 'failed', + name: 'failed-d' + } + ].sort(byCID)) + }) + + it('removes multiple matches', async () => { + const result = ipfs.pin.remote.rmAll({ + cid: [cid1, cid2], + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + }) + await expect(result).to.eventually.be.equal(undefined) + + const list = await all(ipfs.pin.remote.ls({ + status: ['queued', 'pinning', 'pinned', 'failed'], + service: SERVICE + })) + + expect(list.sort(byCID)).to.deep.equal([ + { + cid: cid3, + status: 'pinned', + name: 'pinned-c' + }, + { + cid: cid4, + status: 'failed', + name: 'failed-d' + } + ].sort(byCID)) + }) + + it('should respect timeout option', () => { + return testTimeout(() => ipfs.pin.remote.rmAll({ + timeout: 1, + service: SERVICE + })) + }) + }) +} + +const byCID = (a, b) => a.cid.toString() > b.cid.toString() ? 1 : -1 From 7433001dfa1609daa9fae1d27032c7af149cae4a Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 19 Jan 2021 13:22:27 -0800 Subject: [PATCH 38/46] fix: lint issue --- packages/interface-ipfs-core/src/pin/remote/rm.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/interface-ipfs-core/src/pin/remote/rm.js b/packages/interface-ipfs-core/src/pin/remote/rm.js index 8236a11ead..4dead16588 100644 --- a/packages/interface-ipfs-core/src/pin/remote/rm.js +++ b/packages/interface-ipfs-core/src/pin/remote/rm.js @@ -136,9 +136,10 @@ module.exports = (common, options) => { status: ['queued', 'pinning', 'pinned', 'failed'], service: SERVICE }) + await expect(result).to.eventually.be.rejectedWith( /multiple remote pins are matching this query/ - ); + ) const list = await all(ipfs.pin.remote.ls({ status: ['queued', 'pinning', 'pinned', 'failed'], From 035b381d3e8a59e49cb47bd0804ead15aea00360 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 19 Jan 2021 22:32:47 -0800 Subject: [PATCH 39/46] fix: node hang --- packages/interface-ipfs-core/src/pin/remote/service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/interface-ipfs-core/src/pin/remote/service.js b/packages/interface-ipfs-core/src/pin/remote/service.js index b88d543de8..b0721950a2 100644 --- a/packages/interface-ipfs-core/src/pin/remote/service.js +++ b/packages/interface-ipfs-core/src/pin/remote/service.js @@ -24,8 +24,8 @@ module.exports = (common, options) => { ipfs = (await common.spawn()).api }) - after(() => { - common.clean() + after(async () => { + await common.clean() }) afterEach(() => clearServices(ipfs)) From 95b2fb8f8bb982911d4bcbfca5d7b6e05d560d76 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 19 Jan 2021 22:33:39 -0800 Subject: [PATCH 40/46] chore: report stop errors --- packages/ipfs/test/utils/mock-pinning-service.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/ipfs/test/utils/mock-pinning-service.js b/packages/ipfs/test/utils/mock-pinning-service.js index a968e0e294..fae4c4f9f3 100644 --- a/packages/ipfs/test/utils/mock-pinning-service.js +++ b/packages/ipfs/test/utils/mock-pinning-service.js @@ -26,7 +26,15 @@ class PinningService { * @returns {Promise} */ static stop (service) { - return new Promise(resolve => service.server.close(resolve)) + return new Promise((resolve, reject) => { + service.server.close((error) => { + if (error) { + reject(error) + } else { + resolve() + } + }) + }) } constructor ({ server, host, port, token }) { From 9d8b44b219d268f420bc2faee96ed1d42bea6ace Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 26 Jan 2021 13:42:46 -0800 Subject: [PATCH 41/46] fix: failing type check Note: filter on Array does refine T type. --- packages/ipfs-grpc-server/src/endpoints/add.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ipfs-grpc-server/src/endpoints/add.js b/packages/ipfs-grpc-server/src/endpoints/add.js index 5f39f01413..c31a8d3b1a 100644 --- a/packages/ipfs-grpc-server/src/endpoints/add.js +++ b/packages/ipfs-grpc-server/src/endpoints/add.js @@ -56,7 +56,6 @@ module.exports = function grpcAdd (ipfs, options = {}) { if (!stream) { // start of new file - // @ts-ignore stream = streams[index] = pushable() fileInputStream.push({ @@ -83,7 +82,7 @@ module.exports = function grpcAdd (ipfs, options = {}) { fileInputStream.end(err) } finally { // clean up any open streams - streams.filter(Boolean).forEach(stream => stream.end()) + streams.forEach(stream => stream && stream.end()) } }, 0) From 4c9494d8b5812586e0ba71bf427ecac1fe685411 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Wed, 27 Jan 2021 11:07:48 -0800 Subject: [PATCH 42/46] chore: update libp2p-crypto --- packages/interface-ipfs-core/package.json | 2 +- packages/ipfs-cli/package.json | 2 +- packages/ipfs-core/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index c5034eee7e..bcb622e919 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -54,7 +54,7 @@ "it-last": "^1.0.4", "it-map": "^1.0.4", "it-pushable": "^1.4.0", - "libp2p-crypto": "^0.18.0", + "libp2p-crypto": "^0.19.0", "libp2p-websockets": "^0.15.0", "multiaddr": "^8.0.0", "multibase": "^3.0.0", diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index b17c75769e..8f4aed67a8 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -51,7 +51,7 @@ "it-glob": "0.0.10", "it-pipe": "^1.1.0", "jsondiffpatch": "^0.4.1", - "libp2p-crypto": "^0.18.0", + "libp2p-crypto": "^0.19.0", "mafmt": "^8.0.0", "multiaddr": "^8.0.0", "multiaddr-to-uri": "^6.0.0", diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index ff494f623e..dea133e6c7 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -91,7 +91,7 @@ "it-pipe": "^1.1.0", "libp2p": "^0.30.0", "libp2p-bootstrap": "^0.12.1", - "libp2p-crypto": "^0.18.0", + "libp2p-crypto": "^0.19.0", "libp2p-floodsub": "^0.24.1", "libp2p-gossipsub": "^0.8.0", "libp2p-kad-dht": "^0.20.1", From 59d4e76a70f8d738511a00080245f73280ab58a1 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 28 Jan 2021 14:52:34 -0800 Subject: [PATCH 43/46] fix: type annotation --- packages/ipfs-core/src/components/libp2p.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs-core/src/components/libp2p.js b/packages/ipfs-core/src/components/libp2p.js index f0437c0945..395e520ecc 100644 --- a/packages/ipfs-core/src/components/libp2p.js +++ b/packages/ipfs-core/src/components/libp2p.js @@ -164,6 +164,6 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p * @typedef {import('.').PeerId} PeerId * @typedef {import('.').Options} IPFSOptions * @typedef {import('libp2p')} LibP2P - * @typedef {import('libp2p').Libp2pOptions} Options + * @typedef {import('libp2p').Libp2pOptions & import('libp2p').constructorOptions} Options * @typedef {import('.').IPFSConfig} IPFSConfig */ From 6bb0591b2aa24e9ea04db1f4aba07d2ed220ca06 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 29 Jan 2021 19:27:30 +0100 Subject: [PATCH 44/46] chore: go-ipfs 0.8.0-rc2 License: MIT Signed-off-by: Marcin Rataj --- packages/ipfs-http-client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index d09f1515f5..b20586ac1e 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -82,7 +82,7 @@ "devDependencies": { "aegir": "^29.2.2", "delay": "^4.4.0", - "go-ipfs": "0.8.0-rc1", + "go-ipfs": "0.8.0-rc2", "ipfs-core": "^0.4.2", "ipfsd-ctl": "^7.2.0", "it-all": "^1.0.4", From 8de937df482e2b7beb16b02146cb54020ca8f2bf Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 29 Jan 2021 10:35:25 -0800 Subject: [PATCH 45/46] chore: update to rc2 --- examples/browser-ipns-publish/package.json | 2 +- examples/http-client-browser-pubsub/package.json | 2 +- examples/http-client-name-api/package.json | 2 +- packages/ipfs-core/package.json | 2 +- packages/ipfs/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/browser-ipns-publish/package.json b/examples/browser-ipns-publish/package.json index 92e55a594a..5964876fca 100644 --- a/examples/browser-ipns-publish/package.json +++ b/examples/browser-ipns-publish/package.json @@ -28,7 +28,7 @@ "delay": "^4.4.0", "execa": "^4.0.3", "ipfsd-ctl": "^7.2.0", - "go-ipfs": "0.8.0-rc1", + "go-ipfs": "0.8.0-rc2", "parcel-bundler": "^1.12.4", "path": "^0.12.7", "test-ipfs-example": "^2.0.3" diff --git a/examples/http-client-browser-pubsub/package.json b/examples/http-client-browser-pubsub/package.json index fc2d3a7322..0c24d53a4b 100644 --- a/examples/http-client-browser-pubsub/package.json +++ b/examples/http-client-browser-pubsub/package.json @@ -19,7 +19,7 @@ ], "devDependencies": { "execa": "^4.0.3", - "go-ipfs": "0.8.0-rc1", + "go-ipfs": "0.8.0-rc2", "ipfs": "^0.53.2", "ipfsd-ctl": "^7.2.0", "parcel-bundler": "^1.12.4", diff --git a/examples/http-client-name-api/package.json b/examples/http-client-name-api/package.json index e0ee8e07bc..6503643c5e 100644 --- a/examples/http-client-name-api/package.json +++ b/examples/http-client-name-api/package.json @@ -17,7 +17,7 @@ }, "devDependencies": { "execa": "^4.0.3", - "go-ipfs": "0.8.0-rc1", + "go-ipfs": "0.8.0-rc2", "ipfsd-ctl": "^7.2.0", "parcel-bundler": "^1.12.4", "rimraf": "^3.0.2", diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 94c343dbd1..72532b5861 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -120,7 +120,7 @@ "devDependencies": { "aegir": "^29.2.2", "delay": "^4.4.0", - "go-ipfs": "0.8.0-rc1", + "go-ipfs": "0.8.0-rc2", "interface-ipfs-core": "^0.143.1", "ipfsd-ctl": "^7.2.0", "ipld-git": "^0.6.1", diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index af80427219..27ba8bbd5c 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -49,7 +49,7 @@ "aegir": "^29.2.2", "cross-env": "^7.0.0", "electron-webrtc": "^0.3.0", - "go-ipfs": "0.8.0-rc1", + "go-ipfs": "0.8.0-rc2", "interface-ipfs-core": "^0.143.1", "ipfs-client": "^0.2.2", "ipfs-http-client": "^48.2.2", From cacf8bdcd1da4d2eb16504e33ff6238321e3821b Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 29 Jan 2021 14:34:39 -0800 Subject: [PATCH 46/46] fix: incompatibilities with go-ipfs@0.8.0-rc2 --- .../ipfs-http-client/src/pin/remote/index.js | 75 ++++++++++++------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/packages/ipfs-http-client/src/pin/remote/index.js b/packages/ipfs-http-client/src/pin/remote/index.js index befcb84c67..0019020f6b 100644 --- a/packages/ipfs-http-client/src/pin/remote/index.js +++ b/packages/ipfs-http-client/src/pin/remote/index.js @@ -45,19 +45,11 @@ class Remote { * @param {AddOptions & AbortOptions & HttpOptions} options */ static async add (client, cid, { timeout, signal, headers, ...options }) { - const { name, origins, background, service } = options - const response = await client.post('pin/remote/add', { timeout, signal, headers, - searchParams: toUrlSearchParams({ - arg: encodeCID(cid), - service: encodeService(service), - name, - origins, - background: background ? true : undefined - }) + searchParams: encodeAddParams({ cid, ...options }) }) return Remote.decodePin(await response.json()) @@ -98,7 +90,7 @@ class Remote { signal, timeout, headers, - searchParams: Remote.encodeQuery(query) + searchParams: encodeQuery(query) }) for await (const pin of response.ndjson()) { @@ -106,20 +98,6 @@ class Remote { } } - /** - * @param {Query & { all?: boolean }} query - * @returns {URLSearchParams} - */ - static encodeQuery ({ service, cid, name, status, all }) { - return toUrlSearchParams({ - service: encodeService(service), - name, - status, - force: all ? true : undefined, - cid: cid && cid.map(encodeCID) - }) - } - /** * Removes a single pin object matching query allowing it to be garbage * collected (if needed). Will error if multiple pins mtach provided @@ -151,7 +129,7 @@ class Remote { timeout, signal, headers, - searchParams: Remote.encodeQuery(query) + searchParams: encodeQuery(query) }) } } @@ -180,4 +158,51 @@ const encodeCID = (cid) => { } } +/** + * @param {Query & { all?: boolean }} query + * @returns {URLSearchParams} + */ +const encodeQuery = ({ service, cid, name, status, all }) => { + const query = toUrlSearchParams({ + service: encodeService(service), + name, + force: all ? true : undefined + }) + + if (cid) { + for (const value of cid) { + query.append('cid', encodeCID(value)) + } + } + + if (status) { + for (const value of status) { + query.append('status', value) + } + } + + return query +} + +/** + * @param {AddOptions & {cid:CID}} options + * @returns {URLSearchParams} + */ +const encodeAddParams = ({ cid, service, background, name, origins }) => { + const params = toUrlSearchParams({ + arg: encodeCID(cid), + service: encodeService(service), + name, + background: background ? true : undefined + }) + + if (origins) { + for (const origin of origins) { + params.append('origin', origin.toString()) + } + } + + return params +} + module.exports = Remote