|
1 | 1 | export class FetchRequest { |
2 | | - constructor(method: string, url: string, options?: Options); |
3 | | - addHeader(key: string, value: string): void; |
| 2 | + constructor(method: string, url: string | URL, options?: Options); |
4 | 3 | perform(): Promise<FetchResponse>; |
| 4 | + addHeader(key: string, value: string): void; |
| 5 | + sameHostname(): boolean; |
| 6 | + get fetchOptions(): RequestInit & { method: string; headers: HeadersInit }; |
| 7 | + get headers(): HeadersInit; |
| 8 | + get csrfToken(): string | undefined; |
| 9 | + get contentType(): string | undefined; |
| 10 | + get accept(): string; |
| 11 | + get body(): BodyInit | Record<string, unknown> | null | undefined; |
| 12 | + get query(): string; |
| 13 | + get url(): string; |
| 14 | + get responseKind(): ResponseKind; |
| 15 | + get signal(): AbortSignal | null | undefined; |
| 16 | + get redirect(): RequestRedirect; |
| 17 | + get credentials(): RequestCredentials; |
| 18 | + get keepalive(): boolean; |
| 19 | + get additionalHeaders(): HeadersInit; |
| 20 | + get formattedBody(): string; |
5 | 21 | } |
6 | 22 |
|
| 23 | +export type ResponseKind = "html" | "turbo-stream" | "json" | "script"; |
| 24 | + |
7 | 25 | export interface Options { |
8 | | - body?: BodyInit | Record<any, any>; |
| 26 | + body?: BodyInit | Record<string, unknown> | null; |
9 | 27 | contentType?: string; |
10 | 28 | headers?: HeadersInit; |
11 | 29 | credentials?: RequestCredentials; |
12 | | - query?: Record<any, any> | FormData | URLSearchParams; |
13 | | - responseKind?: "html" | "turbo-stream" | "json"; |
| 30 | + query?: Record<string, unknown> | FormData | URLSearchParams; |
| 31 | + responseKind?: ResponseKind; |
| 32 | + signal?: AbortSignal | null; |
| 33 | + redirect?: RequestRedirect; |
| 34 | + keepalive?: boolean; |
14 | 35 | } |
15 | 36 |
|
16 | 37 | export class FetchResponse { |
17 | 38 | get statusCode(): number; |
18 | 39 | get redirected(): boolean; |
19 | 40 | get ok(): boolean; |
| 41 | + get unauthenticated(): boolean; |
| 42 | + get unprocessableEntity(): boolean; |
| 43 | + get authenticationURL(): string | null; |
20 | 44 | get contentType(): string; |
21 | 45 | get headers(): Headers; |
22 | 46 | get html(): Promise<string>; |
23 | 47 | get json(): Promise<any>; |
24 | 48 | get text(): Promise<string>; |
| 49 | + get isTurboStream(): boolean; |
| 50 | + get isScript(): boolean; |
| 51 | + renderTurboStream(): Promise<void>; |
| 52 | + activeScript(): Promise<void>; |
25 | 53 | } |
26 | 54 |
|
27 | 55 | export class RequestInterceptor { |
28 | 56 | static register(interceptor: (request: FetchRequest) => void | Promise<void>): void; |
| 57 | + static get(): (request: FetchRequest) => void | Promise<void>; |
29 | 58 | static reset(): void; |
30 | 59 | } |
31 | 60 |
|
32 | | -export function get(url: string, options?: Options): Promise<FetchResponse>; |
33 | | -export function post(url: string, options?: Options): Promise<FetchResponse>; |
34 | | -export function put(url: string, options?: Options): Promise<FetchResponse>; |
35 | | -export function patch(url: string, options?: Options): Promise<FetchResponse>; |
36 | | -export function destroy(url: string, options?: Options): Promise<FetchResponse>; |
| 61 | +export function get(url: string | URL, options?: Options): Promise<FetchResponse>; |
| 62 | +export function post(url: string | URL, options?: Options): Promise<FetchResponse>; |
| 63 | +export function put(url: string | URL, options?: Options): Promise<FetchResponse>; |
| 64 | +export function patch(url: string | URL, options?: Options): Promise<FetchResponse>; |
| 65 | +export function destroy(url: string | URL, options?: Options): Promise<FetchResponse>; |
0 commit comments