From 69b225c3f7a4c7d5014b1039914cec52d0c7b5e2 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Wed, 23 Oct 2019 14:58:18 -0700 Subject: [PATCH] refactor: remove duplicated type definitions --- src/types.ts | 121 ++++----------------------------------------------- 1 file changed, 9 insertions(+), 112 deletions(-) diff --git a/src/types.ts b/src/types.ts index c21c165dc..16073369c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,11 +1,14 @@ -import { Agent } from "http"; +import { + EndpointOptions, + RequestInterface, + RequestRequestOptions +} from "@octokit/types"; -import { request as Request } from "@octokit/request"; import { Octokit } from "."; export type OctokitOptions = { auth?: string | AutenticationHook; - request?: OctokitRequestOptions; + request?: RequestRequestOptions; timeZone?: string; [option: string]: any; }; @@ -14,115 +17,9 @@ interface AutenticationHook { (options?: any): any; hook: ( - request: typeof Request, - options: Endpoint - ) => ReturnType; + request: RequestInterface, + options: EndpointOptions + ) => ReturnType; } export type Plugin = (octokit: Octokit, options: OctokitOptions) => void; - -// TODO: deduplicate - -/** - * Endpoint parameters - */ -export type Parameters = { - /** - * Base URL to be used when a relative URL is passed, such as `/orgs/:org`. - * If `baseUrl` is `https://enterprise.acme-inc.com/api/v3`, then the request - * will be sent to `https://enterprise.acme-inc.com/api/v3/orgs/:org`. - */ - baseUrl?: string; - - /** - * HTTP headers. Use lowercase keys. - */ - headers?: RequestHeaders; - - /** - * Media type options, see {@link https://developer.github.com/v3/media/|GitHub Developer Guide} - */ - mediaType?: { - /** - * `json` by default. Can be `raw`, `text`, `html`, `full`, `diff`, `patch`, `sha`, `base64`. Depending on endpoint - */ - format?: string; - - /** - * Custom media type names of {@link https://developer.github.com/v3/media/|API Previews} without the `-preview` suffix. - * Example for single preview: `['squirrel-girl']`. - * Example for multiple previews: `['squirrel-girl', 'mister-fantastic']`. - */ - previews?: string[]; - }; - - /** - * Pass custom meta information for the request. The `request` object will be returned as is. - */ - request?: OctokitRequestOptions; - - /** - * Any additional parameter will be passed as follows - * 1. URL parameter if `':parameter'` or `{parameter}` is part of `url` - * 2. Query parameter if `method` is `'GET'` or `'HEAD'` - * 3. Request body if `parameter` is `'data'` - * 4. JSON in the request body in the form of `body[parameter]` unless `parameter` key is `'data'` - */ - [parameter: string]: any; -}; - -/** - * Relative or absolute URL. Examples: `'/orgs/:org'`, `https://example.com/foo/bar` - */ -export type Url = string; - -/** - * Request method - */ -export type Method = "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT"; - -export type Endpoint = Parameters & { - method: Method; - url: Url; -}; - -export type RequestHeaders = { - /** - * Avoid setting `accept`, use `mediaFormat.{format|previews}` instead. - */ - accept?: string; - /** - * Use `authorization` to send authenticated request, remember `token ` / `bearer ` prefixes. Example: `token 1234567890abcdef1234567890abcdef12345678` - */ - authorization?: string; - /** - * `user-agent` is set do a default and can be overwritten as needed. - */ - "user-agent"?: string; - - [header: string]: string | number | undefined; -}; - -export type Fetch = any; -export type Signal = any; - -export type OctokitRequestOptions = { - /** - * Node only. Useful for custom proxy, certificate, or dns lookup. - */ - agent?: Agent; - /** - * Custom replacement for built-in fetch method. Useful for testing or request hooks. - */ - fetch?: Fetch; - /** - * Use an `AbortController` instance to cancel a request. In node you can only cancel streamed requests. - */ - signal?: Signal; - /** - * Node only. Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies). `options.request.signal` is recommended instead. - */ - timeout?: number; - - [option: string]: any; -};