diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/shared-react/package.json | 4 | ||||
| -rw-r--r-- | packages/shared/customFetch.ts | 31 |
2 files changed, 23 insertions, 12 deletions
diff --git a/packages/shared-react/package.json b/packages/shared-react/package.json index 7b3df535..3e01363c 100644 --- a/packages/shared-react/package.json +++ b/packages/shared-react/package.json @@ -16,8 +16,8 @@ "@karakeep/tsconfig": "workspace:^0.1.0" }, "peerDependencies": { - "react": "^18.3.1", - "react-native": "^0.76.3" + "react": "^19.0.0", + "react-native": "0.79.3" }, "peerDependenciesMeta": { "react-native": { diff --git a/packages/shared/customFetch.ts b/packages/shared/customFetch.ts index e9ac8a89..18b4e133 100644 --- a/packages/shared/customFetch.ts +++ b/packages/shared/customFetch.ts @@ -1,13 +1,24 @@ import serverConfig from "./config"; -// Custom fetch function with configurable timeout -export function customFetch( - input: Parameters<typeof fetch>[0], - init?: Parameters<typeof fetch>[1], -): ReturnType<typeof fetch> { - const timeout = serverConfig.inference.fetchTimeoutSec * 1000; // Convert to milliseconds - return fetch(input, { - signal: AbortSignal.timeout(timeout), - ...init, - }); +// Generic fetch function type that works across environments +type FetchFunction = ( + input: RequestInfo | URL | string, + init?: RequestInit, +) => Promise<Response>; + +// Factory function to create a custom fetch with timeout for any fetch implementation +export function createCustomFetch(fetchImpl: FetchFunction = globalThis.fetch) { + return function customFetch( + input: Parameters<typeof fetchImpl>[0], + init?: Parameters<typeof fetchImpl>[1], + ): ReturnType<typeof fetchImpl> { + const timeout = serverConfig.inference.fetchTimeoutSec * 1000; // Convert to milliseconds + return fetchImpl(input, { + signal: AbortSignal.timeout(timeout), + ...init, + }); + }; } + +// Default export for backward compatibility - uses global fetch +export const customFetch = createCustomFetch(); |
