2021-01-11 12:13:41 -05:00
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2020-09-18 09:20:55 -04:00
2020-11-03 10:19:29 -05:00
// deno-lint-ignore-file no-explicit-any
2020-09-18 09:20:55 -04:00
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
interface DomIterable < K , V > {
keys ( ) : IterableIterator < K > ;
values ( ) : IterableIterator < V > ;
entries ( ) : IterableIterator < [ K , V ] > ;
[ Symbol . iterator ] ( ) : IterableIterator < [ K , V ] > ;
forEach (
callback : ( value : V , key : K , parent : this ) = > void ,
thisArg? : any ,
) : void ;
}
interface ReadableStreamReadDoneResult < T > {
done : true ;
value? : T ;
}
interface ReadableStreamReadValueResult < T > {
done : false ;
value : T ;
}
type ReadableStreamReadResult < T > =
| ReadableStreamReadValueResult < T >
| ReadableStreamReadDoneResult < T > ;
interface ReadableStreamDefaultReader < R = any > {
readonly closed : Promise < void > ;
cancel ( reason? : any ) : Promise < void > ;
read ( ) : Promise < ReadableStreamReadResult < R > > ;
releaseLock ( ) : void ;
}
interface ReadableStreamReader < R = any > {
cancel ( ) : Promise < void > ;
read ( ) : Promise < ReadableStreamReadResult < R > > ;
releaseLock ( ) : void ;
}
interface ReadableByteStreamControllerCallback {
( controller : ReadableByteStreamController ) : void | PromiseLike < void > ;
}
interface UnderlyingByteSource {
autoAllocateChunkSize? : number ;
cancel? : ReadableStreamErrorCallback ;
pull? : ReadableByteStreamControllerCallback ;
start? : ReadableByteStreamControllerCallback ;
type : "bytes" ;
}
interface UnderlyingSource < R = any > {
cancel? : ReadableStreamErrorCallback ;
pull? : ReadableStreamDefaultControllerCallback < R > ;
start? : ReadableStreamDefaultControllerCallback < R > ;
type ? : undefined ;
}
interface ReadableStreamErrorCallback {
( reason : any ) : void | PromiseLike < void > ;
}
interface ReadableStreamDefaultControllerCallback < R > {
( controller : ReadableStreamDefaultController < R > ) : void | PromiseLike < void > ;
}
interface ReadableStreamDefaultController < R = any > {
readonly desiredSize : number | null ;
close ( ) : void ;
enqueue ( chunk : R ) : void ;
error ( error? : any ) : void ;
}
interface ReadableByteStreamController {
readonly byobRequest : undefined ;
readonly desiredSize : number | null ;
close ( ) : void ;
enqueue ( chunk : ArrayBufferView ) : void ;
error ( error? : any ) : void ;
}
interface PipeOptions {
preventAbort? : boolean ;
preventCancel? : boolean ;
preventClose? : boolean ;
signal? : AbortSignal ;
}
interface QueuingStrategySizeCallback < T = any > {
( chunk : T ) : number ;
}
interface QueuingStrategy < T = any > {
highWaterMark? : number ;
size? : QueuingStrategySizeCallback < T > ;
}
2020-11-03 10:19:29 -05:00
/ * * T h i s S t r e a m s A P I i n t e r f a c e p r o v i d e s a b u i l t - i n b y t e l e n g t h q u e u i n g s t r a t e g y
2020-09-25 10:21:34 -04:00
* that can be used when constructing streams . * /
2020-09-18 09:20:55 -04:00
declare class CountQueuingStrategy implements QueuingStrategy {
constructor ( options : { highWaterMark : number } ) ;
highWaterMark : number ;
size ( chunk : any ) : 1 ;
}
declare class ByteLengthQueuingStrategy
implements QueuingStrategy < ArrayBufferView > {
constructor ( options : { highWaterMark : number } ) ;
highWaterMark : number ;
size ( chunk : ArrayBufferView ) : number ;
}
/ * * T h i s S t r e a m s A P I i n t e r f a c e r e p r e s e n t s a r e a d a b l e s t r e a m o f b y t e d a t a . T h e
2020-09-25 10:21:34 -04:00
* Fetch API offers a concrete instance of a ReadableStream through the body
* property of a Response object . * /
2020-09-18 09:20:55 -04:00
interface ReadableStream < R = any > {
readonly locked : boolean ;
cancel ( reason? : any ) : Promise < void > ;
getIterator ( options ? : { preventCancel? : boolean } ) : AsyncIterableIterator < R > ;
// getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
getReader ( ) : ReadableStreamDefaultReader < R > ;
pipeThrough < T > (
{
writable ,
readable ,
} : {
writable : WritableStream < R > ;
readable : ReadableStream < T > ;
} ,
options? : PipeOptions ,
) : ReadableStream < T > ;
pipeTo ( dest : WritableStream < R > , options? : PipeOptions ) : Promise < void > ;
tee ( ) : [ ReadableStream < R > , ReadableStream < R > ] ;
[ Symbol . asyncIterator ] ( options ? : {
preventCancel? : boolean ;
} ) : AsyncIterableIterator < R > ;
}
2020-09-25 17:23:35 -04:00
declare var ReadableStream : {
2020-09-18 09:20:55 -04:00
prototype : ReadableStream ;
new (
underlyingSource : UnderlyingByteSource ,
strategy ? : { highWaterMark? : number ; size? : undefined } ,
) : ReadableStream < Uint8Array > ;
new < R = any > (
underlyingSource? : UnderlyingSource < R > ,
strategy? : QueuingStrategy < R > ,
) : ReadableStream < R > ;
} ;
interface WritableStreamDefaultControllerCloseCallback {
( ) : void | PromiseLike < void > ;
}
interface WritableStreamDefaultControllerStartCallback {
( controller : WritableStreamDefaultController ) : void | PromiseLike < void > ;
}
interface WritableStreamDefaultControllerWriteCallback < W > {
( chunk : W , controller : WritableStreamDefaultController ) :
| void
| PromiseLike <
void
> ;
}
interface WritableStreamErrorCallback {
( reason : any ) : void | PromiseLike < void > ;
}
interface UnderlyingSink < W = any > {
abort? : WritableStreamErrorCallback ;
close? : WritableStreamDefaultControllerCloseCallback ;
start? : WritableStreamDefaultControllerStartCallback ;
type ? : undefined ;
write? : WritableStreamDefaultControllerWriteCallback < W > ;
}
2020-11-03 10:19:29 -05:00
/ * * T h i s S t r e a m s A P I i n t e r f a c e p r o v i d e s a s t a n d a r d a b s t r a c t i o n f o r w r i t i n g
2020-09-25 10:21:34 -04:00
* streaming data to a destination , known as a sink . This object comes with
* built - in backpressure and queuing . * /
2020-09-18 09:20:55 -04:00
declare class WritableStream < W = any > {
constructor (
underlyingSink? : UnderlyingSink < W > ,
strategy? : QueuingStrategy < W > ,
) ;
readonly locked : boolean ;
abort ( reason? : any ) : Promise < void > ;
close ( ) : Promise < void > ;
getWriter ( ) : WritableStreamDefaultWriter < W > ;
}
/ * * T h i s S t r e a m s A P I i n t e r f a c e r e p r e s e n t s a c o n t r o l l e r a l l o w i n g c o n t r o l o f a
2020-09-25 10:21:34 -04:00
* WritableStream ' s state . When constructing a WritableStream , the underlying
* sink is given a corresponding WritableStreamDefaultController instance to
* manipulate . * /
2020-09-18 09:20:55 -04:00
interface WritableStreamDefaultController {
error ( error? : any ) : void ;
}
/ * * T h i s S t r e a m s A P I i n t e r f a c e i s t h e o b j e c t r e t u r n e d b y
2020-09-25 10:21:34 -04:00
* WritableStream . getWriter ( ) and once created locks the < writer to the
* WritableStream ensuring that no other streams can write to the underlying
* sink . * /
2020-09-18 09:20:55 -04:00
interface WritableStreamDefaultWriter < W = any > {
readonly closed : Promise < void > ;
readonly desiredSize : number | null ;
readonly ready : Promise < void > ;
abort ( reason? : any ) : Promise < void > ;
close ( ) : Promise < void > ;
releaseLock ( ) : void ;
write ( chunk : W ) : Promise < void > ;
}
declare class TransformStream < I = any , O = any > {
constructor (
transformer? : Transformer < I , O > ,
writableStrategy? : QueuingStrategy < I > ,
readableStrategy? : QueuingStrategy < O > ,
) ;
readonly readable : ReadableStream < O > ;
readonly writable : WritableStream < I > ;
}
interface TransformStreamDefaultController < O = any > {
readonly desiredSize : number | null ;
enqueue ( chunk : O ) : void ;
error ( reason? : any ) : void ;
terminate ( ) : void ;
}
interface Transformer < I = any , O = any > {
flush? : TransformStreamDefaultControllerCallback < O > ;
readableType? : undefined ;
start? : TransformStreamDefaultControllerCallback < O > ;
transform? : TransformStreamDefaultControllerTransformCallback < I , O > ;
writableType? : undefined ;
}
interface TransformStreamDefaultControllerCallback < O > {
( controller : TransformStreamDefaultController < O > ) : void | PromiseLike < void > ;
}
interface TransformStreamDefaultControllerTransformCallback < I , O > {
(
chunk : I ,
controller : TransformStreamDefaultController < O > ,
) : void | PromiseLike < void > ;
}
type BlobPart = BufferSource | Blob | string ;
interface BlobPropertyBag {
type ? : string ;
ending ? : "transparent" | "native" ;
}
/** A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system. */
2020-09-25 10:21:34 -04:00
declare class Blob {
constructor ( blobParts? : BlobPart [ ] , options? : BlobPropertyBag ) ;
2020-09-18 09:20:55 -04:00
readonly size : number ;
readonly type : string ;
arrayBuffer ( ) : Promise < ArrayBuffer > ;
slice ( start? : number , end? : number , contentType? : string ) : Blob ;
stream ( ) : ReadableStream ;
text ( ) : Promise < string > ;
}
interface FilePropertyBag extends BlobPropertyBag {
lastModified? : number ;
}
/ * * P r o v i d e s i n f o r m a t i o n a b o u t f i l e s a n d a l l o w s J a v a S c r i p t i n a w e b p a g e t o
2020-09-25 10:21:34 -04:00
* access their content . * /
declare class File extends Blob {
constructor (
fileBits : BlobPart [ ] ,
fileName : string ,
options? : FilePropertyBag ,
) ;
2020-09-18 09:20:55 -04:00
readonly lastModified : number ;
readonly name : string ;
}
type FormDataEntryValue = File | string ;
/ * * P r o v i d e s a w a y t o e a s i l y c o n s t r u c t a s e t o f k e y / v a l u e p a i r s r e p r e s e n t i n g
* form fields and their values , which can then be easily sent using the
* XMLHttpRequest . send ( ) method . It uses the same format a form would use if the
* encoding type were set to "multipart/form-data" . * /
2020-09-25 10:21:34 -04:00
declare class FormData implements DomIterable < string , FormDataEntryValue > {
// TODO(ry) FormData constructor is non-standard.
// new(form?: HTMLFormElement): FormData;
constructor ( ) ;
2020-09-18 09:20:55 -04:00
append ( name : string , value : string | Blob , fileName? : string ) : void ;
delete ( name : string ) : void ;
get ( name : string ) : FormDataEntryValue | null ;
getAll ( name : string ) : FormDataEntryValue [ ] ;
has ( name : string ) : boolean ;
set ( name : string , value : string | Blob , fileName? : string ) : void ;
2020-09-25 10:21:34 -04:00
keys ( ) : IterableIterator < string > ;
values ( ) : IterableIterator < string > ;
entries ( ) : IterableIterator < [ string , FormDataEntryValue ] > ;
[ Symbol . iterator ] ( ) : IterableIterator < [ string , FormDataEntryValue ] > ;
forEach (
callback : ( value : FormDataEntryValue , key : string , parent : this ) = > void ,
thisArg? : any ,
) : void ;
2020-09-18 09:20:55 -04:00
}
interface Body {
/** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body : ReadableStream < Uint8Array > | null ;
/ * * S t o r e s a ` B o o l e a n ` t h a t d e c l a r e s w h e t h e r t h e b o d y h a s b e e n u s e d i n a
* response yet .
* /
readonly bodyUsed : boolean ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with an ` ArrayBuffer ` .
* /
arrayBuffer ( ) : Promise < ArrayBuffer > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` Blob ` .
* /
blob ( ) : Promise < Blob > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` FormData ` object .
* /
formData ( ) : Promise < FormData > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with the result of parsing the body text as JSON .
* /
json ( ) : Promise < any > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` USVString ` ( text ) .
* /
text ( ) : Promise < string > ;
}
type HeadersInit = Headers | string [ ] [ ] | Record < string , string > ;
/ * * T h i s F e t c h A P I i n t e r f a c e a l l o w s y o u t o p e r f o r m v a r i o u s a c t i o n s o n H T T P
* request and response headers . These actions include retrieving , setting ,
* adding to , and removing . A Headers object has an associated header list ,
2020-11-03 10:19:29 -05:00
* which is initially empty and consists of zero or more name and value pairs .
* You can add to this using methods like append ( ) ( see Examples ) . In all
2020-09-18 09:20:55 -04:00
* methods of this interface , header names are matched by case - insensitive byte
* sequence . * /
interface Headers {
append ( name : string , value : string ) : void ;
delete ( name : string ) : void ;
get ( name : string ) : string | null ;
has ( name : string ) : boolean ;
set ( name : string , value : string ) : void ;
forEach (
callbackfn : ( value : string , key : string , parent : Headers ) = > void ,
thisArg? : any ,
) : void ;
}
2020-09-25 10:21:34 -04:00
declare class Headers implements DomIterable < string , string > {
constructor ( init? : HeadersInit ) ;
2020-09-18 09:20:55 -04:00
/ * * A p p e n d s a n e w v a l u e o n t o a n e x i s t i n g h e a d e r i n s i d e a ` H e a d e r s ` o b j e c t , o r
* adds the header if it does not already exist .
* /
append ( name : string , value : string ) : void ;
/** Deletes a header from a `Headers` object. */
delete ( name : string ) : void ;
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l k e y / v a l u e p a i r s
* contained in this Headers object . The both the key and value of each pairs
* are ByteString objects .
* /
entries ( ) : IterableIterator < [ string , string ] > ;
/ * * R e t u r n s a ` B y t e S t r i n g ` s e q u e n c e o f a l l t h e v a l u e s o f a h e a d e r w i t h i n a
* ` Headers ` object with a given name .
* /
get ( name : string ) : string | null ;
/ * * R e t u r n s a b o o l e a n s t a t i n g w h e t h e r a ` H e a d e r s ` o b j e c t c o n t a i n s a c e r t a i n
* header .
* /
has ( name : string ) : boolean ;
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l k e y s c o n t a i n e d i n
* this Headers object . The keys are ByteString objects .
* /
keys ( ) : IterableIterator < string > ;
/ * * S e t s a n e w v a l u e f o r a n e x i s t i n g h e a d e r i n s i d e a H e a d e r s o b j e c t , o r a d d s
* the header if it does not already exist .
* /
set ( name : string , value : string ) : void ;
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l v a l u e s c o n t a i n e d i n
* this Headers object . The values are ByteString objects .
* /
values ( ) : IterableIterator < string > ;
forEach (
callbackfn : ( value : string , key : string , parent : this ) = > void ,
thisArg? : any ,
) : void ;
/ * * T h e S y m b o l . i t e r a t o r w e l l - k n o w n s y m b o l s p e c i f i e s t h e d e f a u l t
* iterator for this Headers object
* /
[ Symbol . iterator ] ( ) : IterableIterator < [ string , string ] > ;
}
type RequestInfo = Request | string ;
type RequestCache =
| "default"
| "force-cache"
| "no-cache"
| "no-store"
| "only-if-cached"
| "reload" ;
type RequestCredentials = "include" | "omit" | "same-origin" ;
type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin" ;
type RequestRedirect = "error" | "follow" | "manual" ;
type ReferrerPolicy =
| ""
| "no-referrer"
| "no-referrer-when-downgrade"
| "origin"
| "origin-when-cross-origin"
| "same-origin"
| "strict-origin"
| "strict-origin-when-cross-origin"
| "unsafe-url" ;
type BodyInit =
| Blob
| BufferSource
| FormData
| URLSearchParams
| ReadableStream < Uint8Array >
| string ;
type RequestDestination =
| ""
| "audio"
| "audioworklet"
| "document"
| "embed"
| "font"
| "image"
| "manifest"
| "object"
| "paintworklet"
| "report"
| "script"
| "sharedworker"
| "style"
| "track"
| "video"
| "worker"
| "xslt" ;
interface RequestInit {
/ * *
* A BodyInit object or null to set request ' s body .
* /
body? : BodyInit | null ;
/ * *
* A string indicating how the request will interact with the browser ' s cache
* to set request ' s cache .
* /
cache? : RequestCache ;
/ * *
* A string indicating whether credentials will be sent with the request
* always , never , or only when sent to a same - origin URL . Sets request ' s
* credentials .
* /
credentials? : RequestCredentials ;
/ * *
* A Headers object , an object literal , or an array of two - item arrays to set
* request ' s headers .
* /
headers? : HeadersInit ;
/ * *
* A cryptographic hash of the resource to be fetched by request . Sets
* request ' s integrity .
* /
integrity? : string ;
/ * *
* A boolean to set request ' s keepalive .
* /
keepalive? : boolean ;
/ * *
* A string to set request ' s method .
* /
method? : string ;
/ * *
* A string to indicate whether the request will use CORS , or will be
* restricted to same - origin URLs . Sets request ' s mode .
* /
mode? : RequestMode ;
/ * *
* A string indicating whether request follows redirects , results in an error
* upon encountering a redirect , or returns the redirect ( in an opaque
* fashion ) . Sets request ' s redirect .
* /
redirect? : RequestRedirect ;
/ * *
* A string whose value is a same - origin URL , "about:client" , or the empty
* string , to set request ' s referrer .
* /
referrer? : string ;
/ * *
* A referrer policy to set request ' s referrerPolicy .
* /
referrerPolicy? : ReferrerPolicy ;
/ * *
* An AbortSignal to set request ' s signal .
* /
signal? : AbortSignal | null ;
/ * *
* Can only be null . Used to disassociate request from any Window .
* /
window ? : any ;
}
/** This Fetch API interface represents a resource request. */
2020-09-25 10:21:34 -04:00
declare class Request implements Body {
constructor ( input : RequestInfo , init? : RequestInit ) ;
2020-09-18 09:20:55 -04:00
/ * *
* Returns the cache mode associated with request , which is a string
* indicating how the request will interact with the browser ' s cache when
* fetching .
* /
readonly cache : RequestCache ;
/ * *
* Returns the credentials mode associated with request , which is a string
* indicating whether credentials will be sent with the request always , never ,
* or only when sent to a same - origin URL .
* /
readonly credentials : RequestCredentials ;
/ * *
* Returns the kind of resource requested by request , e . g . , "document" or "script" .
* /
readonly destination : RequestDestination ;
/ * *
* Returns a Headers object consisting of the headers associated with request .
* Note that headers added in the network layer by the user agent will not be
* accounted for in this object , e . g . , the "Host" header .
* /
readonly headers : Headers ;
/ * *
* Returns request ' s subresource integrity metadata , which is a cryptographic
* hash of the resource being fetched . Its value consists of multiple hashes
* separated by whitespace . [ SRI ]
* /
readonly integrity : string ;
/ * *
* Returns a boolean indicating whether or not request is for a history
* navigation ( a . k . a . back - forward navigation ) .
* /
readonly isHistoryNavigation : boolean ;
/ * *
* Returns a boolean indicating whether or not request is for a reload
* navigation .
* /
readonly isReloadNavigation : boolean ;
/ * *
* Returns a boolean indicating whether or not request can outlive the global
* in which it was created .
* /
readonly keepalive : boolean ;
/ * *
* Returns request ' s HTTP method , which is "GET" by default .
* /
readonly method : string ;
/ * *
* Returns the mode associated with request , which is a string indicating
* whether the request will use CORS , or will be restricted to same - origin
* URLs .
* /
readonly mode : RequestMode ;
/ * *
* Returns the redirect mode associated with request , which is a string
* indicating how redirects for the request will be handled during fetching . A
* request will follow redirects by default .
* /
readonly redirect : RequestRedirect ;
/ * *
* Returns the referrer of request . Its value can be a same - origin URL if
* explicitly set in init , the empty string to indicate no referrer , and
* "about:client" when defaulting to the global ' s default . This is used during
* fetching to determine the value of the ` Referer ` header of the request
* being made .
* /
readonly referrer : string ;
/ * *
* Returns the referrer policy associated with request . This is used during
* fetching to compute the value of the request ' s referrer .
* /
readonly referrerPolicy : ReferrerPolicy ;
/ * *
* Returns the signal associated with request , which is an AbortSignal object
* indicating whether or not request has been aborted , and its abort event
* handler .
* /
readonly signal : AbortSignal ;
/ * *
* Returns the URL of request as a string .
* /
readonly url : string ;
clone ( ) : Request ;
2020-09-25 10:21:34 -04:00
/** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body : ReadableStream < Uint8Array > | null ;
/ * * S t o r e s a ` B o o l e a n ` t h a t d e c l a r e s w h e t h e r t h e b o d y h a s b e e n u s e d i n a
* response yet .
* /
readonly bodyUsed : boolean ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with an ` ArrayBuffer ` .
* /
arrayBuffer ( ) : Promise < ArrayBuffer > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` Blob ` .
* /
blob ( ) : Promise < Blob > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` FormData ` object .
* /
formData ( ) : Promise < FormData > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with the result of parsing the body text as JSON .
* /
json ( ) : Promise < any > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` USVString ` ( text ) .
* /
text ( ) : Promise < string > ;
2020-09-18 09:20:55 -04:00
}
2020-09-25 10:21:34 -04:00
interface ResponseInit {
headers? : HeadersInit ;
status? : number ;
statusText? : string ;
}
2020-09-18 09:20:55 -04:00
2020-09-25 10:21:34 -04:00
type ResponseType =
| "basic"
| "cors"
| "default"
| "error"
| "opaque"
| "opaqueredirect" ;
2020-09-18 09:20:55 -04:00
2020-09-25 10:21:34 -04:00
/** This Fetch API interface represents the response to a request. */
declare class Response implements Body {
constructor ( body? : BodyInit | null , init? : ResponseInit ) ;
static error ( ) : Response ;
static redirect ( url : string , status? : number ) : Response ;
readonly headers : Headers ;
readonly ok : boolean ;
readonly redirected : boolean ;
readonly status : number ;
readonly statusText : string ;
readonly trailer : Promise < Headers > ;
readonly type : ResponseType ;
readonly url : string ;
clone ( ) : Response ;
/** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body : ReadableStream < Uint8Array > | null ;
/ * * S t o r e s a ` B o o l e a n ` t h a t d e c l a r e s w h e t h e r t h e b o d y h a s b e e n u s e d i n a
* response yet .
* /
readonly bodyUsed : boolean ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with an ` ArrayBuffer ` .
* /
arrayBuffer ( ) : Promise < ArrayBuffer > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` Blob ` .
* /
blob ( ) : Promise < Blob > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` FormData ` object .
* /
formData ( ) : Promise < FormData > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with the result of parsing the body text as JSON .
2020-09-18 09:20:55 -04:00
* /
2020-09-25 10:21:34 -04:00
json ( ) : Promise < any > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` USVString ` ( text ) .
* /
text ( ) : Promise < string > ;
}
/ * * F e t c h a r e s o u r c e f r o m t h e n e t w o r k . I t r e t u r n s a P r o m i s e t h a t r e s o l v e s t o t h e
* Response to that request , whether it is successful or not .
*
* const response = await fetch ( "http://my.json.host/data.json" ) ;
* console . log ( response . status ) ; // e.g. 200
* console . log ( response . statusText ) ; // e.g. "OK"
* const jsonData = await response . json ( ) ;
* /
2020-09-18 09:20:55 -04:00
declare function fetch (
input : Request | URL | string ,
init? : RequestInit ,
) : Promise < Response > ;