import type { AnySpiceflow, Spiceflow } from '../spiceflow.ts'; import type { ExtractParamsFromPath } from '../types.ts'; import type { SpiceflowClient } from './types.ts'; import type { ReplaceGeneratorWithAsyncGenerator } from './types.ts'; import { SpiceflowFetchError } from './errors.ts'; type NavigateRoutes = Path extends `/${infer Rest}` ? Rest extends '' ? 'index' extends keyof Routes ? Routes['index'] : never : _NavigateRoutes : _NavigateRoutes; type _NavigateRoutes = Path extends `${infer Segment}/${infer Rest}` ? Segment extends keyof Routes ? _NavigateRoutes : never : Path extends keyof Routes ? Routes[Path] : never; type RouteAtPath, Path extends string> = NavigateRoutes; type RouteInfoForMethod, Path extends string, Method extends string> = Lowercase extends keyof RouteAtPath ? RouteAtPath[Lowercase] : never; type ParamsOption = ExtractParamsFromPath extends undefined ? { params?: Record; } : { params: ExtractParamsFromPath; }; type QueryOption, Path extends string, Method extends string> = RouteInfoForMethod extends { query: infer Q; } ? undefined extends Q ? { query?: Record; } : { query: Q; } : { query?: Record; }; type BodyOption, Path extends string, Method extends string> = Lowercase extends 'get' | 'head' | 'subscribe' ? {} : RouteInfoForMethod extends { request: infer Body; } ? undefined extends Body ? { body?: unknown; } : { body: Body; } : { body?: unknown; }; type HasRequiredFields, Path extends string, Method extends string> = ExtractParamsFromPath extends undefined ? RouteInfoForMethod extends { query: infer Q; } ? undefined extends Q ? Lowercase extends 'get' | 'head' | 'subscribe' ? false : RouteInfoForMethod extends { request: infer Body; } ? undefined extends Body ? false : true : false : true : Lowercase extends 'get' | 'head' | 'subscribe' ? false : RouteInfoForMethod extends { request: infer Body; } ? undefined extends Body ? false : true : false : true; type FetchOptionsTyped, Path extends string, Method extends string> = { method?: Method; headers?: RequestInit['headers']; signal?: AbortSignal; } & ParamsOption & QueryOption & BodyOption; type FetchOptionsFallback = { method?: string; body?: BodyInit | Record | null; query?: Record; params?: Record; headers?: RequestInit['headers']; signal?: AbortSignal; [key: string]: unknown; }; type FetchOptions, Path extends string, Method extends string> = [RouteAtPath] extends [never] ? FetchOptionsFallback : FetchOptionsTyped; type FetchResultData, Path extends string, Method extends string> = [RouteAtPath] extends [never] ? any : RouteInfoForMethod extends { response: infer Res extends Record; } ? ReplaceGeneratorWithAsyncGenerator[200] : any; type FetchResultError, Path extends string, Method extends string> = [RouteAtPath] extends [never] ? SpiceflowFetchError : RouteInfoForMethod extends { response: infer Res extends Record; } ? Exclude extends never ? SpiceflowFetchError : { [Status in keyof Res]: SpiceflowFetchError; }[Exclude] : SpiceflowFetchError; type FetchResult, Path extends string, Method extends string> = FetchResultError | FetchResultData; type ResolveOptions = App extends { _types: { ClientRoutes: infer Routes extends Record; }; } ? FetchOptions : FetchOptionsFallback; type ResolveResult = App extends { _types: { ClientRoutes: infer Routes extends Record; }; } ? FetchResult : SpiceflowFetchError | any; type IsOptionsRequired = App extends { _types: { ClientRoutes: infer Routes extends Record; }; } ? [RouteAtPath] extends [never] ? false : HasRequiredFields : false; export interface SpiceflowFetch { (...args: IsOptionsRequired extends true ? [path: Path, options: ResolveOptions] : [path: Path, options?: ResolveOptions]): Promise>; } export declare function createSpiceflowFetch(domain: App | string, config?: SpiceflowClient.Config & (App extends Spiceflow ? { state?: Singleton['state']; } : {})): SpiceflowFetch; export {}; //# sourceMappingURL=fetch.d.ts.map