@@ -56,6 +56,10 @@ declare module 'astro:content' {
56
56
collection : C ;
57
57
slug : E ;
58
58
} ;
59
+ export type ReferenceLiveEntry < C extends keyof LiveContentConfig [ 'collections' ] > = {
60
+ collection : C ;
61
+ id : string ;
62
+ } ;
59
63
60
64
/** @deprecated Use `getEntry` instead. */
61
65
export function getEntryBySlug <
@@ -84,6 +88,13 @@ declare module 'astro:content' {
84
88
filter ?: ( entry : CollectionEntry < C > ) => unknown ,
85
89
) : Promise < CollectionEntry < C > [ ] > ;
86
90
91
+ export function getLiveCollection < C extends keyof LiveContentConfig [ 'collections' ] > (
92
+ collection : C ,
93
+ filter ?: LiveLoaderCollectionFilterType < C > ,
94
+ ) : Promise <
95
+ import ( 'astro' ) . LiveDataCollectionResult < LiveLoaderDataType < C > , LiveLoaderErrorType < C > >
96
+ > ;
97
+
87
98
export function getEntry <
88
99
C extends keyof ContentEntryMap ,
89
100
E extends ValidContentEntrySlug < C > | ( string & { } ) ,
@@ -120,6 +131,10 @@ declare module 'astro:content' {
120
131
? Promise < DataEntryMap [ C ] [ E ] > | undefined
121
132
: Promise < DataEntryMap [ C ] [ E ] >
122
133
: Promise < CollectionEntry < C > | undefined > ;
134
+ export function getLiveEntry < C extends keyof LiveContentConfig [ 'collections' ] > (
135
+ collection : C ,
136
+ filter : string | LiveLoaderEntryFilterType < C > ,
137
+ ) : Promise < import ( 'astro' ) . LiveDataEntryResult < LiveLoaderDataType < C > , LiveLoaderErrorType < C > > > ;
123
138
124
139
/** Resolve an array of entry references from the same collection */
125
140
export function getEntries < C extends keyof ContentEntryMap > (
@@ -187,5 +202,33 @@ declare module 'astro:content' {
187
202
188
203
type AnyEntryMap = ContentEntryMap & DataEntryMap ;
189
204
205
+ type ExtractLoaderTypes < T > = T extends import ( 'astro/loaders' ) . LiveLoader <
206
+ infer TData ,
207
+ infer TEntryFilter ,
208
+ infer TCollectionFilter ,
209
+ infer TError
210
+ >
211
+ ? { data : TData ; entryFilter : TEntryFilter ; collectionFilter : TCollectionFilter ; error : TError }
212
+ : { data : never ; entryFilter : never ; collectionFilter : never ; error : never } ;
213
+ type ExtractDataType < T > = ExtractLoaderTypes < T > [ 'data' ] ;
214
+ type ExtractEntryFilterType < T > = ExtractLoaderTypes < T > [ 'entryFilter' ] ;
215
+ type ExtractCollectionFilterType < T > = ExtractLoaderTypes < T > [ 'collectionFilter' ] ;
216
+ type ExtractErrorType < T > = ExtractLoaderTypes < T > [ 'error' ] ;
217
+
218
+ type LiveLoaderDataType < C extends keyof LiveContentConfig [ 'collections' ] > =
219
+ LiveContentConfig [ 'collections' ] [ C ] [ 'schema' ] extends undefined
220
+ ? ExtractDataType < LiveContentConfig [ 'collections' ] [ C ] [ 'loader' ] >
221
+ : import ( 'astro/zod' ) . infer <
222
+ Exclude < LiveContentConfig [ 'collections' ] [ C ] [ 'schema' ] , undefined >
223
+ > ;
224
+ type LiveLoaderEntryFilterType < C extends keyof LiveContentConfig [ 'collections' ] > =
225
+ ExtractEntryFilterType < LiveContentConfig [ 'collections' ] [ C ] [ 'loader' ] > ;
226
+ type LiveLoaderCollectionFilterType < C extends keyof LiveContentConfig [ 'collections' ] > =
227
+ ExtractCollectionFilterType < LiveContentConfig [ 'collections' ] [ C ] [ 'loader' ] > ;
228
+ type LiveLoaderErrorType < C extends keyof LiveContentConfig [ 'collections' ] > = ExtractErrorType <
229
+ LiveContentConfig [ 'collections' ] [ C ] [ 'loader' ]
230
+ > ;
231
+
190
232
export type ContentConfig = typeof import ( "../src/content.config.js" ) ;
233
+ export type LiveContentConfig = never ;
191
234
}
0 commit comments