Skip to content

Commit 7749aee

Browse files
authored
Merge pull request #420 from saschanaz/fetch
Add Fetch standard types
2 parents cfa8a81 + 44ccb0a commit 7749aee

File tree

11 files changed

+199
-57
lines changed

11 files changed

+199
-57
lines changed

baselines/dom.generated.d.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ interface RegistrationOptions {
14341434
}
14351435

14361436
interface RequestInit {
1437-
body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null;
1437+
body?: BodyInit | null;
14381438
cache?: RequestCache;
14391439
credentials?: RequestCredentials;
14401440
headers?: HeadersInit;
@@ -1445,7 +1445,7 @@ interface RequestInit {
14451445
redirect?: RequestRedirect;
14461446
referrer?: string;
14471447
referrerPolicy?: ReferrerPolicy;
1448-
signal?: AbortSignal;
1448+
signal?: AbortSignal | null;
14491449
window?: any;
14501450
}
14511451

@@ -2163,6 +2163,7 @@ interface BlobPropertyBag {
21632163
}
21642164

21652165
interface Body {
2166+
readonly body: ReadableStream | null;
21662167
readonly bodyUsed: boolean;
21672168
arrayBuffer(): Promise<ArrayBuffer>;
21682169
blob(): Promise<Blob>;
@@ -8327,10 +8328,10 @@ declare var HashChangeEvent: {
83278328
interface Headers {
83288329
append(name: string, value: string): void;
83298330
delete(name: string): void;
8330-
forEach(callback: Function, thisArg?: any): void;
83318331
get(name: string): string | null;
83328332
has(name: string): boolean;
83338333
set(name: string, value: string): void;
8334+
forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void;
83348335
}
83358336

83368337
declare var Headers: {
@@ -10801,32 +10802,31 @@ interface Request extends Body {
1080110802
readonly redirect: RequestRedirect;
1080210803
readonly referrer: string;
1080310804
readonly referrerPolicy: ReferrerPolicy;
10804-
readonly signal: AbortSignal | null;
10805-
readonly type: RequestType;
10805+
readonly signal: AbortSignal;
1080610806
readonly url: string;
1080710807
clone(): Request;
1080810808
}
1080910809

1081010810
declare var Request: {
1081110811
prototype: Request;
10812-
new(input: Request | string, init?: RequestInit): Request;
10812+
new(input: RequestInfo, init?: RequestInit): Request;
1081310813
};
1081410814

1081510815
interface Response extends Body {
10816-
readonly body: ReadableStream | null;
1081710816
readonly headers: Headers;
1081810817
readonly ok: boolean;
1081910818
readonly redirected: boolean;
1082010819
readonly status: number;
1082110820
readonly statusText: string;
10821+
readonly trailer: Promise<Headers>;
1082210822
readonly type: ResponseType;
1082310823
readonly url: string;
1082410824
clone(): Response;
1082510825
}
1082610826

1082710827
declare var Response: {
1082810828
prototype: Response;
10829-
new(body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null, init?: ResponseInit): Response;
10829+
new(body?: BodyInit | null, init?: ResponseInit): Response;
1083010830
error(): Response;
1083110831
redirect(url: string, status?: number): Response;
1083210832
};
@@ -16160,6 +16160,9 @@ declare function addEventListener<K extends keyof WindowEventMap>(type: K, liste
1616016160
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
1616116161
declare function removeEventListener<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
1616216162
declare function removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
16163+
type HeadersInit = Headers | string[][] | Record<string, string>;
16164+
type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStream | string;
16165+
type RequestInfo = Request | string;
1616316166
type DOMHighResTimeStamp = number;
1616416167
type PerformanceEntryList = PerformanceEntry[];
1616516168
type BufferSource = ArrayBufferView | ArrayBuffer;
@@ -16170,13 +16173,11 @@ type MouseWheelEvent = WheelEvent;
1617016173
type ScrollRestoration = "auto" | "manual";
1617116174
type FormDataEntryValue = string | File;
1617216175
type InsertPosition = "beforebegin" | "afterbegin" | "beforeend" | "afterend";
16173-
type HeadersInit = Headers | string[][] | { [key: string]: string };
1617416176
type OrientationLockType = "any" | "natural" | "portrait" | "landscape" | "portrait-primary" | "portrait-secondary" | "landscape-primary"| "landscape-secondary";
1617516177
type IDBValidKey = number | string | Date | IDBArrayKey;
1617616178
type AlgorithmIdentifier = string | Algorithm;
1617716179
type MutationRecordType = "attributes" | "characterData" | "childList";
1617816180
type AAGUID = string;
16179-
type BodyInit = any;
1618016181
type ByteString = string;
1618116182
type ConstrainBoolean = boolean | ConstrainBooleanParameters;
1618216183
type ConstrainDOMString = string | string[] | ConstrainDOMStringParameters;
@@ -16203,7 +16204,6 @@ type MSLocalClientEvent = MSLocalClientEventBase | MSAudioLocalClientEvent;
1620316204
type MSOutboundPayload = MSVideoSendPayload | MSAudioSendPayload;
1620416205
type RTCIceGatherCandidate = RTCIceCandidateDictionary | RTCIceCandidateComplete;
1620516206
type RTCTransport = RTCDtlsTransport | RTCSrtpSdesTransport;
16206-
type RequestInfo = Request | string;
1620716207
type USVString = string;
1620816208
type payloadtype = number;
1620916209
type ClientTypes = "window" | "worker" | "sharedworker" | "all";
@@ -16278,12 +16278,11 @@ type RTCStatsIceCandidateType = "host" | "serverreflexive" | "peerreflexive" | "
1627816278
type RTCStatsType = "inboundrtp" | "outboundrtp" | "session" | "datachannel" | "track" | "transport" | "candidatepair" | "localcandidate" | "remotecandidate";
1627916279
type ReadyState = "closed" | "open" | "ended";
1628016280
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "origin-only" | "origin-when-cross-origin" | "unsafe-url";
16281-
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache";
16281+
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
1628216282
type RequestCredentials = "omit" | "same-origin" | "include";
16283-
type RequestDestination = "" | "document" | "sharedworker" | "subresource" | "unknown" | "worker";
16283+
type RequestDestination = "" | "audio" | "audioworklet" | "document" | "embed" | "font" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt";
1628416284
type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors";
1628516285
type RequestRedirect = "follow" | "error" | "manual";
16286-
type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video";
1628716286
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
1628816287
type ScopedCredentialType = "ScopedCred";
1628916288
type ServiceWorkerState = "installing" | "installed" | "activating" | "activated" | "redundant";

baselines/webworker.generated.d.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ interface PushSubscriptionOptionsInit {
142142
}
143143

144144
interface RequestInit {
145-
body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null;
145+
body?: BodyInit | null;
146146
cache?: RequestCache;
147147
credentials?: RequestCredentials;
148148
headers?: HeadersInit;
@@ -153,7 +153,7 @@ interface RequestInit {
153153
redirect?: RequestRedirect;
154154
referrer?: string;
155155
referrerPolicy?: ReferrerPolicy;
156-
signal?: object;
156+
signal?: object | null;
157157
window?: any;
158158
}
159159

@@ -218,6 +218,7 @@ interface BlobPropertyBag {
218218
}
219219

220220
interface Body {
221+
readonly body: ReadableStream | null;
221222
readonly bodyUsed: boolean;
222223
arrayBuffer(): Promise<ArrayBuffer>;
223224
blob(): Promise<Blob>;
@@ -661,10 +662,10 @@ interface GlobalFetch {
661662
interface Headers {
662663
append(name: string, value: string): void;
663664
delete(name: string): void;
664-
forEach(callback: Function, thisArg?: any): void;
665665
get(name: string): string | null;
666666
has(name: string): boolean;
667667
set(name: string, value: string): void;
668+
forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void;
668669
}
669670

670671
declare var Headers: {
@@ -1280,32 +1281,31 @@ interface Request extends Body {
12801281
readonly redirect: RequestRedirect;
12811282
readonly referrer: string;
12821283
readonly referrerPolicy: ReferrerPolicy;
1283-
readonly signal: object | null;
1284-
readonly type: RequestType;
1284+
readonly signal: object;
12851285
readonly url: string;
12861286
clone(): Request;
12871287
}
12881288

12891289
declare var Request: {
12901290
prototype: Request;
1291-
new(input: Request | string, init?: RequestInit): Request;
1291+
new(input: RequestInfo, init?: RequestInit): Request;
12921292
};
12931293

12941294
interface Response extends Body {
1295-
readonly body: ReadableStream | null;
12961295
readonly headers: Headers;
12971296
readonly ok: boolean;
12981297
readonly redirected: boolean;
12991298
readonly status: number;
13001299
readonly statusText: string;
1300+
readonly trailer: Promise<Headers>;
13011301
readonly type: ResponseType;
13021302
readonly url: string;
13031303
clone(): Response;
13041304
}
13051305

13061306
declare var Response: {
13071307
prototype: Response;
1308-
new(body?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null, init?: ResponseInit): Response;
1308+
new(body?: BodyInit | null, init?: ResponseInit): Response;
13091309
error(): Response;
13101310
redirect(url: string, status?: number): Response;
13111311
};
@@ -1768,12 +1768,14 @@ declare function addEventListener<K extends keyof DedicatedWorkerGlobalScopeEven
17681768
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
17691769
declare function removeEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
17701770
declare function removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
1771+
type HeadersInit = Headers | string[][] | Record<string, string>;
1772+
type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStream | string;
1773+
type RequestInfo = Request | string;
17711774
type PerformanceEntryList = PerformanceEntry[];
1775+
type BufferSource = ArrayBufferView | ArrayBuffer;
17721776
type FormDataEntryValue = string | File;
1773-
type HeadersInit = Headers | string[][] | { [key: string]: string };
17741777
type AlgorithmIdentifier = string | Algorithm;
17751778
type AAGUID = string;
1776-
type BodyInit = any;
17771779
type ByteString = string;
17781780
type CryptoOperationData = ArrayBufferView;
17791781
type GLbitfield = number;
@@ -1791,7 +1793,6 @@ type GLubyte = number;
17911793
type GLuint = number;
17921794
type GLushort = number;
17931795
type IDBKeyPath = string;
1794-
type RequestInfo = Request | string;
17951796
type USVString = string;
17961797
type payloadtype = number;
17971798
type ClientTypes = "window" | "worker" | "sharedworker" | "all";
@@ -1808,12 +1809,11 @@ type NotificationPermission = "default" | "denied" | "granted";
18081809
type PushEncryptionKeyName = "p256dh" | "auth";
18091810
type PushPermissionState = "granted" | "denied" | "prompt";
18101811
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "origin-only" | "origin-when-cross-origin" | "unsafe-url";
1811-
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache";
1812+
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
18121813
type RequestCredentials = "omit" | "same-origin" | "include";
1813-
type RequestDestination = "" | "document" | "sharedworker" | "subresource" | "unknown" | "worker";
1814+
type RequestDestination = "" | "audio" | "audioworklet" | "document" | "embed" | "font" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt";
18141815
type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors";
18151816
type RequestRedirect = "follow" | "error" | "manual";
1816-
type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video";
18171817
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
18181818
type ServiceWorkerState = "installing" | "installed" | "activating" | "activated" | "redundant";
18191819
type VisibilityState = "hidden" | "visible" | "prerender" | "unloaded";

inputfiles/addedTypes.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
{
22
"mixins": {
33
"mixin": {
4-
"Body": {
5-
"name": "Body",
6-
"methods": {
7-
"method": {
8-
"formData": {
9-
"name": "formData",
10-
"flavor": "Web",
11-
"override-signatures": [
12-
"formData(): Promise<FormData>"
13-
]
14-
}
15-
}
16-
}
17-
},
184
"HTMLHyperlinkElementUtils": {
195
"name": "HTMLHyperlinkElementUtils",
206
"properties": {
@@ -2878,7 +2864,7 @@
28782864
"new-type": "InsertPosition"
28792865
},
28802866
{
2881-
"override-type": "Headers | string[][] | { [key: string]: string }",
2867+
"override-type": "Headers | string[][] | Record<string, string>",
28822868
"new-type": "HeadersInit"
28832869
},
28842870
{
@@ -2901,10 +2887,6 @@
29012887
"new-type": "AAGUID",
29022888
"override-type": "string"
29032889
},
2904-
{
2905-
"new-type": "BodyInit",
2906-
"override-type": "any"
2907-
},
29082890
{
29092891
"new-type": "ByteString",
29102892
"override-type": "string"

inputfiles/idl/Fetch.widl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;
2+
3+
[Constructor(optional HeadersInit init),
4+
Exposed=(Window,Worker)]
5+
interface Headers {
6+
void append(ByteString name, ByteString value);
7+
void delete(ByteString name);
8+
ByteString? get(ByteString name);
9+
boolean has(ByteString name);
10+
void set(ByteString name, ByteString value);
11+
iterable<ByteString, ByteString>;
12+
};
13+
typedef (Blob or BufferSource or FormData or URLSearchParams or ReadableStream or USVString) BodyInit;
14+
interface mixin Body {
15+
readonly attribute ReadableStream? body;
16+
readonly attribute boolean bodyUsed;
17+
[NewObject] Promise<ArrayBuffer> arrayBuffer();
18+
[NewObject] Promise<Blob> blob();
19+
[NewObject] Promise<FormData> formData();
20+
[NewObject] Promise<any> json();
21+
[NewObject] Promise<USVString> text();
22+
};
23+
typedef (Request or USVString) RequestInfo;
24+
25+
[Constructor(RequestInfo input, optional RequestInit init),
26+
Exposed=(Window,Worker)]
27+
interface Request {
28+
readonly attribute ByteString method;
29+
readonly attribute USVString url;
30+
[SameObject] readonly attribute Headers headers;
31+
32+
readonly attribute RequestDestination destination;
33+
readonly attribute USVString referrer;
34+
readonly attribute ReferrerPolicy referrerPolicy;
35+
readonly attribute RequestMode mode;
36+
readonly attribute RequestCredentials credentials;
37+
readonly attribute RequestCache cache;
38+
readonly attribute RequestRedirect redirect;
39+
readonly attribute DOMString integrity;
40+
readonly attribute boolean keepalive;
41+
readonly attribute AbortSignal signal;
42+
43+
[NewObject] Request clone();
44+
};
45+
Request includes Body;
46+
47+
dictionary RequestInit {
48+
ByteString method;
49+
HeadersInit headers;
50+
BodyInit? body;
51+
USVString referrer;
52+
ReferrerPolicy referrerPolicy;
53+
RequestMode mode;
54+
RequestCredentials credentials;
55+
RequestCache cache;
56+
RequestRedirect redirect;
57+
DOMString integrity;
58+
boolean keepalive;
59+
AbortSignal? signal;
60+
any window; // can only be set to null
61+
};
62+
63+
enum RequestDestination { "", "audio", "audioworklet", "document", "embed", "font", "image", "manifest", "object", "paintworklet", "report", "script", "sharedworker", "style", "track", "video", "worker", "xslt" };
64+
enum RequestMode { "navigate", "same-origin", "no-cors", "cors" };
65+
enum RequestCredentials { "omit", "same-origin", "include" };
66+
enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
67+
enum RequestRedirect { "follow", "error", "manual" };
68+
[Constructor(optional BodyInit? body = null, optional ResponseInit init), Exposed=(Window,Worker)]
69+
interface Response {
70+
[NewObject] static Response error();
71+
[NewObject] static Response redirect(USVString url, optional unsigned short status = 302);
72+
73+
readonly attribute ResponseType type;
74+
75+
readonly attribute USVString url;
76+
readonly attribute boolean redirected;
77+
readonly attribute unsigned short status;
78+
readonly attribute boolean ok;
79+
readonly attribute ByteString statusText;
80+
[SameObject] readonly attribute Headers headers;
81+
readonly attribute Promise<Headers> trailer;
82+
83+
[NewObject] Response clone();
84+
};
85+
Response includes Body;
86+
87+
dictionary ResponseInit {
88+
unsigned short status = 200;
89+
ByteString statusText = "OK";
90+
HeadersInit headers;
91+
};
92+
93+
enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" };
94+
partial interface WindowOrWorkerGlobalScope {
95+
[NewObject] Promise<Response> fetch(RequestInfo input, optional RequestInit init);
96+
};

inputfiles/idlSources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"url": "https://encoding.spec.whatwg.org/",
44
"title": "Encoding"
55
},
6+
{
7+
"url": "https://fetch.spec.whatwg.org/",
8+
"title": "Fetch"
9+
},
610
{
711
"url": "https://drafts.fxtf.org/geometry/",
812
"title": "Geometry Interfaces"

inputfiles/knownWorkerTypes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,6 @@
185185
"BlobPropertyBag",
186186
"FilePropertyBag",
187187
"IDBArrayKey",
188-
"IDBVersionChangeEventInit"
188+
"IDBVersionChangeEventInit",
189+
"BufferSource"
189190
]

0 commit comments

Comments
 (0)