@@ -125,8 +125,8 @@ export type ModelQueryOptions<T> = Omit<CreateQueryOptions<T, DefaultError>, 'qu
125125
126126export type ModelQueryResult < T > = CreateQueryResult < WithOptimistic < T > , DefaultError > & { queryKey : QueryKey } ;
127127
128- export type ModelInfiniteQueryOptions < T > = Omit <
129- CreateInfiniteQueryOptions < T , DefaultError , InfiniteData < T > > ,
128+ export type ModelInfiniteQueryOptions < T , TPageParam = unknown > = Omit <
129+ CreateInfiniteQueryOptions < T , DefaultError , InfiniteData < T , TPageParam > , QueryKey , TPageParam > ,
130130 'queryKey' | 'initialPageParam'
131131> &
132132 QueryContext ;
@@ -147,7 +147,10 @@ export type ModelMutationModelResult<
147147 Array extends boolean = false ,
148148 Options extends QueryOptions < Schema > = QueryOptions < Schema > ,
149149 ExtResult extends ExtResultBase < Schema > = { } ,
150- > = Omit < ModelMutationResult < SimplifiedResult < Schema , Model , TArgs , Options , false , Array , ExtResult > , TArgs > , 'mutateAsync' > & {
150+ > = Omit <
151+ ModelMutationResult < SimplifiedResult < Schema , Model , TArgs , Options , false , Array , ExtResult > , TArgs > ,
152+ 'mutateAsync'
153+ > & {
151154 mutateAsync < T extends TArgs > (
152155 args : T ,
153156 options ?: ModelMutationOptions < SimplifiedResult < Schema , Model , T , Options , false , Array , ExtResult > , T > ,
@@ -159,7 +162,12 @@ export type ClientHooks<
159162 Options extends QueryOptions < Schema > = QueryOptions < Schema > ,
160163 ExtResult extends ExtResultBase < Schema > = { } ,
161164> = {
162- [ Model in GetSlicedModels < Schema , Options > as `${Uncapitalize < Model > } `] : ModelQueryHooks < Schema , Model , Options , ExtResult > ;
165+ [ Model in GetSlicedModels < Schema , Options > as `${Uncapitalize < Model > } `] : ModelQueryHooks <
166+ Schema ,
167+ Model ,
168+ Options ,
169+ ExtResult
170+ > ;
163171} & ProcedureHooks < Schema , Options > ;
164172
165173type ProcedureHookGroup < Schema extends SchemaDef , Options extends QueryOptions < Schema > > = {
@@ -238,10 +246,14 @@ export type ModelQueryHooks<
238246 options ?: Accessor < ModelQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > > ,
239247 ) : ModelQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > ;
240248
241- useInfiniteFindMany < T extends FindManyArgs < Schema , Model , Options , { } , ExtResult > > (
249+ useInfiniteFindMany < T extends FindManyArgs < Schema , Model , Options , { } , ExtResult > , TPageParam = unknown > (
242250 args ?: Accessor < SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , ExtResult > > > ,
243- options ?: Accessor < ModelInfiniteQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > > ,
244- ) : ModelInfiniteQueryResult < InfiniteData < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > > ;
251+ options ?: Accessor <
252+ ModelInfiniteQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] , TPageParam >
253+ > ,
254+ ) : ModelInfiniteQueryResult <
255+ InfiniteData < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] , TPageParam >
256+ > ;
245257
246258 useCreate < T extends CreateArgs < Schema , Model , Options , { } , ExtResult > > (
247259 options ?: Accessor < ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > , T > > ,
@@ -310,23 +322,20 @@ export type ModelQueryHooks<
310322 * const client = useClientQueries<DbType>(schema)
311323 * ```
312324 */
313- export function useClientQueries <
314- SchemaOrClient extends SchemaDef | ClientContract < any , any , any , any , any > ,
315- > (
325+ export function useClientQueries < SchemaOrClient extends SchemaDef | ClientContract < any , any , any , any , any > > (
316326 schema : InferSchema < SchemaOrClient > ,
317327 options ?: Accessor < QueryContext > ,
318- ) : ClientHooks < InferSchema < SchemaOrClient > , InferOptions < SchemaOrClient , InferSchema < SchemaOrClient > > , InferExtResult < SchemaOrClient > extends ExtResultBase < InferSchema < SchemaOrClient > > ? InferExtResult < SchemaOrClient > : { } > {
319- const result = Object . keys ( schema . models ) . reduce (
320- ( acc , model ) => {
321- ( acc as any ) [ lowerCaseFirst ( model ) ] = useModelQueries (
322- schema as any ,
323- model as any ,
324- options ,
325- ) ;
326- return acc ;
327- } ,
328- { } as any ,
329- ) ;
328+ ) : ClientHooks <
329+ InferSchema < SchemaOrClient > ,
330+ InferOptions < SchemaOrClient , InferSchema < SchemaOrClient > > ,
331+ InferExtResult < SchemaOrClient > extends ExtResultBase < InferSchema < SchemaOrClient > >
332+ ? InferExtResult < SchemaOrClient >
333+ : { }
334+ > {
335+ const result = Object . keys ( schema . models ) . reduce ( ( acc , model ) => {
336+ ( acc as any ) [ lowerCaseFirst ( model ) ] = useModelQueries ( schema as any , model as any , options ) ;
337+ return acc ;
338+ } , { } as any ) ;
330339
331340 const procedures = ( schema as any ) . procedures as Record < string , { mutation ?: boolean } > | undefined ;
332341 if ( procedures ) {
@@ -376,7 +385,11 @@ export function useModelQueries<
376385 Model extends GetModels < Schema > ,
377386 Options extends QueryOptions < Schema > ,
378387 ExtResult extends ExtResultBase < Schema > = { } ,
379- > ( schema : Schema , model : Model , rootOptions ?: Accessor < QueryContext > ) : ModelQueryHooks < Schema , Model , Options , ExtResult > {
388+ > (
389+ schema : Schema ,
390+ model : Model ,
391+ rootOptions ?: Accessor < QueryContext > ,
392+ ) : ModelQueryHooks < Schema , Model , Options , ExtResult > {
380393 const modelDef = Object . values ( schema . models ) . find ( ( m ) => m . name . toLowerCase ( ) === model . toLowerCase ( ) ) ;
381394 if ( ! modelDef ) {
382395 throw new Error ( `Model "${ model } " not found in schema` ) ;
@@ -487,36 +500,58 @@ export function useInternalQuery<TQueryFnData, TData>(
487500 return createQueryResult ( query , queryKey ) ;
488501}
489502
490- export function useInternalInfiniteQuery < TQueryFnData , TData > (
503+ export function useInternalInfiniteQuery < TQueryFnData , TData , TPageParam = unknown > (
491504 _schema : SchemaDef ,
492505 model : string ,
493506 operation : string ,
494- args : Accessor < unknown > ,
507+ args ? : Accessor < unknown > ,
495508 options ?: Accessor <
496509 Omit <
497- CreateInfiniteQueryOptions < TQueryFnData , DefaultError , InfiniteData < TData > > ,
510+ CreateInfiniteQueryOptions <
511+ TQueryFnData ,
512+ DefaultError ,
513+ InfiniteData < TData , TPageParam > ,
514+ QueryKey ,
515+ TPageParam
516+ > ,
498517 'queryKey' | 'initialPageParam'
499518 > &
500519 QueryContext
501520 > ,
502521) {
503522 const { endpoint, fetch } = useFetchOptions ( options ) ;
504523
505- const queryKey = $derived ( getQueryKey ( model , operation , args ( ) , { infinite : true , optimisticUpdate : false } ) ) ;
524+ const queryKey = $derived ( getQueryKey ( model , operation , args ?. ( ) , { infinite : true , optimisticUpdate : false } ) ) ;
506525
507526 const finalOptions = ( ) => {
508- const queryFn : QueryFunction < TQueryFnData , QueryKey , unknown > = ( { pageParam, signal } ) =>
509- fetcher < TQueryFnData > ( makeUrl ( endpoint , model , operation , pageParam ?? args ( ) ) , { signal } , fetch ) ;
527+ const queryFn : QueryFunction < TQueryFnData , QueryKey , TPageParam > = ( { pageParam, signal } ) =>
528+ fetcher < TQueryFnData > ( makeUrl ( endpoint , model , operation , pageParam ?? args ?. ( ) ) , { signal } , fetch ) ;
510529 const optionsValue = options ?.( ) ?? { getNextPageParam : ( ) => undefined } ;
511530 return {
512531 queryKey,
513532 queryFn,
514- initialPageParam : args ( ) ,
533+ initialPageParam : args ?. ( ) as TPageParam ,
515534 ...optionsValue ,
516535 } ;
517536 } ;
518537
519- const query = createInfiniteQuery < TQueryFnData , DefaultError , InfiniteData < TData > > ( finalOptions ) ;
538+ const query = createInfiniteQuery <
539+ TQueryFnData ,
540+ DefaultError ,
541+ InfiniteData < TData , TPageParam > ,
542+ QueryKey ,
543+ TPageParam
544+ > (
545+ finalOptions as unknown as Accessor <
546+ CreateInfiniteQueryOptions <
547+ TQueryFnData ,
548+ DefaultError ,
549+ InfiniteData < TData , TPageParam > ,
550+ QueryKey ,
551+ TPageParam
552+ >
553+ > ,
554+ ) ;
520555 // svelte-ignore state_referenced_locally
521556 return createQueryResult ( query , queryKey ) ;
522557}
0 commit comments