@@ -15,21 +15,13 @@ declare module 'astro:content' {
1515 [ key : string ] : unknown ;
1616 } ;
1717 }
18- }
1918
20- declare module 'astro:content' {
2119 type Flatten < T > = T extends { [ K : string ] : infer U } ? U : never ;
2220
23- export type CollectionKey = keyof AnyEntryMap ;
24- export type CollectionEntry < C extends CollectionKey > = Flatten < AnyEntryMap [ C ] > ;
25-
26- export type ContentCollectionKey = keyof ContentEntryMap ;
27- export type DataCollectionKey = keyof DataEntryMap ;
21+ export type CollectionKey = keyof DataEntryMap ;
22+ export type CollectionEntry < C extends CollectionKey > = Flatten < DataEntryMap [ C ] > ;
2823
2924 type AllValuesOf < T > = T extends any ? T [ keyof T ] : never ;
30- type ValidContentEntrySlug < C extends keyof ContentEntryMap > = AllValuesOf <
31- ContentEntryMap [ C ]
32- > [ 'slug' ] ;
3325
3426 export type ReferenceDataEntry <
3527 C extends CollectionKey ,
@@ -38,41 +30,17 @@ declare module 'astro:content' {
3830 collection : C ;
3931 id : E ;
4032 } ;
41- export type ReferenceContentEntry <
42- C extends keyof ContentEntryMap ,
43- E extends ValidContentEntrySlug < C > | ( string & { } ) = string ,
44- > = {
45- collection : C ;
46- slug : E ;
47- } ;
33+
4834 export type ReferenceLiveEntry < C extends keyof LiveContentConfig [ 'collections' ] > = {
4935 collection : C ;
5036 id : string ;
5137 } ;
5238
53- /** @deprecated Use `getEntry` instead. */
54- export function getEntryBySlug <
55- C extends keyof ContentEntryMap ,
56- E extends ValidContentEntrySlug < C > | ( string & { } ) ,
57- > (
58- collection : C ,
59- // Note that this has to accept a regular string too, for SSR
60- entrySlug : E ,
61- ) : E extends ValidContentEntrySlug < C >
62- ? Promise < CollectionEntry < C > >
63- : Promise < CollectionEntry < C > | undefined > ;
64-
65- /** @deprecated Use `getEntry` instead. */
66- export function getDataEntryById < C extends keyof DataEntryMap , E extends keyof DataEntryMap [ C ] > (
67- collection : C ,
68- entryId : E ,
69- ) : Promise < CollectionEntry < C > > ;
70-
71- export function getCollection < C extends keyof AnyEntryMap , E extends CollectionEntry < C > > (
39+ export function getCollection < C extends keyof DataEntryMap , E extends CollectionEntry < C > > (
7240 collection : C ,
7341 filter ?: ( entry : CollectionEntry < C > ) => entry is E ,
7442 ) : Promise < E [ ] > ;
75- export function getCollection < C extends keyof AnyEntryMap > (
43+ export function getCollection < C extends keyof DataEntryMap > (
7644 collection : C ,
7745 filter ?: ( entry : CollectionEntry < C > ) => unknown ,
7846 ) : Promise < CollectionEntry < C > [ ] > ;
@@ -84,14 +52,6 @@ declare module 'astro:content' {
8452 import ( 'astro' ) . LiveDataCollectionResult < LiveLoaderDataType < C > , LiveLoaderErrorType < C > >
8553 > ;
8654
87- export function getEntry <
88- C extends keyof ContentEntryMap ,
89- E extends ValidContentEntrySlug < C > | ( string & { } ) ,
90- > (
91- entry : ReferenceContentEntry < C , E > ,
92- ) : E extends ValidContentEntrySlug < C >
93- ? Promise < CollectionEntry < C > >
94- : Promise < CollectionEntry < C > | undefined > ;
9555 export function getEntry <
9656 C extends keyof DataEntryMap ,
9757 E extends keyof DataEntryMap [ C ] | ( string & { } ) ,
@@ -100,15 +60,6 @@ declare module 'astro:content' {
10060 ) : E extends keyof DataEntryMap [ C ]
10161 ? Promise < DataEntryMap [ C ] [ E ] >
10262 : Promise < CollectionEntry < C > | undefined > ;
103- export function getEntry <
104- C extends keyof ContentEntryMap ,
105- E extends ValidContentEntrySlug < C > | ( string & { } ) ,
106- > (
107- collection : C ,
108- slug : E ,
109- ) : E extends ValidContentEntrySlug < C >
110- ? Promise < CollectionEntry < C > >
111- : Promise < CollectionEntry < C > | undefined > ;
11263 export function getEntry <
11364 C extends keyof DataEntryMap ,
11465 E extends keyof DataEntryMap [ C ] | ( string & { } ) ,
@@ -126,47 +77,52 @@ declare module 'astro:content' {
12677 ) : Promise < import ( 'astro' ) . LiveDataEntryResult < LiveLoaderDataType < C > , LiveLoaderErrorType < C > > > ;
12778
12879 /** Resolve an array of entry references from the same collection */
129- export function getEntries < C extends keyof ContentEntryMap > (
130- entries : ReferenceContentEntry < C , ValidContentEntrySlug < C > > [ ] ,
131- ) : Promise < CollectionEntry < C > [ ] > ;
13280 export function getEntries < C extends keyof DataEntryMap > (
13381 entries : ReferenceDataEntry < C , keyof DataEntryMap [ C ] > [ ] ,
13482 ) : Promise < CollectionEntry < C > [ ] > ;
13583
136- export function render < C extends keyof AnyEntryMap > (
137- entry : AnyEntryMap [ C ] [ string ] ,
84+ export function render < C extends keyof DataEntryMap > (
85+ entry : DataEntryMap [ C ] [ string ] ,
13886 ) : Promise < RenderResult > ;
13987
140- export function reference < C extends keyof AnyEntryMap > (
88+ export function reference <
89+ C extends
90+ | keyof DataEntryMap
91+ // Allow generic `string` to avoid excessive type errors in the config
92+ // if `dev` is not running to update as you edit.
93+ // Invalid collection names will be caught at build time.
94+ | ( string & { } ) ,
95+ > (
14196 collection : C ,
142- ) : import ( 'astro/zod' ) . ZodEffects <
97+ ) : import ( 'astro/zod' ) . ZodPipe <
14398 import ( 'astro/zod' ) . ZodString ,
144- C extends keyof ContentEntryMap
145- ? ReferenceContentEntry < C , ValidContentEntrySlug < C > >
146- : ReferenceDataEntry < C , keyof DataEntryMap [ C ] >
99+ import ( 'astro/zod' ) . ZodTransform <
100+ C extends keyof DataEntryMap
101+ ? {
102+ collection : C ;
103+ id : string ;
104+ }
105+ : never ,
106+ string
107+ >
147108 > ;
148- // Allow generic `string` to avoid excessive type errors in the config
149- // if `dev` is not running to update as you edit.
150- // Invalid collection names will be caught at build time.
151- export function reference < C extends string > (
152- collection : C ,
153- ) : import ( 'astro/zod' ) . ZodEffects < import ( 'astro/zod' ) . ZodString , never > ;
154109
155110 type ReturnTypeOrOriginal < T > = T extends ( ...args : any [ ] ) = > infer R ? R : T ;
156- type InferEntrySchema < C extends keyof AnyEntryMap > = import ( 'astro/zod' ) . infer <
111+ type InferEntrySchema < C extends keyof DataEntryMap > = import ( 'astro/zod' ) . infer <
157112 ReturnTypeOrOriginal < Required < ContentConfig [ 'collections' ] [ C ] > [ 'schema' ] >
158113 > ;
159-
160- type ContentEntryMap = {
161-
162- } ;
114+ type ExtractLoaderConfig < T > = T extends { loader : infer L } ? L : never ;
115+ type InferLoaderSchema <
116+ C extends keyof DataEntryMap ,
117+ L = ExtractLoaderConfig < ContentConfig [ 'collections' ] [ C ] > ,
118+ > = L extends { schema : import ( 'astro/zod' ) . ZodSchema }
119+ ? import ( 'astro/zod' ) . infer < L [ 'schema' ] >
120+ : any ;
163121
164122 type DataEntryMap = {
165123
166124 } ;
167125
168- type AnyEntryMap = ContentEntryMap & DataEntryMap ;
169-
170126 type ExtractLoaderTypes < T > = T extends import ( 'astro/loaders' ) . LiveLoader <
171127 infer TData ,
172128 infer TEntryFilter ,
@@ -175,10 +131,10 @@ declare module 'astro:content' {
175131 >
176132 ? { data : TData ; entryFilter : TEntryFilter ; collectionFilter : TCollectionFilter ; error : TError }
177133 : { data : never ; entryFilter : never ; collectionFilter : never ; error : never } ;
178- type ExtractDataType < T > = ExtractLoaderTypes < T > [ 'data' ] ;
179134 type ExtractEntryFilterType < T > = ExtractLoaderTypes < T > [ 'entryFilter' ] ;
180135 type ExtractCollectionFilterType < T > = ExtractLoaderTypes < T > [ 'collectionFilter' ] ;
181136 type ExtractErrorType < T > = ExtractLoaderTypes < T > [ 'error' ] ;
137+ type ExtractDataType < T > = ExtractLoaderTypes < T > [ 'data' ] ;
182138
183139 type LiveLoaderDataType < C extends keyof LiveContentConfig [ 'collections' ] > =
184140 LiveContentConfig [ 'collections' ] [ C ] [ 'schema' ] extends undefined
@@ -194,6 +150,6 @@ declare module 'astro:content' {
194150 LiveContentConfig [ 'collections' ] [ C ] [ 'loader' ]
195151 > ;
196152
197- export type ContentConfig = typeof import ( "./../src/content.config.mjs" ) ;
153+ export type ContentConfig = never ;
198154 export type LiveContentConfig = never ;
199155}
0 commit comments