From cfc17c8e017e4b8f4e19cee09e9ca09541077919 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Sun, 19 May 2019 11:35:05 -0700 Subject: [PATCH] Export constructor options from node/browser files --- src/browser.ts | 8 +++++--- src/common.ts | 6 +++--- src/node.ts | 8 +++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/browser.ts b/src/browser.ts index 46ced3d..bb3b93d 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -5,14 +5,16 @@ import { CommonBody, useRawBody, EmptyBody, - RequestOptions, - ResponseOptions, + CommonRequestOptions, + CommonResponseOptions, CommonResponse, CommonRequest } from "./common"; export type RawBody = ReadableStream | ArrayBuffer | string; export type CreateBody = RawBody | EmptyBody; +export type RequestOptions = CommonRequestOptions; +export type ResponseOptions = CommonResponseOptions; export * from "./headers"; export * from "./signal"; @@ -188,7 +190,7 @@ export class Request extends Body implements CommonRequest { signal: Signal; trailer: Promise; - constructor(input: string | Request, init: RequestOptions = {}) { + constructor(input: string | Request, init: RequestOptions = {}) { // Clone request or use passed options object. const opts = typeof input === "string" ? init : input.clone(); const headers = new Headers(init.headers || opts.headers); diff --git a/src/common.ts b/src/common.ts index 17fe6b2..53b2e36 100644 --- a/src/common.ts +++ b/src/common.ts @@ -19,7 +19,7 @@ export type EmptyBody = null | undefined; /** * Body constructor shape. */ -export type BodyConstructor = { +export type CommonBodyConstructor = { new (body: T | EmptyBody, headers: Headers): CommonBody; }; @@ -40,7 +40,7 @@ export interface CommonBody { /** * Request configuration. */ -export interface RequestOptions { +export interface CommonRequestOptions { method?: string; body?: T; signal?: Signal; @@ -61,7 +61,7 @@ export interface CommonRequest extends CommonBody { /** * Response configuration. */ -export interface ResponseOptions { +export interface CommonResponseOptions { status?: number; statusText?: string; headers?: HeadersInit; diff --git a/src/node.ts b/src/node.ts index 19a48bc..91d084c 100644 --- a/src/node.ts +++ b/src/node.ts @@ -6,13 +6,15 @@ import { CommonBody, useRawBody, EmptyBody, - RequestOptions, - ResponseOptions, + CommonRequestOptions, + CommonResponseOptions, CommonRequest } from "./common"; export type RawBody = Readable | Buffer | string; export type CreateBody = RawBody | ArrayBuffer | EmptyBody; +export type RequestOptions = CommonRequestOptions; +export type ResponseOptions = CommonResponseOptions; export * from "./headers"; export * from "./signal"; @@ -182,7 +184,7 @@ export class Request extends Body implements CommonRequest { signal: Signal; trailer: Promise; - constructor(input: string | Request, init: RequestOptions = {}) { + constructor(input: string | Request, init: RequestOptions = {}) { // Clone request or use passed options object. const opts = typeof input === "string" ? init : input.clone(); const headers = new Headers(init.headers || opts.headers);