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

Commit

Permalink
fix: declare types in .ts files (#3840)
Browse files Browse the repository at this point in the history
`.d.ts` files are not type checked as they are usually machine generated.

Switch to using `.ts` files instead so we get some compiler safety.

Refs: ipfs/aegir#849
  • Loading branch information
achingbrain authored Aug 27, 2021
1 parent 54b8cc6 commit eba5fe6
Show file tree
Hide file tree
Showing 42 changed files with 108 additions and 84 deletions.
6 changes: 5 additions & 1 deletion packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"ipfs-utils/src/files/glob-source": false
},
"scripts": {
"clean": "rimraf ./dist",
"build": "aegir build",
"lint": "aegir lint",
"test": "echo 'No tests here'",
"dep-check": "aegir dep-check -i abort-controller -i ipfs-core-types"
"dep-check": "aegir dep-check -i abort-controller -i ipfs-core-types -i rimraf"
},
"files": [
"src/",
Expand Down Expand Up @@ -80,6 +81,9 @@
"sinon": "^11.1.1",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"rimraf": "^3.0.2"
},
"contributors": [
"Alan Shaw <alan.shaw@protocol.ai>",
"Alan Shaw <alan@tableflip.io>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IPFS } from 'ipfs-core-types'
import type { IPFS } from 'ipfs-core-types'
import type { Multiaddr } from 'multiaddr'

declare module '@hapi/hapi' {
interface ServerInfo {
Expand Down
21 changes: 18 additions & 3 deletions packages/ipfs-core-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@
"version": "0.7.0",
"description": "IPFS interface definitions used by implementations for API compatibility.",
"leadMaintainer": "Alex Potsides <alex@achingbrain.net>",
"types": "src/index.d.ts",
"types": "dist/src/index.d.ts",
"homepage": "https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-core-types#readme",
"bugs": "https://github.com/ipfs/js-ipfs/issues",
"scripts": {
"clean": "rimraf ./dist",
"lint": "aegir ts -p check && aegir lint",
"test": "aegir ts -p check"
},
"files": [
"src"
"src",
"dist",
"!dist/*.tsbuildinfo"
],
"typesVersions": {
"*": {
"src/*": [
"dist/src/*",
"dist/src/*/index"
],
"src/": [
"dist/src/index"
]
}
},
"eslintConfig": {
"extends": "ipfs"
},
Expand All @@ -33,7 +47,8 @@
"multiformats": "^9.4.1"
},
"devDependencies": {
"aegir": "^35.0.2"
"aegir": "^35.0.2",
"rimraf": "^3.0.2"
},
"contributors": [
"Irakli Gozalishvili <dev@gozala.io>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbortOptions, PreloadOptions } from '../utils'
import { CID, CIDVersion } from 'multiformats/cid'
import type { AbortOptions, PreloadOptions } from '../utils'
import type { CID, CIDVersion } from 'multiformats/cid'

export interface API<OptionExtension = {}> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AbortOptions } from '../utils'
import { API as ProfilesAPI } from './profiles'
import type { API as ProfilesAPI } from './profiles'

export interface API<OptionExtension = {}> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbortOptions, PreloadOptions, IPFSPath } from '../utils'
import { CID, CIDVersion } from 'multiformats/cid'
import type { AbortOptions, PreloadOptions, IPFSPath } from '../utils'
import type { CID, CIDVersion } from 'multiformats/cid'

export interface API<OptionExtension = {}> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbortOptions, IPFSPath } from '../utils'
import { CID, CIDVersion } from 'multiformats/cid'
import { Mtime, MtimeLike } from 'ipfs-unixfs'
import type { AbortOptions, IPFSPath } from '../utils'
import type { CID, CIDVersion } from 'multiformats/cid'
import type { Mtime, MtimeLike } from 'ipfs-unixfs'
import type { AddProgressFn } from '../root'

export interface API<OptionExtension = {}> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { API as RootAPI } from './root'
import { API as BitswapAPI } from './bitswap'
import { API as BlockAPI } from './block'
import { API as BootstrapAPI } from './bootstrap'
import { API as ConfigAPI } from './config'
import { API as DAGAPI } from './dag'
import { API as DHTAPI } from './dht'
import { API as DiagAPI } from './diag'
import { API as FilesAPI } from './files'
import { API as KeyAPI } from './key'
import { API as LogAPI } from './log'
import { API as NameAPI } from './name'
import { API as ObjectAPI } from './object'
import { API as PinAPI } from './pin'
import { API as PubsubAPI } from './pubsub'
import { Refs, Local } from './refs'
import { API as RepoAPI } from './repo'
import { API as StatsAPI } from './stats'
import { API as SwarmAPI } from './swarm'
import { AbortOptions, Await, AwaitIterable } from './utils'
import type { API as RootAPI } from './root'
import type { API as BitswapAPI } from './bitswap'
import type { API as BlockAPI } from './block'
import type { API as BootstrapAPI } from './bootstrap'
import type { API as ConfigAPI } from './config'
import type { API as DAGAPI } from './dag'
import type { API as DHTAPI } from './dht'
import type { API as DiagAPI } from './diag'
import type { API as FilesAPI } from './files'
import type { API as KeyAPI } from './key'
import type { API as LogAPI } from './log'
import type { API as NameAPI } from './name'
import type { API as ObjectAPI } from './object'
import type { API as PinAPI } from './pin'
import type { API as PubsubAPI } from './pubsub'
import type { Refs, Local } from './refs'
import type { API as RepoAPI } from './repo'
import type { API as StatsAPI } from './stats'
import type { API as SwarmAPI } from './swarm'
import type { AbortOptions, Await, AwaitIterable } from './utils'
import type { BlockCodec } from 'multiformats/codecs/interface'
import type { MultibaseCodec } from 'multiformats/bases/interface'
import type { MultihashHasher } from 'multiformats/hashes/interface'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CID } from 'multiformats/cid'
import type { CID } from 'multiformats/cid'
import type { AbortOptions } from '../utils'
import type { API as PubsubAPI } from './pubsub'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CID } from 'multiformats/cid'
import { Multiaddr } from 'multiaddr'
import { API as Service } from './service'
import { AbortOptions } from '../../utils'
import type { CID } from 'multiformats/cid'
import type { Multiaddr } from 'multiaddr'
import type { API as Service } from './service'
import type { AbortOptions } from '../../utils'

export interface API<OptionExtension = {}> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbortOptions } from '../../../utils'
import type { AbortOptions } from '../../../utils'

export interface API<OptionExtension = {}> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AbortOptions } from '../utils'
import { CID } from 'multiformats/cid'
import type { CID } from 'multiformats/cid'

export interface API<OptionExtension = {}> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbortOptions, PreloadOptions, IPFSPath, ImportCandidateStream, ImportCandidate } from './utils'
import { CID, CIDVersion } from 'multiformats/cid'
import { Mtime } from 'ipfs-unixfs'
import { Multiaddr } from 'multiaddr'
import type { AbortOptions, PreloadOptions, IPFSPath, ImportCandidateStream, ImportCandidate } from './utils'
import type { CID, CIDVersion } from 'multiformats/cid'
import type { Mtime } from 'ipfs-unixfs'
import type { Multiaddr } from 'multiaddr'

export interface API<OptionExtension = {}> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AbortOptions } from '../utils'
import { API as BitswapAPI } from '../bitswap'
import { API as RepoAPI } from '../repo'
import type { API as BitswapAPI } from '../bitswap'
import type { API as RepoAPI } from '../repo'

export interface API<OptionExtension = {}> {
bitswap: BitswapAPI<OptionExtension>['stat']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CID } from 'multiformats/cid'
import { Mtime, MtimeLike } from 'ipfs-unixfs'
import type { CID } from 'multiformats/cid'
import type { Mtime, MtimeLike } from 'ipfs-unixfs'

export type Entry<Content extends AsyncIterable<Uint8Array>|Blob> =
| FileEntry<Content>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MultibaseCodec } from 'multiformats/bases/interface'
import { BlockCodec } from 'multiformats/codecs/interface'
import { MultihashHasher } from 'multiformats/hashes/interface'
import type { MultibaseCodec } from 'multiformats/bases/interface'
import type { BlockCodec } from 'multiformats/codecs/interface'
import type { MultihashHasher } from 'multiformats/hashes/interface'

export interface LoadBaseFn { (codeOrName: string): Promise<MultibaseCodec<any>> }
export interface LoadCodecFn { (codeOrName: number | string): Promise<BlockCodec<any, any>> }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { KeyType } from 'libp2p-crypto'
import type PeerId from 'peer-id'
import type { Config as IPFSConfig } from 'ipfs-core-types/src/config'
import type Libp2p, { Libp2pOptions } from 'libp2p'
import type Libp2p from 'libp2p'
import type { Libp2pOptions } from 'libp2p'

import type { IPFSRepo } from 'ipfs-repo'
import type { ProgressCallback as MigrationProgressCallback } from 'ipfs-repo-migrations'
import type Network, { Options as NetworkOptions } from './components/network'
import type Network from './components/network'
import type { Options as NetworkOptions } from './components/network'

import type { Datastore } from 'interface-datastore'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { agent as HttpAgent } from 'http'
import { agent as HttpsAgent } from 'https'
import { Multiaddr } from 'multiaddr'
import type { Agent as HttpAgent } from 'http'
import type { Agent as HttpsAgent } from 'https'
import type { Multiaddr } from 'multiaddr'

export interface Options {
url: string | URL | Multiaddr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Pushable } from 'it-pushable'
import { EventEmitter } from 'events'
import { Multiaddr } from 'multiaddr'
import type { Pushable } from 'it-pushable'
import type { EventEmitter } from 'events'
import type { Multiaddr } from 'multiaddr'

export interface Options {
socket?: WebsocketServer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Agent as HttpAgent } from 'http'
import { Agent as HttpsAgent } from 'https'
import { Multiaddr } from 'multiaddr'
import type { Agent as HttpAgent } from 'http'
import type { Agent as HttpsAgent } from 'https'
import type { Multiaddr } from 'multiaddr'
import type { BlockCodec } from 'multiformats/codecs/interface'
import type { MultihashHasher } from 'multiformats/hashes/interface'
import type { MultibaseCodec } from 'multiformats/bases/interface'
Expand Down
14 changes: 0 additions & 14 deletions packages/ipfs-http-gateway/src/types.d.ts

This file was deleted.

14 changes: 14 additions & 0 deletions packages/ipfs-http-gateway/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { IPFS } from 'ipfs-core-types'
import type { Request, Server } from '@hapi/hapi'
import type { Multiaddr } from 'multiaddr'

declare module '@hapi/hapi' {
interface ServerApplicationState {
ipfs: IPFS
}
interface ServerInfo {
ma: Multiaddr
}
}

export type { Request, Server }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IPFS } from 'ipfs-core-types'
import { Request, Server } from '@hapi/hapi'
import Multiaddr from 'multiaddrs'
import { Mtime } from 'ipfs-unixfs'
import type { IPFS } from 'ipfs-core-types'
import type { Request, Server } from '@hapi/hapi'
import type { Multiaddr } from 'multiaddr'
import type { Mtime } from 'ipfs-unixfs'

declare module '@hapi/hapi' {
interface ServerApplicationState {
Expand All @@ -15,7 +15,7 @@ declare module '@hapi/hapi' {
}
}

export { Request, Server }
export type { Request, Server }

interface MultipartUpload {
name: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mtime } from 'ipfs-unixfs'
import { EncodedCID } from './cid'
import type { Mtime } from 'ipfs-unixfs'
import type { EncodedCID } from './cid'

export interface EncodedStat {
cid: EncodedCID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Mtime } from 'ipfs-unixfs'
import type { RemoteIterable } from './core'
import type { FileType } from './data'
import type { EncodedCID } from './cid'

export type FileType = 'dir' | 'file'

export type EncodedFileContent = ArrayBufferView | ArrayBuffer | Blob | string | RemoteIterable<ArrayBufferView> | RemoteIterable<ArrayBuffer>

Expand Down

0 comments on commit eba5fe6

Please sign in to comment.