import type { InnerClientState } from '../Client/client' ; import type { SchedulerPromiseValue } from '../Scheduler' ; export interface Prefetch < GeneratedSchema extends { query : object ; } > { < TData > ( fn ) : TData | ( Promise < TData > & { schedulerPromise : Promise < SchedulerPromiseValue > ; } ) ; } export function createPrefetch < GeneratedSchema extends { query : object ; } > ( query , { scheduler } ) { return function prefetch < TData > ( fn ) : ( Promise < TData > & { schedulerPromise : Promise < SchedulerPromiseValue > ; } ) | TData { const existingData = fn ( query ) ; if ( scheduler . resolving ) { return Object . assign ( scheduler . resolving . promise . then ( ( ) => prefetch ( fn ) ) , { schedulerPromise : scheduler . resolving . promise , } ) ; } return existingData ; } ; }