@@ -19,7 +19,7 @@ import {
1919 type UseSuspenseQueryOptions ,
2020 type UseSuspenseQueryResult ,
2121} from '@tanstack/react-query' ;
22- import { createInvalidator , createOptimisticUpdater , DEFAULT_QUERY_ENDPOINT , type InferOptions , type InferSchema } from '@zenstackhq/client-helpers' ;
22+ import { createInvalidator , createOptimisticUpdater , DEFAULT_QUERY_ENDPOINT , type InferExtResult , type InferOptions , type InferSchema } from '@zenstackhq/client-helpers' ;
2323import { fetcher , makeUrl , marshal } from '@zenstackhq/client-helpers/fetch' ;
2424import { lowerCaseFirst } from '@zenstackhq/common-helpers' ;
2525import type {
@@ -35,6 +35,7 @@ import type {
3535 DeleteArgs ,
3636 DeleteManyArgs ,
3737 ExistsArgs ,
38+ ExtResultBase ,
3839 FindFirstArgs ,
3940 FindManyArgs ,
4041 FindUniqueArgs ,
@@ -69,7 +70,7 @@ import type {
6970 WithOptimistic ,
7071} from './common/types.js' ;
7172export type { FetchFn } from '@zenstackhq/client-helpers/fetch' ;
72- export type { InferOptions , InferSchema } from '@zenstackhq/client-helpers' ;
73+ export type { InferExtResult , InferOptions , InferSchema } from '@zenstackhq/client-helpers' ;
7374export type { SchemaDef } from '@zenstackhq/schema' ;
7475
7576type ProcedureHookFn <
@@ -145,18 +146,20 @@ export type ModelMutationModelResult<
145146 TArgs ,
146147 Array extends boolean = false ,
147148 Options extends QueryOptions < Schema > = QueryOptions < Schema > ,
148- > = Omit < ModelMutationResult < SimplifiedResult < Schema , Model , TArgs , Options , false , Array , { } > , TArgs > , 'mutateAsync' > & {
149+ ExtResult extends ExtResultBase < Schema > = { } ,
150+ > = Omit < ModelMutationResult < SimplifiedResult < Schema , Model , TArgs , Options , false , Array , ExtResult > , TArgs > , 'mutateAsync' > & {
149151 mutateAsync < T extends TArgs > (
150152 args : T ,
151- options ?: ModelMutationOptions < SimplifiedResult < Schema , Model , T , Options , false , Array , { } > , T > ,
152- ) : Promise < SimplifiedResult < Schema , Model , T , Options , false , Array , { } > > ;
153+ options ?: ModelMutationOptions < SimplifiedResult < Schema , Model , T , Options , false , Array , ExtResult > , T > ,
154+ ) : Promise < SimplifiedResult < Schema , Model , T , Options , false , Array , ExtResult > > ;
153155} ;
154156
155157export type ClientHooks <
156158 Schema extends SchemaDef ,
157159 Options extends QueryOptions < Schema > = QueryOptions < Schema > ,
160+ ExtResult extends ExtResultBase < Schema > = { } ,
158161> = {
159- [ Model in GetSlicedModels < Schema , Options > as `${Uncapitalize < Model > } `] : ModelQueryHooks < Schema , Model , Options > ;
162+ [ Model in GetSlicedModels < Schema , Options > as `${Uncapitalize < Model > } `] : ModelQueryHooks < Schema , Model , Options , ExtResult > ;
160163} & ProcedureHooks < Schema , Options > ;
161164
162165type ProcedureHookGroup < Schema extends SchemaDef , Options extends QueryOptions < Schema > > = {
@@ -219,87 +222,88 @@ export type ModelQueryHooks<
219222 Schema extends SchemaDef ,
220223 Model extends GetModels < Schema > ,
221224 Options extends QueryOptions < Schema > = QueryOptions < Schema > ,
225+ ExtResult extends ExtResultBase < Schema > = { } ,
222226> = TrimSlicedOperations <
223227 Schema ,
224228 Model ,
225229 Options ,
226230 {
227- useFindUnique < T extends FindUniqueArgs < Schema , Model , Options , { } , { } > > (
228- args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options , { } , { } > > ,
229- options ?: ModelQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ,
230- ) : ModelQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ;
231-
232- useSuspenseFindUnique < T extends FindUniqueArgs < Schema , Model , Options , { } , { } > > (
233- args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options , { } , { } > > ,
234- options ?: ModelSuspenseQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ,
235- ) : ModelSuspenseQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ;
236-
237- useFindFirst < T extends FindFirstArgs < Schema , Model , Options , { } , { } > > (
238- args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options , { } , { } > > ,
239- options ?: ModelQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ,
240- ) : ModelQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ;
241-
242- useSuspenseFindFirst < T extends FindFirstArgs < Schema , Model , Options , { } , { } > > (
243- args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options , { } , { } > > ,
244- options ?: ModelSuspenseQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ,
245- ) : ModelSuspenseQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , { } > | null > ;
231+ useFindUnique < T extends FindUniqueArgs < Schema , Model , Options , { } , ExtResult > > (
232+ args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options , { } , ExtResult > > ,
233+ options ?: ModelQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ,
234+ ) : ModelQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ;
235+
236+ useSuspenseFindUnique < T extends FindUniqueArgs < Schema , Model , Options , { } , ExtResult > > (
237+ args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options , { } , ExtResult > > ,
238+ options ?: ModelSuspenseQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ,
239+ ) : ModelSuspenseQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ;
240+
241+ useFindFirst < T extends FindFirstArgs < Schema , Model , Options , { } , ExtResult > > (
242+ args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options , { } , ExtResult > > ,
243+ options ?: ModelQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ,
244+ ) : ModelQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ;
245+
246+ useSuspenseFindFirst < T extends FindFirstArgs < Schema , Model , Options , { } , ExtResult > > (
247+ args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options , { } , ExtResult > > ,
248+ options ?: ModelSuspenseQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ,
249+ ) : ModelSuspenseQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > | null > ;
246250
247251 useExists < T extends ExistsArgs < Schema , Model , Options > > (
248252 args ?: Subset < T , ExistsArgs < Schema , Model , Options > > ,
249253 options ?: ModelQueryOptions < boolean > ,
250254 ) : ModelQueryResult < boolean > ;
251255
252- useFindMany < T extends FindManyArgs < Schema , Model , Options , { } , { } > > (
253- args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , { } > > ,
254- options ?: ModelQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > ,
255- ) : ModelQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > ;
256+ useFindMany < T extends FindManyArgs < Schema , Model , Options , { } , ExtResult > > (
257+ args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , ExtResult > > ,
258+ options ?: ModelQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > ,
259+ ) : ModelQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > ;
256260
257- useSuspenseFindMany < T extends FindManyArgs < Schema , Model , Options , { } , { } > > (
258- args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , { } > > ,
259- options ?: ModelSuspenseQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > ,
260- ) : ModelSuspenseQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > ;
261+ useSuspenseFindMany < T extends FindManyArgs < Schema , Model , Options , { } , ExtResult > > (
262+ args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , ExtResult > > ,
263+ options ?: ModelSuspenseQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > ,
264+ ) : ModelSuspenseQueryResult < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > ;
261265
262- useInfiniteFindMany < T extends FindManyArgs < Schema , Model , Options , { } , { } > > (
263- args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , { } > > ,
264- options ?: ModelInfiniteQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > ,
265- ) : ModelInfiniteQueryResult < InfiniteData < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > > ;
266+ useInfiniteFindMany < T extends FindManyArgs < Schema , Model , Options , { } , ExtResult > > (
267+ args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , ExtResult > > ,
268+ options ?: ModelInfiniteQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > ,
269+ ) : ModelInfiniteQueryResult < InfiniteData < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > > ;
266270
267- useSuspenseInfiniteFindMany < T extends FindManyArgs < Schema , Model , Options , { } , { } > > (
268- args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , { } > > ,
269- options ?: ModelSuspenseInfiniteQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > ,
270- ) : ModelSuspenseInfiniteQueryResult < InfiniteData < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] > > ;
271+ useSuspenseInfiniteFindMany < T extends FindManyArgs < Schema , Model , Options , { } , ExtResult > > (
272+ args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , { } , ExtResult > > ,
273+ options ?: ModelSuspenseInfiniteQueryOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > ,
274+ ) : ModelSuspenseInfiniteQueryResult < InfiniteData < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] > > ;
271275
272- useCreate < T extends CreateArgs < Schema , Model , Options , { } , { } > > (
273- options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > , T > ,
274- ) : ModelMutationModelResult < Schema , Model , T , false , Options > ;
276+ useCreate < T extends CreateArgs < Schema , Model , Options , { } , ExtResult > > (
277+ options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > , T > ,
278+ ) : ModelMutationModelResult < Schema , Model , T , false , Options , ExtResult > ;
275279
276280 useCreateMany < T extends CreateManyArgs < Schema , Model > > (
277281 options ?: ModelMutationOptions < BatchResult , T > ,
278282 ) : ModelMutationResult < BatchResult , T > ;
279283
280- useCreateManyAndReturn < T extends CreateManyAndReturnArgs < Schema , Model , Options , { } , { } > > (
281- options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] , T > ,
282- ) : ModelMutationModelResult < Schema , Model , T , true , Options > ;
284+ useCreateManyAndReturn < T extends CreateManyAndReturnArgs < Schema , Model , Options , { } , ExtResult > > (
285+ options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] , T > ,
286+ ) : ModelMutationModelResult < Schema , Model , T , true , Options , ExtResult > ;
283287
284- useUpdate < T extends UpdateArgs < Schema , Model , Options , { } , { } > > (
285- options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > , T > ,
286- ) : ModelMutationModelResult < Schema , Model , T , false , Options > ;
288+ useUpdate < T extends UpdateArgs < Schema , Model , Options , { } , ExtResult > > (
289+ options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > , T > ,
290+ ) : ModelMutationModelResult < Schema , Model , T , false , Options , ExtResult > ;
287291
288292 useUpdateMany < T extends UpdateManyArgs < Schema , Model , Options > > (
289293 options ?: ModelMutationOptions < BatchResult , T > ,
290294 ) : ModelMutationResult < BatchResult , T > ;
291295
292- useUpdateManyAndReturn < T extends UpdateManyAndReturnArgs < Schema , Model , Options , { } , { } > > (
293- options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > [ ] , T > ,
294- ) : ModelMutationModelResult < Schema , Model , T , true , Options > ;
296+ useUpdateManyAndReturn < T extends UpdateManyAndReturnArgs < Schema , Model , Options , { } , ExtResult > > (
297+ options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > [ ] , T > ,
298+ ) : ModelMutationModelResult < Schema , Model , T , true , Options , ExtResult > ;
295299
296- useUpsert < T extends UpsertArgs < Schema , Model , Options , { } , { } > > (
297- options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > , T > ,
298- ) : ModelMutationModelResult < Schema , Model , T , false , Options > ;
300+ useUpsert < T extends UpsertArgs < Schema , Model , Options , { } , ExtResult > > (
301+ options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > , T > ,
302+ ) : ModelMutationModelResult < Schema , Model , T , false , Options , ExtResult > ;
299303
300- useDelete < T extends DeleteArgs < Schema , Model , Options , { } , { } > > (
301- options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , { } > , T > ,
302- ) : ModelMutationModelResult < Schema , Model , T , false , Options > ;
304+ useDelete < T extends DeleteArgs < Schema , Model , Options , { } , ExtResult > > (
305+ options ?: ModelMutationOptions < SimplifiedPlainResult < Schema , Model , T , Options , ExtResult > , T > ,
306+ ) : ModelMutationModelResult < Schema , Model , T , false , Options , ExtResult > ;
303307
304308 useDeleteMany < T extends DeleteManyArgs < Schema , Model , Options > > (
305309 options ?: ModelMutationOptions < BatchResult , T > ,
@@ -361,7 +365,7 @@ export function useClientQueries<
361365> (
362366 schema : InferSchema < SchemaOrClient > ,
363367 options ?: QueryContext ,
364- ) : ClientHooks < InferSchema < SchemaOrClient > , InferOptions < SchemaOrClient , InferSchema < SchemaOrClient > > > {
368+ ) : ClientHooks < InferSchema < SchemaOrClient > , InferOptions < SchemaOrClient , InferSchema < SchemaOrClient > > , InferExtResult < SchemaOrClient > extends ExtResultBase < InferSchema < SchemaOrClient > > ? InferExtResult < SchemaOrClient > : { } > {
365369 const result = Object . keys ( schema . models ) . reduce (
366370 ( acc , model ) => {
367371 ( acc as any ) [ lowerCaseFirst ( model ) ] = useModelQueries (
@@ -428,7 +432,8 @@ export function useModelQueries<
428432 Schema extends SchemaDef ,
429433 Model extends GetModels < Schema > ,
430434 Options extends QueryOptions < Schema > ,
431- > ( schema : Schema , model : Model , rootOptions ?: QueryContext ) : ModelQueryHooks < Schema , Model , Options > {
435+ ExtResult extends ExtResultBase < Schema > = { } ,
436+ > ( schema : Schema , model : Model , rootOptions ?: QueryContext ) : ModelQueryHooks < Schema , Model , Options , ExtResult > {
432437 const modelDef = Object . values ( schema . models ) . find ( ( m ) => m . name . toLowerCase ( ) === model . toLowerCase ( ) ) ;
433438 if ( ! modelDef ) {
434439 throw new Error ( `Model "${ model } " not found in schema` ) ;
@@ -538,7 +543,7 @@ export function useModelQueries<
538543 useSuspenseGroupBy : ( args : any , options ?: any ) => {
539544 return useInternalSuspenseQuery ( schema , modelName , 'groupBy' , args , { ...rootOptions , ...options } ) ;
540545 } ,
541- } as ModelQueryHooks < Schema , Model , Options > ;
546+ } as ModelQueryHooks < Schema , Model , Options , ExtResult > ;
542547}
543548
544549export function useInternalQuery < TQueryFnData , TData > (
0 commit comments