mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Fix zod infering of queries
This commit is contained in:
parent
5fe75d5753
commit
53ce929fa7
@ -24,10 +24,9 @@ import {
|
|||||||
QueryClient,
|
QueryClient,
|
||||||
QueryFunctionContext,
|
QueryFunctionContext,
|
||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
useMutation,
|
|
||||||
useQuery,
|
useQuery,
|
||||||
} from "@tanstack/react-query";
|
} from "@tanstack/react-query";
|
||||||
import { z } from "zod";
|
import { ZodType, z } from "zod";
|
||||||
import { KyooErrors } from "./kyoo-errors";
|
import { KyooErrors } from "./kyoo-errors";
|
||||||
import { Page, Paged } from "./page";
|
import { Page, Paged } from "./page";
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
@ -39,7 +38,7 @@ const kyooUrl =
|
|||||||
// The url of kyoo, set after each query (used by the image parser).
|
// The url of kyoo, set after each query (used by the image parser).
|
||||||
export let kyooApiUrl = kyooUrl;
|
export let kyooApiUrl = kyooUrl;
|
||||||
|
|
||||||
export const queryFn = async <Data,>(
|
export const queryFn = async <Data extends ZodType,>(
|
||||||
context:
|
context:
|
||||||
| (QueryFunctionContext & { timeout?: number; apiUrl?: string })
|
| (QueryFunctionContext & { timeout?: number; apiUrl?: string })
|
||||||
| {
|
| {
|
||||||
@ -50,9 +49,9 @@ export const queryFn = async <Data,>(
|
|||||||
apiUrl?: string;
|
apiUrl?: string;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
},
|
},
|
||||||
type?: z.ZodType<Data>,
|
type?: Data,
|
||||||
token?: string | null,
|
token?: string | null,
|
||||||
): Promise<Data> => {
|
): Promise<z.infer<Data>> => {
|
||||||
const url = context.apiUrl ?? (Platform.OS === "web" ? kyooUrl : getCurrentAccount()!.apiUrl);
|
const url = context.apiUrl ?? (Platform.OS === "web" ? kyooUrl : getCurrentAccount()!.apiUrl);
|
||||||
kyooApiUrl = url;
|
kyooApiUrl = url;
|
||||||
|
|
||||||
@ -109,7 +108,6 @@ export const queryFn = async <Data,>(
|
|||||||
throw data as KyooErrors;
|
throw data as KyooErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error Assume Data is nullable.
|
|
||||||
if (resp.status === 204) return null;
|
if (resp.status === 204) return null;
|
||||||
|
|
||||||
let data;
|
let data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user