diff --git a/packages/ipfs-core-types/package.json b/packages/ipfs-core-types/package.json index 931f71a7c7..a131cb475f 100644 --- a/packages/ipfs-core-types/package.json +++ b/packages/ipfs-core-types/package.json @@ -29,7 +29,8 @@ "license": "(Apache-2.0 OR MIT)", "dependencies": { "cids": "^1.1.6", - "ipld": "^0.30.0", + "interface-datastore": "^4.0.0", + "ipld-block": "^0.11.1", "multiaddr": "^9.0.1", "multibase": "^4.0.2" }, diff --git a/packages/ipfs-core-types/src/object/index.d.ts b/packages/ipfs-core-types/src/object/index.d.ts index 2a1206e095..f1864d9b2d 100644 --- a/packages/ipfs-core-types/src/object/index.d.ts +++ b/packages/ipfs-core-types/src/object/index.d.ts @@ -8,8 +8,8 @@ export interface API { put: (obj: DAGNode | DAGNodeLike | Uint8Array, options?: PutOptions & OptionExtension) => Promise get: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise data: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise - links: (cid, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise - stat: (cid, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise + links: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise + stat: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise patch: PatchAPI } diff --git a/packages/ipfs-core-types/src/pin/index.d.ts b/packages/ipfs-core-types/src/pin/index.d.ts index 8072d32371..9a22c8f6a7 100644 --- a/packages/ipfs-core-types/src/pin/index.d.ts +++ b/packages/ipfs-core-types/src/pin/index.d.ts @@ -1,6 +1,6 @@ import type { AbortOptions, AwaitIterable } from '../utils' import type CID from 'cids' -import type { API as remote } from './remote' +import type { API as Remote } from './remote' export interface API { /** @@ -92,7 +92,7 @@ export interface API { */ rmAll: (source: AwaitIterable, options?: AbortOptions & OptionExtension) => AsyncIterable - remote + remote: Remote } export interface AddOptions extends AbortOptions { diff --git a/packages/ipfs-core-types/src/utils.d.ts b/packages/ipfs-core-types/src/utils.d.ts index 1ff3a28fdf..3424cfb307 100644 --- a/packages/ipfs-core-types/src/utils.d.ts +++ b/packages/ipfs-core-types/src/utils.d.ts @@ -1,5 +1,7 @@ import CID from 'cids' import { Mtime, MtimeLike } from 'ipfs-unixfs' +import { Options as DatastoreOptions, Query, KeyQuery } from 'interface-datastore' +import Block from 'ipld-block' export type Entry|Blob> = | FileEntry @@ -131,57 +133,3 @@ export interface BufferStore { get: (key: Uint8Array) => Promise stores: any[] } - -export interface Blockstore { - open: () => Promise - - /** - * Query the store - */ - query: (Query, options?: DatastoreOptions) => AsyncIterable - - /** - * Query the store, returning only keys - */ - queryKeys: (query: KeyQuery, options?: DatastoreOptions) => AsyncIterable - - /** - * Get a single block by CID - */ - get: (cid: CID, options?: DatastoreOptions) => Promise - - /** - * Like get, but for more - */ - getMany: (cids: AwaitIterable, options?: DatastoreOptions) => AsyncIterable - - /** - * Write a single block to the store - */ - put: (block: Block, options?: DatastoreOptions) => Promise - - /** - * Like put, but for more - */ - putMany: (blocks: AwaitIterable, options?: DatastoreOptions) => AsyncIterable - - /** - * Does the store contain block with this CID? - */ - has: (cid: CID, options?: DatastoreOptions) => Promise - - /** - * Delete a block from the store - */ - delete: (cid: CID, options?: DatastoreOptions) => Promise - - /** - * Delete a block from the store - */ - deleteMany: (cids: AwaitIterable, options?: DatastoreOptions) => AsyncIterable - - /** - * Close the store - */ - close: () => Promise -} diff --git a/packages/ipfs-core/src/components/pin/index.js b/packages/ipfs-core/src/components/pin/index.js index 468cab5d48..b78d33f647 100644 --- a/packages/ipfs-core/src/components/pin/index.js +++ b/packages/ipfs-core/src/components/pin/index.js @@ -27,17 +27,16 @@ class PinAPI { this.rm = createRm({ rmAll }) this.ls = createLs({ ipld, pinManager }) - const notImplemented = () => Promise.reject(new Error('Not implemented')) - + /** @type {import('ipfs-core-types/src/pin/remote').API} */ this.remote = { - add: notImplemented, - ls: notImplemented, - rm: notImplemented, - rmAll: notImplemented, + add: (cid, options = {}) => Promise.reject(new Error('Not implemented')), + ls: async function * (query, options = {}) { return Promise.reject(new Error('Not implemented')) }, // eslint-disable-line require-yield + rm: (query, options = {}) => Promise.reject(new Error('Not implemented')), + rmAll: (query, options = {}) => Promise.reject(new Error('Not implemented')), service: { - add: notImplemented, - rm: notImplemented, - ls: notImplemented + add: (name, credentials) => Promise.reject(new Error('Not implemented')), + rm: (name, options = {}) => Promise.reject(new Error('Not implemented')), + ls: (options = {}) => Promise.reject(new Error('Not implemented')) } } } diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index f02c02c9c6..8c0c90e8e5 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -53,7 +53,6 @@ "ipfs-core-utils": "^0.7.2", "ipfs-unixfs": "^4.0.3", "ipfs-utils": "^6.0.4", - "ipld": "^0.30.0", "ipld-block": "^0.11.0", "ipld-dag-cbor": "^1.0.0", "ipld-dag-pb": "^0.22.1", diff --git a/packages/ipfs-http-client/src/lib/ipld-formats.js b/packages/ipfs-http-client/src/lib/ipld-formats.js index ffcb753c18..69d47bae0b 100644 --- a/packages/ipfs-http-client/src/lib/ipld-formats.js +++ b/packages/ipfs-http-client/src/lib/ipld-formats.js @@ -8,7 +8,8 @@ const multicodec = require('multicodec') /** * @typedef {import('cids')} CID * @typedef {import('interface-ipld-format').Format} IPLDFormat - * @typedef {import('ipld').LoadFormatFn} LoadFormatFn + * @typedef {import('multicodec').CodecName} CodecName + * @typedef {import('../types').LoadFormatFn} LoadFormatFn */ /** @@ -23,7 +24,7 @@ const noop = (codec) => { * * @param {object} [options] - IPLD options passed to the http client constructor * @param {IPLDFormat[]} [options.formats] - A list of IPLD Formats to use - * @param {import('ipld').LoadFormatFn} [options.loadFormat] - An async function that can load a format when passed a codec number + * @param {LoadFormatFn} [options.loadFormat] - An async function that can load a format when passed a codec name */ module.exports = ({ formats = [], loadFormat = noop } = {}) => { formats = formats || [] @@ -42,11 +43,10 @@ module.exports = ({ formats = [], loadFormat = noop } = {}) => { /** * Attempts to load an IPLD format for the passed CID * - * @param {import('multicodec').CodecName} codec - The code to load the format for + * @param {CodecName} codec - The code to load the format for */ const loadResolver = async (codec) => { const number = multicodec.getCodeFromName(codec) - // @ts-ignore wat const format = configuredFormats[number] || await loadFormat(codec) if (!format) { diff --git a/packages/ipfs-http-client/src/types.d.ts b/packages/ipfs-http-client/src/types.d.ts index b6d9e45527..582bbfebf3 100644 --- a/packages/ipfs-http-client/src/types.d.ts +++ b/packages/ipfs-http-client/src/types.d.ts @@ -1,9 +1,10 @@ import { Format as IPLDFormat } from 'interface-ipld-format' -import { LoadFormatFn } from 'ipld' import { Agent as HttpAgent } from 'http' import { Agent as HttpsAgent } from 'https' import { Multiaddr } from 'multiaddr' +export type LoadFormatFn = (name: CodecName) => Promise + export interface Options { host?: string port?: number