-
Notifications
You must be signed in to change notification settings - Fork 13k
Added the fetch api #12493
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
Added the fetch api #12493
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,13 +137,16 @@ const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) { | |
}); | ||
|
||
const hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"]; | ||
const es2015HostLibrarySources = ["dom.iterable.d.ts", "streams.d.ts", "fetch.d.ts"] | ||
|
||
const librarySourceMap = [ | ||
// Host library | ||
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] }, | ||
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] }, | ||
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] }, | ||
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] }, | ||
{ target: "lib.streams.d.ts", sources: ["header.d.ts", "streams.d.ts"] }, | ||
{ target: "lib.fetch.d.ts", sources: ["header.d.ts", "fetch.d.ts"] }, | ||
|
||
// JavaScript library | ||
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] }, | ||
|
@@ -153,7 +156,7 @@ const librarySourceMap = [ | |
|
||
// JavaScript + all host library | ||
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) }, | ||
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") } | ||
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, es2015HostLibrarySources) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you also need to add entries in commandlineparser.ts for the two new lib targets. |
||
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap); | ||
|
||
const libraryTargets = librarySourceMap.map(function(f) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,13 +312,16 @@ var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) { | |
}); | ||
|
||
var hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"]; | ||
var es2015HostLibrarySources = ["dom.iterable.d.ts", "streams.d.ts", "fetch.d.ts"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
|
||
var librarySourceMap = [ | ||
// Host library | ||
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] }, | ||
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] }, | ||
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] }, | ||
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] }, | ||
{ target: "lib.streams.d.ts", sources: ["header.d.ts", "streams.d.ts"]}, | ||
{ target: "lib.fetch.d.ts", sources: ["header.d.ts", "fetch.d.ts"]}, | ||
|
||
// JavaScript library | ||
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] }, | ||
|
@@ -328,7 +331,7 @@ var librarySourceMap = [ | |
|
||
// JavaScript + all host library | ||
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) }, | ||
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") } | ||
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, es2015HostLibrarySources) } | ||
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap); | ||
|
||
var libraryTargets = librarySourceMap.map(function (f) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/// The fetch API standard can be found at https://fetch.spec.whatwg.org/ | ||
/// Definitions by: Ryan Graham <https://github.com/ryan-codingintrigue>, Kagami Sascha Rosylight <https://github.com/saschanaz>, Robin Van den Broeck <https://github.com/gamesmaxed> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have not included any similar headers in the other lib files. please remove that. |
||
|
||
/// <reference path="lib.streams.d.ts" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also add a reference to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and |
||
|
||
interface Window { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have always been curious why fetch has been under window - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @prabirshrestha also works without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, fetch should be available in non window contexts like Service Workers. |
||
fetch(url: RequestInfo, init?: RequestInit): Promise<Response>; | ||
} | ||
declare var fetch: typeof window.fetch; | ||
|
||
declare type HeadersInit = Headers | string[][] | { [key: string]: string }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I also checked and was slightly disappointed to see it cannot accept arbitrary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For autocomplete maybe we add list of known headers type KnownHeaders = 'Accept' | 'Accept-Charset' //... |
||
declare class Headers { | ||
constructor(init?: HeadersInit); | ||
|
||
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; | ||
|
||
// WebIDL pair iterator: iterable<ByteString, ByteString> | ||
entries(): IterableIterator<[string, string]>; | ||
forEach(callback: (value: string, index: number, headers: Headers) => void, thisArg?: any): void; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<string>; | ||
[Symbol.iterator](): IterableIterator<[string, string]>; | ||
} | ||
|
||
declare type BodyInit = Blob | ArrayBufferView | ArrayBuffer | FormData | URLSearchParams | string; | ||
interface Body { | ||
readonly bodyUsed: boolean; | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
blob(): Promise<Blob>; | ||
formData(): Promise<FormData>; | ||
json(): Promise<any>; | ||
text(): Promise<string>; | ||
} | ||
|
||
declare type RequestInfo = Request | string; | ||
declare class Request { | ||
constructor(input: RequestInfo, init?: RequestInit); | ||
|
||
readonly method: string; | ||
readonly url: string; | ||
readonly headers: Headers; | ||
|
||
readonly type: RequestType | ||
readonly destination: RequestDestination; | ||
readonly referrer: string; | ||
readonly referrerPolicy: ReferrerPolicy; | ||
readonly mode: RequestMode; | ||
readonly credentials: RequestCredentials; | ||
readonly cache: RequestCache; | ||
readonly redirect: RequestRedirect; | ||
readonly integrity: string; | ||
readonly keepalive: boolean; | ||
|
||
clone(): Request; | ||
} | ||
|
||
interface Request extends Body { } | ||
interface RequestInit { | ||
method?: string; | ||
headers?: HeadersInit; | ||
body?: BodyInit; | ||
referrer?: string; | ||
referrerPolicy?: ReferrerPolicy; | ||
mode?: RequestMode; | ||
credentials?: RequestCredentials; | ||
cache?: RequestCache; | ||
redirect?: RequestRedirect; | ||
integrity?: string; | ||
window?: any; | ||
} | ||
|
||
type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video"; | ||
type RequestDestination = "" | "document" | "embed" | "font" | "image" | "manifest" | "media" | "object" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "worker" | "xslt"; | ||
type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors"; | ||
type RequestCredentials = "omit" | "same-origin" | "include"; | ||
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached"; | ||
type RequestRedirect = "follow" | "error" | "manual"; | ||
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url"; | ||
|
||
declare class Response { | ||
constructor(body?: BodyInit, init?: ResponseInit); | ||
|
||
static error(): Response; | ||
static redirect(url: string, status?: number): Response; | ||
|
||
readonly type: ResponseType; | ||
readonly url: string; | ||
readonly redirected: boolean; | ||
readonly status: number; | ||
readonly ok: boolean; | ||
readonly statusText: string; | ||
readonly headers: Headers; | ||
// TODO: Readable stream implementation (I could not find the definitions of this type) | ||
readonly body: ReadableStream | null; | ||
readonly trailer: Promise<Headers>; | ||
|
||
clone(): Response; | ||
} | ||
interface Response extends Body { } | ||
interface ResponseInit { | ||
status?: number; | ||
statusText?: string; | ||
headers?: HeadersInit; | ||
} | ||
|
||
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"; | ||
|
||
declare class URLSearchParams { | ||
constructor(init?: string); | ||
|
||
append(name: string, value: string): void; | ||
delete(name: string): void; | ||
get(name: string): string | void; | ||
getAll(name: string): string[]; | ||
has(name: string): boolean; | ||
set(name: string, value: string): void; | ||
|
||
entries(): IterableIterator<[string, string]>; | ||
forEach(callback: (value: string, index: number, params: URLSearchParams) => void, thisArg?: any): void; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<string>; | ||
[Symbol.iterator](): IterableIterator<[string, string]>; | ||
|
||
// TODO: stringifier | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/// Definitions by: Kagami Sascha Rosylight <https://github.com/saschanaz> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove header. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a reference to |
||
|
||
interface ReadableStreamSource { | ||
start?(controller: ReadableStreamDefaultController): void | Promise<void>; | ||
pull?(controller: ReadableStreamDefaultController): void | Promise<void>; | ||
cancel?(reason: string): void | Promise<void>; | ||
} | ||
|
||
interface ReadableByteStreamSource { | ||
start?(controller: ReadableByteStreamController): void | Promise<void>; | ||
pull?(controller: ReadableByteStreamController): void | Promise<void>; | ||
cancel?(reason: string): void | Promise<void>; | ||
|
||
type: "bytes"; | ||
} | ||
|
||
interface QueuingStrategy { | ||
highWaterMark?: number; | ||
size?(chunk: ArrayBufferView): number; | ||
} | ||
|
||
declare class ReadableStream { | ||
constructor(underlyingSource?: ReadableStreamSource, strategy?: QueuingStrategy); | ||
constructor(underlyingSource?: ReadableByteStreamSource, strategy?: QueuingStrategy); | ||
|
||
locked: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
cancel(reason: string): Promise<void>; | ||
getReader(): ReadableStreamDefaultReader; | ||
getReader({ mode }: { mode: "byob" }): ReadableStreamBYOBReader; | ||
pipeThrough<T extends ReadableStream>({ writable, readable }: { writable: WritableStream, readable: T }): T; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seem from the docs, this should take an additional |
||
pipeTo(dest: WritableStream, { preventClose, preventAbort, preventCancel }: { preventClose?: boolean, preventAbort?: boolean, preventCancel?: boolean }): Promise<void>; | ||
tee(): [ReadableStream, ReadableStream]; | ||
} | ||
|
||
declare class ReadableStreamDefaultReader { | ||
constructor(stream: ReadableStream); | ||
|
||
closed: Promise<void>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
cancel(reason: string): Promise<void>; | ||
read(): Promise<IteratorResult<ArrayBufferView>>; | ||
releaseLock(): void; | ||
} | ||
|
||
declare class ReadableStreamBYOBReader { | ||
constructor(stream: ReadableStream); | ||
|
||
closed: Promise<boolean>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
cancel(reason: string): Promise<void>; | ||
read(view: ArrayBufferView): Promise<IteratorResult<ArrayBufferView>>; | ||
releaseLock(): void; | ||
} | ||
|
||
declare class ReadableStreamDefaultController { | ||
constructor(stream: ReadableStream, underlyingSource: ReadableStreamSource, size: number, highWaterMark: number); | ||
|
||
desiredSize: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
close(): void; | ||
enqueue(chunk: ArrayBufferView): number; | ||
error(e: any): void; | ||
} | ||
|
||
declare class ReadableByteStreamController { | ||
constructor(stream: ReadableStream, underlyingSource: ReadableStreamSource, highWaterMark: number); | ||
|
||
byobRequest: ReadableStreamBYOBRequest; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
desiredSize: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
close(): void; | ||
enqueue(chunk: ArrayBufferView): number; | ||
error(e: any): void; | ||
} | ||
|
||
declare class ReadableStreamBYOBRequest { | ||
constructor(controller: ReadableByteStreamController, view: ArrayBufferView); | ||
|
||
view: ArrayBufferView; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readonly |
||
|
||
respond(bytesWritten: number): void; | ||
respondWithNewView(view: ArrayBufferView): void; | ||
} | ||
|
||
interface WritableStreamSink { | ||
start?(controller: WritableStreamDefaultController): void | Promise<void>; | ||
write?(chunk: any): void | Promise<void>; | ||
close?(): void | Promise<void>; | ||
abort?(reason: string): void | Promise<void>; | ||
} | ||
|
||
declare class WritableStream { | ||
constructor(underlyingSink?: WritableStreamSink, strategy?: QueuingStrategy); | ||
|
||
locked: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readonly |
||
|
||
abort(reason: string): Promise<void>; | ||
getWriter(): WritableStreamDefaultWriter; | ||
} | ||
|
||
declare class WritableStreamDefaultWriter { | ||
constructor(stream: WritableStream); | ||
|
||
closed: Promise<void>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
desiredSize: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ready: Promise<void>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
abort(reason: string): Promise<void>; | ||
close(): Promise<void>; | ||
releaseLock(): void; | ||
write(chunk: any): Promise<void>; | ||
} | ||
|
||
declare class WritableStreamDefaultController { | ||
constructor(stream: WritableStream, underlyingSink: WritableStreamSink, size: number, highWaterMark: number); | ||
|
||
error(e: any): void; | ||
} | ||
|
||
declare class ByteLengthQueuingStrategy { | ||
constructor({ highWaterMark }: { highWaterMark: number }); | ||
|
||
size(chunk: ArrayBufferView): number; | ||
} | ||
|
||
declare class CountQueuingStrategy { | ||
constructor({ highWaterMark }: { highWaterMark: number }); | ||
|
||
size(): number; // 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not think this should be added to the es6 library. it is not related to the ES6 spec, it is an HTML standard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should this be handled?
dom.iterable.d.ts
would still have to depend on iterables, which will depend on ES6Symbol
, which will depend on ES6Object
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file should have /// references on all parts of the es2015 it depends on.