Skip to content

fix: remove retyping of modules with types #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 4, 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
14 changes: 2 additions & 12 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { AbortController } = require('native-abort-controller')
const anySignal = require('any-signal')

/**
* @typedef {import('native-fetch').Response} Response
* @typedef {import('./types').ExtendedResponse} ExtendedResponse
* @typedef {import('stream').Readable} NodeReadableStream
* @typedef {import('stream').Duplex} NodeDuplexStream
* @typedef {import('./types').HTTPOptions} HTTPOptions
Expand Down Expand Up @@ -88,7 +88,7 @@ class HTTP {
*
* @param {string | Request} resource
* @param {HTTPOptions} options
* @returns {Promise<Response>}
* @returns {Promise<ExtendedResponse>}
*/
async fetch (resource, options = {}) {
/** @type {HTTPOptions} */
Expand Down Expand Up @@ -168,7 +168,6 @@ class HTTP {
/**
* @param {string | Request} resource
* @param {HTTPOptions} options
* @returns {Promise<Response>}
*/
post (resource, options = {}) {
return this.fetch(resource, { ...options, method: 'POST' })
Expand All @@ -177,7 +176,6 @@ class HTTP {
/**
* @param {string | Request} resource
* @param {HTTPOptions} options
* @returns {Promise<Response>}
*/
get (resource, options = {}) {
return this.fetch(resource, { ...options, method: 'GET' })
Expand All @@ -186,7 +184,6 @@ class HTTP {
/**
* @param {string | Request} resource
* @param {HTTPOptions} options
* @returns {Promise<Response>}
*/
put (resource, options = {}) {
return this.fetch(resource, { ...options, method: 'PUT' })
Expand All @@ -195,7 +192,6 @@ class HTTP {
/**
* @param {string | Request} resource
* @param {HTTPOptions} options
* @returns {Promise<Response>}
*/
delete (resource, options = {}) {
return this.fetch(resource, { ...options, method: 'DELETE' })
Expand All @@ -204,7 +200,6 @@ class HTTP {
/**
* @param {string | Request} resource
* @param {HTTPOptions} options
* @returns {Promise<Response>}
*/
options (resource, options = {}) {
return this.fetch(resource, { ...options, method: 'OPTIONS' })
Expand Down Expand Up @@ -335,35 +330,30 @@ HTTP.streamToAsyncIterator = fromStream
/**
* @param {string | Request} resource
* @param {HTTPOptions} [options]
* @returns {Promise<Response>}
*/
HTTP.post = (resource, options) => new HTTP(options).post(resource, options)

/**
* @param {string | Request} resource
* @param {HTTPOptions} [options]
* @returns {Promise<Response>}
*/
HTTP.get = (resource, options) => new HTTP(options).get(resource, options)

/**
* @param {string | Request} resource
* @param {HTTPOptions} [options]
* @returns {Promise<Response>}
*/
HTTP.put = (resource, options) => new HTTP(options).put(resource, options)

/**
* @param {string | Request} resource
* @param {HTTPOptions} [options]
* @returns {Promise<Response>}
*/
HTTP.delete = (resource, options) => new HTTP(options).delete(resource, options)

/**
* @param {string | Request} resource
* @param {HTTPOptions} [options]
* @returns {Promise<Response>}
*/
HTTP.options = (resource, options) => new HTTP(options).options(resource, options)

Expand Down
2 changes: 1 addition & 1 deletion src/http/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.AbortError = AbortError

class HTTPError extends Error {
/**
* @param {import('native-fetch').Response} response
* @param {Response} response
*/
constructor (response) {
super(response.statusText)
Expand Down
3 changes: 1 addition & 2 deletions src/http/fetch.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,5 @@ class ResponseWithURL extends Response {
module.exports = {
fetch: fetchWith,
Request,
Headers,
ResponseWithURL
Headers
}
1 change: 0 additions & 1 deletion src/http/fetch.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { Request, Response, Headers, default: nativeFetch } = require('../fetch')
const toStream = require('it-to-stream')
const { Buffer } = require('buffer')
/**
* @typedef {import('native-fetch').BodyInit} BodyInit
* @typedef {import('stream').Readable} NodeReadableStream
*
* @typedef {import('../types').FetchOptions} FetchOptions
Expand Down
7 changes: 6 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RequestInit, Response } from '../types/native-fetch'
interface ProgressStatus {
total: number
loaded: number
Expand Down Expand Up @@ -51,3 +50,9 @@ export interface HTTPOptions extends FetchOptions {
*/
handleError?: (rsp: Response) => Promise<void>
}

export interface ExtendedResponse extends Response {
iterator: () => AsyncGenerator<Uint8Array, void, undefined>

ndjson: () => AsyncGenerator<any, void, undefined>
}
117 changes: 0 additions & 117 deletions types/electron-fetch/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion types/iso-url/index.d.ts

This file was deleted.

117 changes: 0 additions & 117 deletions types/native-fetch/index.d.ts

This file was deleted.