Merge branch 'dev' into pr-14-v2

This commit is contained in:
Jorrin
2023-12-26 21:48:32 +01:00
78 changed files with 2364 additions and 700 deletions

View File

@@ -5,10 +5,13 @@ export type FetcherOptions = {
headers?: Record<string, string>;
query?: Record<string, string>;
method?: 'HEAD' | 'GET' | 'POST';
readHeaders?: string[];
body?: Record<string, any> | string | FormData | URLSearchParams;
returnRaw?: boolean;
};
// Version of the options that always has the defaults set
// This is to make making fetchers yourself easier
export type DefaultedFetcherOptions = {
baseUrl?: string;
body?: Record<string, any> | string | FormData;
@@ -16,13 +19,23 @@ export type DefaultedFetcherOptions = {
query: Record<string, string>;
method: 'HEAD' | 'GET' | 'POST';
returnRaw: boolean;
readHeaders: string[];
};
export type FetcherResponse<T = any> = {
statusCode: number;
headers: Headers;
finalUrl: string;
body: T;
};
// This is the version that will be inputted by library users
export type Fetcher<T = any> = {
(url: string, ops: DefaultedFetcherOptions): Promise<T>;
(url: string, ops: DefaultedFetcherOptions): Promise<FetcherResponse<T>>;
};
// this feature has some quality of life features
// This is the version that scrapers will be interacting with
export type UseableFetcher<T = any> = {
(url: string, ops?: FetcherOptions): Promise<T>;
full: (url: string, ops?: FetcherOptions) => Promise<FetcherResponse<T>>;
};