@@ -3,12 +3,13 @@ import type { ConditionalExcept, Simplify, UnionToIntersection, ValueOf } from '
33import z from 'zod'
44
55import type { MinimalContext } from './config'
6- import type {
7- ApiRoute ,
8- ApiRouteHandler ,
9- ApiRouter ,
10- ApiRouteSchema ,
11- ClientApiRouter ,
6+ import {
7+ type ApiRoute ,
8+ type ApiRouteHandler ,
9+ type ApiRouter ,
10+ type ApiRouteSchema ,
11+ type ClientApiRouter ,
12+ createEndpoint ,
1213} from './endpoint'
1314import {
1415 type Field ,
@@ -23,7 +24,7 @@ import {
2324 fieldsToZodObject ,
2425 type FieldsWithFieldName ,
2526} from './field'
26- import type { GetTableByTableTsName , ToZodObject } from './utils'
27+ import { type GetTableByTableTsName , type ToZodObject } from './utils'
2728
2829type SimplifyConditionalExcept < Base , Condition > = Simplify < ConditionalExcept < Base , Condition > >
2930
@@ -724,7 +725,10 @@ export function getAllCollectionEndpoints<
724725 return { status : 200 , body : response }
725726 }
726727
727- return [ endpointName , { schema, handler } satisfies ApiRoute < any , typeof schema > ]
728+ return [
729+ endpointName ,
730+ createEndpoint ( schema , handler ) satisfies ApiRoute < any , typeof schema > ,
731+ ]
728732 }
729733 case ApiDefaultMethod . FIND_ONE : {
730734 const response = fieldsToZodObject ( fields )
@@ -752,10 +756,18 @@ export function getAllCollectionEndpoints<
752756 return { status : 200 , body : response }
753757 }
754758
755- return [ endpointName , { schema, handler } satisfies ApiRoute < any , typeof schema > ]
759+ return [
760+ endpointName ,
761+ createEndpoint ( schema , handler ) satisfies ApiRoute < any , typeof schema > ,
762+ ]
756763 }
757764 case ApiDefaultMethod . FIND_MANY : {
758- const response = fieldsToZodObject ( fields )
765+ const body = fieldsToZodObject ( fields )
766+ const response = z . object ( {
767+ data : z . array ( body ) ,
768+ total : z . number ( ) ,
769+ page : z . number ( ) ,
770+ } )
759771
760772 const schema = {
761773 path : `/api/${ collection . slug } /${ method } ` ,
@@ -786,7 +798,10 @@ export function getAllCollectionEndpoints<
786798 return { status : 200 , body : response }
787799 }
788800
789- return [ endpointName , { schema, handler } satisfies ApiRoute < any , typeof schema > ]
801+ return [
802+ endpointName ,
803+ createEndpoint ( schema , handler ) satisfies ApiRoute < any , typeof schema > ,
804+ ]
790805 }
791806 case ApiDefaultMethod . UPDATE : {
792807 const body = fieldsToZodObject ( fields )
@@ -820,7 +835,10 @@ export function getAllCollectionEndpoints<
820835 return { status : 200 , body : response }
821836 }
822837
823- return [ endpointName , { schema, handler } satisfies ApiRoute < any , typeof schema > ]
838+ return [
839+ endpointName ,
840+ createEndpoint ( schema , handler ) satisfies ApiRoute < any , typeof schema > ,
841+ ]
824842 }
825843 case ApiDefaultMethod . DELETE : {
826844 const schema = {
@@ -846,7 +864,10 @@ export function getAllCollectionEndpoints<
846864 return { status : 200 , body : { message : 'ok' } }
847865 }
848866
849- return [ endpointName , { schema, handler } satisfies ApiRoute < any , typeof schema > ]
867+ return [
868+ endpointName ,
869+ createEndpoint ( schema , handler ) satisfies ApiRoute < any , typeof schema > ,
870+ ]
850871 }
851872 default :
852873 throw new Error ( `Unknown method: ${ method } ` )
0 commit comments