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

fix: fix types #3662

Merged
merged 4 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/ipfs-core-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core-types/src/object/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export interface API<OptionExtension = {}> {
put: (obj: DAGNode | DAGNodeLike | Uint8Array, options?: PutOptions & OptionExtension) => Promise<CID>
get: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<DAGNode>
data: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<Uint8Array>
links: (cid, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<DAGLink[]>
stat: (cid, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<StatResult>
links: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<DAGLink[]>
stat: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<StatResult>

patch: PatchAPI
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core-types/src/pin/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<OptionExtension = {}> {
/**
Expand Down Expand Up @@ -92,7 +92,7 @@ export interface API<OptionExtension = {}> {
*/
rmAll: (source: AwaitIterable<RmAllInput>, options?: AbortOptions & OptionExtension) => AsyncIterable<CID>

remote
remote: Remote<OptionExtension>
}

export interface AddOptions extends AbortOptions {
Expand Down
56 changes: 2 additions & 54 deletions packages/ipfs-core-types/src/utils.d.ts
Original file line number Diff line number Diff line change
@@ -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<Content extends AsyncIterable<Uint8Array>|Blob> =
| FileEntry<Content>
Expand Down Expand Up @@ -131,57 +133,3 @@ export interface BufferStore {
get: (key: Uint8Array) => Promise<Uint8Array>
stores: any[]
}

export interface Blockstore {
open: () => Promise<Void>

/**
* Query the store
*/
query: (Query, options?: DatastoreOptions) => AsyncIterable<Block>

/**
* Query the store, returning only keys
*/
queryKeys: (query: KeyQuery, options?: DatastoreOptions) => AsyncIterable<CID>

/**
* Get a single block by CID
*/
get: (cid: CID, options?: DatastoreOptions) => Promise<Block>

/**
* Like get, but for more
*/
getMany: (cids: AwaitIterable<CID>, options?: DatastoreOptions) => AsyncIterable<Block>

/**
* Write a single block to the store
*/
put: (block: Block, options?: DatastoreOptions) => Promise<Block>

/**
* Like put, but for more
*/
putMany: (blocks: AwaitIterable<Block>, options?: DatastoreOptions) => AsyncIterable<Block>

/**
* Does the store contain block with this CID?
*/
has: (cid: CID, options?: DatastoreOptions) => Promise<boolean>

/**
* Delete a block from the store
*/
delete: (cid: CID, options?: DatastoreOptions) => Promise<Void>

/**
* Delete a block from the store
*/
deleteMany: (cids: AwaitIterable<any>, options?: DatastoreOptions) => AsyncIterable<Key>

/**
* Close the store
*/
close: () => Promise<Void>
}
17 changes: 8 additions & 9 deletions packages/ipfs-core/src/components/pin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/ipfs-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/ipfs-http-client/src/lib/ipld-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const multicodec = require('multicodec')
/**
* @typedef {import('cids')} CID
* @typedef {import('interface-ipld-format').Format<any>} IPLDFormat
* @typedef {import('ipld').LoadFormatFn} LoadFormatFn
* @typedef {import('multicodec').CodecName} CodecName
* @typedef {import('../types').LoadFormatFn} LoadFormatFn
*/

/**
Expand All @@ -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 || []
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -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<IPLDFormat>

export interface Options {
host?: string
port?: number
Expand Down