11import type { Many , Table , TableRelationalConfig } from 'drizzle-orm'
2- import type { ConditionalExcept , Simplify , ValueOf } from 'type-fest'
2+ import type { ConditionalExcept , Simplify , UnionToIntersection , ValueOf } from 'type-fest'
33import z from 'zod'
44
55import type { MinimalContext } from './config'
@@ -421,7 +421,7 @@ export type CollectionConfig<
421421 TSlug extends string = string ,
422422 TContext extends MinimalContext = MinimalContext ,
423423 TFields extends FieldsInitial < TContext > = FieldsInitial < TContext > ,
424- TAppRouter extends ApiRouter < TContext > = ApiRouter < TContext > ,
424+ TAppRouter extends ApiRouter < TContext > = { } ,
425425> = {
426426 slug : TSlug
427427 primaryField : Extract < keyof TFields , string >
@@ -435,7 +435,7 @@ export type Collection<
435435 TFullSchema extends Record < string , unknown > = Record < string , unknown > ,
436436 TContext extends MinimalContext = MinimalContext ,
437437 TFields extends Fields < TContext > = Fields < TContext > ,
438- TApiRouter extends ApiRouter < TContext > = ApiRouter < TContext > ,
438+ TApiRouter extends ApiRouter < TContext > = { } ,
439439> = {
440440 _ : {
441441 table : TFullSchema [ TTableName ] extends Table < any > ? TFullSchema [ TTableName ] : never
@@ -520,30 +520,31 @@ export type GetAllTableTsNames<TFullSchema extends Record<string, unknown>> = Ex
520520export type ExtractCollectionCustomEndpoints <
521521 TCollection extends Collection < any , any , any , any , any , any > ,
522522> = TCollection [ 'admin' ] [ 'endpoints' ] extends infer TEndpoints
523- ? TEndpoints extends Record < string , ApiRouteSchema >
523+ ? TEndpoints extends Record < string , ApiRoute < any , any > >
524524 ? {
525- [ TEndpoint in Extract <
526- keyof TEndpoints ,
527- string
528- > as `${TCollection [ 'slug' ] } .${TEndpoint } `] : TEndpoints [ TEndpoint ]
525+ [ TEndpoint in keyof TEndpoints as TEndpoints [ TEndpoint ] [ 'schema' ] extends ApiRouteSchema
526+ ? `${TCollection [ 'slug' ] } .${TEndpoint extends string ? TEndpoint : never } `
527+ : never ] : TEndpoints [ TEndpoint ]
529528 }
530529 : never
531530 : never
532531
533532export type ExtractAllCollectionCustomEndpoints <
534533 TCollections extends Record < string , Collection < any , any , any , any , any , any > > ,
535- > = ValueOf < {
536- [ TCollectionIndex in keyof TCollections ] : TCollections [ TCollectionIndex ] extends Collection <
537- any ,
538- any ,
539- any ,
540- any ,
541- any ,
542- any
543- >
544- ? ExtractCollectionCustomEndpoints < TCollections [ TCollectionIndex ] >
545- : { }
546- } >
534+ > = UnionToIntersection <
535+ ValueOf < {
536+ [ TCollectionIndex in keyof TCollections ] : TCollections [ TCollectionIndex ] extends Collection <
537+ any ,
538+ any ,
539+ any ,
540+ any ,
541+ any ,
542+ any
543+ >
544+ ? ExtractCollectionCustomEndpoints < TCollections [ TCollectionIndex ] >
545+ : { }
546+ } >
547+ >
547548
548549type SuccessResponse < TFunc extends ( ...args : any ) => any > = ToZodObject < Awaited < ReturnType < TFunc > > >
549550
@@ -619,18 +620,20 @@ export type ExtractCollectionDefaultEndpoints<
619620
620621export type ExtractAllCollectionDefaultEndpoints <
621622 TCollections extends Record < string , Collection < any , any , any , any , any , any > > ,
622- > = ValueOf < {
623- [ TCollectionIndex in keyof TCollections ] : TCollections [ TCollectionIndex ] extends Collection <
624- any ,
625- any ,
626- any ,
627- any ,
628- any ,
629- any
630- >
631- ? ExtractCollectionDefaultEndpoints < TCollections [ TCollectionIndex ] >
632- : { }
633- } >
623+ > = UnionToIntersection <
624+ ValueOf < {
625+ [ TCollectionIndex in keyof TCollections ] : TCollections [ TCollectionIndex ] extends Collection <
626+ any ,
627+ any ,
628+ any ,
629+ any ,
630+ any ,
631+ any
632+ >
633+ ? ExtractCollectionDefaultEndpoints < TCollections [ TCollectionIndex ] >
634+ : { }
635+ } >
636+ >
634637
635638export function getAllCollectionEndpoints <
636639 TCollections extends Record < string , Collection < any , any , any , any , any , any > > ,
0 commit comments