Skip to content

Instantly share code, notes, and snippets.

@andyjessop
Created September 16, 2024 14:16
Show Gist options
  • Save andyjessop/ca8456d22b2abb44542143d55c196040 to your computer and use it in GitHub Desktop.
Save andyjessop/ca8456d22b2abb44542143d55c196040 to your computer and use it in GitHub Desktop.
/**
* This Fetch API interface represents the response to a request.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
*/
declare var Response: {
prototype: Response;
new (body?: BodyInit | null, init?: ResponseInit): Response;
redirect(url: string, status?: number): Response;
json(any: any, maybeInit?: ResponseInit | Response): Response;
};
/**
* This Fetch API interface represents the response to a request.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
*/
interface Response extends Body {
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status) */
status: number;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/statusText) */
statusText: string;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
headers: Headers;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/ok) */
ok: boolean;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirected) */
redirected: boolean;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
}
/**
* This Fetch API interface represents a resource request.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request)
*/
declare var Request: {
prototype: Request;
new <CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>(
input: RequestInfo<CfProperties>,
init?: RequestInit<Cf>,
): Request<CfHostMetadata, Cf>;
};
/**
* This Fetch API interface represents a resource request.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request)
*/
interface Request<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>
extends Body {
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/clone) */
clone(): Request<CfHostMetadata, Cf>;
/**
* Returns request's HTTP method, which is "GET" by default.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/method)
*/
method: string;
/**
* Returns the URL of request as a string.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/url)
*/
url: string;
/**
* 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.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/headers)
*/
headers: Headers;
/**
* 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.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/redirect)
*/
redirect: string;
fetcher: Fetcher | null;
/**
* Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/signal)
*/
signal: AbortSignal;
cf: Cf | undefined;
/**
* 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]
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/integrity)
*/
integrity: string;
/**
* Returns a boolean indicating whether or not request can outlive the global in which it was created.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/keepalive)
*/
keepalive: boolean;
/**
* Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/cache)
*/
cache?: "no-store";
}
/**
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
*/
declare var WebSocket: {
prototype: WebSocket;
new (url: string, protocols?: string[] | string): WebSocket;
readonly READY_STATE_CONNECTING: number;
readonly CONNECTING: number;
readonly READY_STATE_OPEN: number;
readonly OPEN: number;
readonly READY_STATE_CLOSING: number;
readonly CLOSING: number;
readonly READY_STATE_CLOSED: number;
readonly CLOSED: number;
};
/**
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
*/
interface WebSocket extends EventTarget<WebSocketEventMap> {
accept(): void;
/**
* Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
*/
send(message: (ArrayBuffer | ArrayBufferView) | string): void;
/**
* Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
*/
close(code?: number, reason?: string): void;
serializeAttachment(attachment: any): void;
deserializeAttachment(): any | null;
/**
* Returns the state of the WebSocket object's connection. It can have the values described below.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
*/
readyState: number;
/**
* Returns the URL that was used to establish the WebSocket connection.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
*/
url: string | null;
/**
* Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
*/
protocol: string | null;
/**
* Returns the extensions selected by the server, if any.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
*/
extensions: string | null;
}
declare class Response extends Body {
constructor(body?: BodyInit | null, init?: ResponseInit);
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
static redirect(url: string, status?: number): Response;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
static json(any: any, maybeInit?: ResponseInit | Response): Response;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */
clone(): Response;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status) */
get status(): number;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/statusText) */
get statusText(): string;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
get headers(): Headers;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/ok) */
get ok(): boolean;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirected) */
get redirected(): boolean;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */
get url(): string;
get webSocket(): WebSocket | null;
get cf(): any | undefined;
}
/**
* This Fetch API interface represents a resource request.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request)
*/
declare class Request<
CfHostMetadata = unknown,
Cf = CfProperties<CfHostMetadata>,
> extends Body {
constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/clone) */
clone(): Request<CfHostMetadata, Cf>;
/**
* Returns request's HTTP method, which is "GET" by default.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/method)
*/
get method(): string;
/**
* Returns the URL of request as a string.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/url)
*/
get url(): string;
/**
* 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.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/headers)
*/
get headers(): Headers;
/**
* 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.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/redirect)
*/
get redirect(): string;
get fetcher(): Fetcher | null;
/**
* Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/signal)
*/
get signal(): AbortSignal;
get cf(): Cf | undefined;
/**
* 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]
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/integrity)
*/
get integrity(): string;
/**
* Returns a boolean indicating whether or not request can outlive the global in which it was created.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/keepalive)
*/
get keepalive(): boolean;
/**
* Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/cache)
*/
cache?: "no-store";
}
/**
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
*/
declare class WebSocket extends EventTarget<WebSocketEventMap> {
constructor(url: string, protocols?: string[] | string);
accept(): void;
/**
* Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
*/
send(message: (ArrayBuffer | ArrayBufferView) | string): void;
/**
* Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
*/
close(code?: number, reason?: string): void;
serializeAttachment(attachment: any): void;
deserializeAttachment(): any | null;
static readonly READY_STATE_CONNECTING: number;
static readonly CONNECTING: number;
static readonly READY_STATE_OPEN: number;
static readonly OPEN: number;
static readonly READY_STATE_CLOSING: number;
static readonly CLOSING: number;
static readonly READY_STATE_CLOSED: number;
static readonly CLOSED: number;
/**
* Returns the state of the WebSocket object's connection. It can have the values described below.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
*/
get readyState(): number;
/**
* Returns the URL that was used to establish the WebSocket connection.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
*/
get url(): string | null;
/**
* Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
*/
get protocol(): string | null;
/**
* Returns the extensions selected by the server, if any.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
*/
get extensions(): string | null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment