Skip to content

Add Fetch standard types #420

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 7 commits into from
Apr 10, 2018
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
27 changes: 13 additions & 14 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ interface RegistrationOptions {
}

interface RequestInit {
body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null;
body?: BodyInit | null;
cache?: RequestCache;
credentials?: RequestCredentials;
headers?: HeadersInit;
Expand All @@ -1445,7 +1445,7 @@ interface RequestInit {
redirect?: RequestRedirect;
referrer?: string;
referrerPolicy?: ReferrerPolicy;
signal?: AbortSignal;
signal?: AbortSignal | null;
window?: any;
}

Expand Down Expand Up @@ -2163,6 +2163,7 @@ interface BlobPropertyBag {
}

interface Body {
readonly body: ReadableStream | null;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
Expand Down Expand Up @@ -8327,10 +8328,10 @@ declare var HashChangeEvent: {
interface Headers {
append(name: string, value: string): void;
delete(name: string): void;
forEach(callback: Function, thisArg?: any): 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;
}

declare var Headers: {
Expand Down Expand Up @@ -10801,32 +10802,31 @@ interface Request extends Body {
readonly redirect: RequestRedirect;
readonly referrer: string;
readonly referrerPolicy: ReferrerPolicy;
readonly signal: AbortSignal | null;
readonly type: RequestType;
readonly signal: AbortSignal;
readonly url: string;
clone(): Request;
}

declare var Request: {
prototype: Request;
new(input: Request | string, init?: RequestInit): Request;
new(input: RequestInfo, init?: RequestInit): Request;
};

interface Response extends Body {
readonly body: ReadableStream | null;
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;
}

declare var Response: {
prototype: Response;
new(body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null, init?: ResponseInit): Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
error(): Response;
redirect(url: string, status?: number): Response;
};
Expand Down Expand Up @@ -16160,6 +16160,9 @@ declare function addEventListener<K extends keyof WindowEventMap>(type: K, liste
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
declare function removeEventListener<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
declare function removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
type HeadersInit = Headers | string[][] | Record<string, string>;
type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStream | string;
type RequestInfo = Request | string;
type DOMHighResTimeStamp = number;
type PerformanceEntryList = PerformanceEntry[];
type BufferSource = ArrayBufferView | ArrayBuffer;
Expand All @@ -16170,13 +16173,11 @@ type MouseWheelEvent = WheelEvent;
type ScrollRestoration = "auto" | "manual";
type FormDataEntryValue = string | File;
type InsertPosition = "beforebegin" | "afterbegin" | "beforeend" | "afterend";
type HeadersInit = Headers | string[][] | { [key: string]: string };
type OrientationLockType = "any" | "natural" | "portrait" | "landscape" | "portrait-primary" | "portrait-secondary" | "landscape-primary"| "landscape-secondary";
type IDBValidKey = number | string | Date | IDBArrayKey;
type AlgorithmIdentifier = string | Algorithm;
type MutationRecordType = "attributes" | "characterData" | "childList";
type AAGUID = string;
type BodyInit = any;
type ByteString = string;
type ConstrainBoolean = boolean | ConstrainBooleanParameters;
type ConstrainDOMString = string | string[] | ConstrainDOMStringParameters;
Expand All @@ -16203,7 +16204,6 @@ type MSLocalClientEvent = MSLocalClientEventBase | MSAudioLocalClientEvent;
type MSOutboundPayload = MSVideoSendPayload | MSAudioSendPayload;
type RTCIceGatherCandidate = RTCIceCandidateDictionary | RTCIceCandidateComplete;
type RTCTransport = RTCDtlsTransport | RTCSrtpSdesTransport;
type RequestInfo = Request | string;
type USVString = string;
type payloadtype = number;
type ClientTypes = "window" | "worker" | "sharedworker" | "all";
Expand Down Expand Up @@ -16278,12 +16278,11 @@ type RTCStatsIceCandidateType = "host" | "serverreflexive" | "peerreflexive" | "
type RTCStatsType = "inboundrtp" | "outboundrtp" | "session" | "datachannel" | "track" | "transport" | "candidatepair" | "localcandidate" | "remotecandidate";
type ReadyState = "closed" | "open" | "ended";
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "origin-only" | "origin-when-cross-origin" | "unsafe-url";
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache";
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
type RequestCredentials = "omit" | "same-origin" | "include";
type RequestDestination = "" | "document" | "sharedworker" | "subresource" | "unknown" | "worker";
type RequestDestination = "" | "audio" | "audioworklet" | "document" | "embed" | "font" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt";
type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors";
type RequestRedirect = "follow" | "error" | "manual";
type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video";
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
type ScopedCredentialType = "ScopedCred";
type ServiceWorkerState = "installing" | "installed" | "activating" | "activated" | "redundant";
Expand Down
28 changes: 14 additions & 14 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ interface PushSubscriptionOptionsInit {
}

interface RequestInit {
body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null;
body?: BodyInit | null;
cache?: RequestCache;
credentials?: RequestCredentials;
headers?: HeadersInit;
Expand All @@ -153,7 +153,7 @@ interface RequestInit {
redirect?: RequestRedirect;
referrer?: string;
referrerPolicy?: ReferrerPolicy;
signal?: object;
signal?: object | null;
window?: any;
}

Expand Down Expand Up @@ -218,6 +218,7 @@ interface BlobPropertyBag {
}

interface Body {
readonly body: ReadableStream | null;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
Expand Down Expand Up @@ -661,10 +662,10 @@ interface GlobalFetch {
interface Headers {
append(name: string, value: string): void;
delete(name: string): void;
forEach(callback: Function, thisArg?: any): 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;
}

declare var Headers: {
Expand Down Expand Up @@ -1280,32 +1281,31 @@ interface Request extends Body {
readonly redirect: RequestRedirect;
readonly referrer: string;
readonly referrerPolicy: ReferrerPolicy;
readonly signal: object | null;
readonly type: RequestType;
readonly signal: object;
readonly url: string;
clone(): Request;
}

declare var Request: {
prototype: Request;
new(input: Request | string, init?: RequestInit): Request;
new(input: RequestInfo, init?: RequestInit): Request;
};

interface Response extends Body {
readonly body: ReadableStream | null;
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;
}

declare var Response: {
prototype: Response;
new(body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null, init?: ResponseInit): Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
error(): Response;
redirect(url: string, status?: number): Response;
};
Expand Down Expand Up @@ -1768,12 +1768,14 @@ declare function addEventListener<K extends keyof DedicatedWorkerGlobalScopeEven
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
declare function removeEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
declare function removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
type HeadersInit = Headers | string[][] | Record<string, string>;
type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStream | string;
type RequestInfo = Request | string;
type PerformanceEntryList = PerformanceEntry[];
type BufferSource = ArrayBufferView | ArrayBuffer;
type FormDataEntryValue = string | File;
type HeadersInit = Headers | string[][] | { [key: string]: string };
type AlgorithmIdentifier = string | Algorithm;
type AAGUID = string;
type BodyInit = any;
type ByteString = string;
type CryptoOperationData = ArrayBufferView;
type GLbitfield = number;
Expand All @@ -1791,7 +1793,6 @@ type GLubyte = number;
type GLuint = number;
type GLushort = number;
type IDBKeyPath = string;
type RequestInfo = Request | string;
type USVString = string;
type payloadtype = number;
type ClientTypes = "window" | "worker" | "sharedworker" | "all";
Expand All @@ -1808,12 +1809,11 @@ type NotificationPermission = "default" | "denied" | "granted";
type PushEncryptionKeyName = "p256dh" | "auth";
type PushPermissionState = "granted" | "denied" | "prompt";
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "origin-only" | "origin-when-cross-origin" | "unsafe-url";
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache";
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
type RequestCredentials = "omit" | "same-origin" | "include";
type RequestDestination = "" | "document" | "sharedworker" | "subresource" | "unknown" | "worker";
type RequestDestination = "" | "audio" | "audioworklet" | "document" | "embed" | "font" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt";
type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors";
type RequestRedirect = "follow" | "error" | "manual";
type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video";
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
type ServiceWorkerState = "installing" | "installed" | "activating" | "activated" | "redundant";
type VisibilityState = "hidden" | "visible" | "prerender" | "unloaded";
Expand Down
20 changes: 1 addition & 19 deletions inputfiles/addedTypes.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
{
"mixins": {
"mixin": {
"Body": {
"name": "Body",
"methods": {
"method": {
"formData": {
"name": "formData",
"flavor": "Web",
"override-signatures": [
"formData(): Promise<FormData>"
]
}
}
}
},
"HTMLHyperlinkElementUtils": {
"name": "HTMLHyperlinkElementUtils",
"properties": {
Expand Down Expand Up @@ -2878,7 +2864,7 @@
"new-type": "InsertPosition"
},
{
"override-type": "Headers | string[][] | { [key: string]: string }",
"override-type": "Headers | string[][] | Record<string, string>",
"new-type": "HeadersInit"
},
{
Expand All @@ -2901,10 +2887,6 @@
"new-type": "AAGUID",
"override-type": "string"
},
{
"new-type": "BodyInit",
"override-type": "any"
},
{
"new-type": "ByteString",
"override-type": "string"
Expand Down
96 changes: 96 additions & 0 deletions inputfiles/idl/Fetch.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;

[Constructor(optional HeadersInit init),
Exposed=(Window,Worker)]
interface Headers {
void append(ByteString name, ByteString value);
void delete(ByteString name);
ByteString? get(ByteString name);
boolean has(ByteString name);
void set(ByteString name, ByteString value);
iterable<ByteString, ByteString>;
};
typedef (Blob or BufferSource or FormData or URLSearchParams or ReadableStream or USVString) BodyInit;
interface mixin Body {
readonly attribute ReadableStream? body;
readonly attribute boolean bodyUsed;
[NewObject] Promise<ArrayBuffer> arrayBuffer();
[NewObject] Promise<Blob> blob();
[NewObject] Promise<FormData> formData();
[NewObject] Promise<any> json();
[NewObject] Promise<USVString> text();
};
typedef (Request or USVString) RequestInfo;

[Constructor(RequestInfo input, optional RequestInit init),
Exposed=(Window,Worker)]
interface Request {
readonly attribute ByteString method;
readonly attribute USVString url;
[SameObject] readonly attribute Headers headers;

readonly attribute RequestDestination destination;
readonly attribute USVString referrer;
readonly attribute ReferrerPolicy referrerPolicy;
readonly attribute RequestMode mode;
readonly attribute RequestCredentials credentials;
readonly attribute RequestCache cache;
readonly attribute RequestRedirect redirect;
readonly attribute DOMString integrity;
readonly attribute boolean keepalive;
readonly attribute AbortSignal signal;

[NewObject] Request clone();
};
Request includes Body;

dictionary RequestInit {
ByteString method;
HeadersInit headers;
BodyInit? body;
USVString referrer;
ReferrerPolicy referrerPolicy;
RequestMode mode;
RequestCredentials credentials;
RequestCache cache;
RequestRedirect redirect;
DOMString integrity;
boolean keepalive;
AbortSignal? signal;
any window; // can only be set to null
};

enum RequestDestination { "", "audio", "audioworklet", "document", "embed", "font", "image", "manifest", "object", "paintworklet", "report", "script", "sharedworker", "style", "track", "video", "worker", "xslt" };
enum RequestMode { "navigate", "same-origin", "no-cors", "cors" };
enum RequestCredentials { "omit", "same-origin", "include" };
enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
enum RequestRedirect { "follow", "error", "manual" };
[Constructor(optional BodyInit? body = null, optional ResponseInit init), Exposed=(Window,Worker)]
interface Response {
[NewObject] static Response error();
[NewObject] static Response redirect(USVString url, optional unsigned short status = 302);

readonly attribute ResponseType type;

readonly attribute USVString url;
readonly attribute boolean redirected;
readonly attribute unsigned short status;
readonly attribute boolean ok;
readonly attribute ByteString statusText;
[SameObject] readonly attribute Headers headers;
readonly attribute Promise<Headers> trailer;

[NewObject] Response clone();
};
Response includes Body;

dictionary ResponseInit {
unsigned short status = 200;
ByteString statusText = "OK";
HeadersInit headers;
};

enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" };
partial interface WindowOrWorkerGlobalScope {
[NewObject] Promise<Response> fetch(RequestInfo input, optional RequestInit init);
};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"url": "https://encoding.spec.whatwg.org/",
"title": "Encoding"
},
{
"url": "https://fetch.spec.whatwg.org/",
"title": "Fetch"
},
{
"url": "https://drafts.fxtf.org/geometry/",
"title": "Geometry Interfaces"
Expand Down
3 changes: 2 additions & 1 deletion inputfiles/knownWorkerTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,6 @@
"BlobPropertyBag",
"FilePropertyBag",
"IDBArrayKey",
"IDBVersionChangeEventInit"
"IDBVersionChangeEventInit",
"BufferSource"
]
Loading