|
1 | | -declare module 'astro:content' { |
2 | | - export interface RenderResult { |
3 | | - Content: import('astro/runtime/server/index.js').AstroComponentFactory; |
4 | | - headings: import('astro').MarkdownHeading[]; |
5 | | - remarkPluginFrontmatter: Record<string, any>; |
6 | | - } |
7 | | - interface Render { |
8 | | - '.md': Promise<RenderResult>; |
9 | | - } |
10 | | - |
11 | | - export interface RenderedContent { |
12 | | - html: string; |
13 | | - metadata?: { |
14 | | - imagePaths: Array<string>; |
15 | | - [key: string]: unknown; |
16 | | - }; |
17 | | - } |
18 | | - |
19 | | - type Flatten<T> = T extends { [K: string]: infer U } ? U : never; |
20 | | - |
21 | | - export type CollectionKey = keyof DataEntryMap; |
22 | | - export type CollectionEntry<C extends CollectionKey> = Flatten<DataEntryMap[C]>; |
23 | | - |
24 | | - type AllValuesOf<T> = T extends any ? T[keyof T] : never; |
25 | | - |
26 | | - export type ReferenceDataEntry< |
27 | | - C extends CollectionKey, |
28 | | - E extends keyof DataEntryMap[C] = string, |
29 | | - > = { |
30 | | - collection: C; |
31 | | - id: E; |
32 | | - }; |
33 | | - |
34 | | - export type ReferenceLiveEntry<C extends keyof LiveContentConfig['collections']> = { |
35 | | - collection: C; |
36 | | - id: string; |
37 | | - }; |
38 | | - |
39 | | - export function getCollection<C extends keyof DataEntryMap, E extends CollectionEntry<C>>( |
40 | | - collection: C, |
41 | | - filter?: (entry: CollectionEntry<C>) => entry is E, |
42 | | - ): Promise<E[]>; |
43 | | - export function getCollection<C extends keyof DataEntryMap>( |
44 | | - collection: C, |
45 | | - filter?: (entry: CollectionEntry<C>) => unknown, |
46 | | - ): Promise<CollectionEntry<C>[]>; |
47 | | - |
48 | | - export function getLiveCollection<C extends keyof LiveContentConfig['collections']>( |
49 | | - collection: C, |
50 | | - filter?: LiveLoaderCollectionFilterType<C>, |
51 | | - ): Promise< |
52 | | - import('astro').LiveDataCollectionResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>> |
53 | | - >; |
54 | | - |
55 | | - export function getEntry< |
56 | | - C extends keyof DataEntryMap, |
57 | | - E extends keyof DataEntryMap[C] | (string & {}), |
58 | | - >( |
59 | | - entry: ReferenceDataEntry<C, E>, |
60 | | - ): E extends keyof DataEntryMap[C] |
61 | | - ? Promise<DataEntryMap[C][E]> |
62 | | - : Promise<CollectionEntry<C> | undefined>; |
63 | | - export function getEntry< |
64 | | - C extends keyof DataEntryMap, |
65 | | - E extends keyof DataEntryMap[C] | (string & {}), |
66 | | - >( |
67 | | - collection: C, |
68 | | - id: E, |
69 | | - ): E extends keyof DataEntryMap[C] |
70 | | - ? string extends keyof DataEntryMap[C] |
71 | | - ? Promise<DataEntryMap[C][E]> | undefined |
72 | | - : Promise<DataEntryMap[C][E]> |
73 | | - : Promise<CollectionEntry<C> | undefined>; |
74 | | - export function getLiveEntry<C extends keyof LiveContentConfig['collections']>( |
75 | | - collection: C, |
76 | | - filter: string | LiveLoaderEntryFilterType<C>, |
77 | | - ): Promise<import('astro').LiveDataEntryResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>>; |
78 | | - |
79 | | - /** Resolve an array of entry references from the same collection */ |
80 | | - export function getEntries<C extends keyof DataEntryMap>( |
81 | | - entries: ReferenceDataEntry<C, keyof DataEntryMap[C]>[], |
82 | | - ): Promise<CollectionEntry<C>[]>; |
83 | | - |
84 | | - export function render<C extends keyof DataEntryMap>( |
85 | | - entry: DataEntryMap[C][string], |
86 | | - ): Promise<RenderResult>; |
87 | | - |
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 | | - >( |
96 | | - collection: C, |
97 | | - ): import('astro/zod').ZodPipe< |
98 | | - import('astro/zod').ZodString, |
99 | | - import('astro/zod').ZodTransform< |
100 | | - C extends keyof DataEntryMap |
101 | | - ? { |
102 | | - collection: C; |
103 | | - id: string; |
104 | | - } |
105 | | - : never, |
106 | | - string |
107 | | - > |
108 | | - >; |
109 | | - |
110 | | - type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T; |
111 | | - type InferEntrySchema<C extends keyof DataEntryMap> = import('astro/zod').infer< |
112 | | - ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']> |
113 | | - >; |
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; |
121 | | - |
122 | | - type DataEntryMap = { |
123 | | - |
124 | | - }; |
125 | | - |
126 | | - type ExtractLoaderTypes<T> = T extends import('astro/loaders').LiveLoader< |
127 | | - infer TData, |
128 | | - infer TEntryFilter, |
129 | | - infer TCollectionFilter, |
130 | | - infer TError |
131 | | - > |
132 | | - ? { data: TData; entryFilter: TEntryFilter; collectionFilter: TCollectionFilter; error: TError } |
133 | | - : { data: never; entryFilter: never; collectionFilter: never; error: never }; |
134 | | - type ExtractEntryFilterType<T> = ExtractLoaderTypes<T>['entryFilter']; |
135 | | - type ExtractCollectionFilterType<T> = ExtractLoaderTypes<T>['collectionFilter']; |
136 | | - type ExtractErrorType<T> = ExtractLoaderTypes<T>['error']; |
137 | | - |
138 | | - type LiveLoaderDataType<C extends keyof LiveContentConfig['collections']> = |
139 | | - LiveContentConfig['collections'][C]['schema'] extends undefined |
140 | | - ? ExtractDataType<LiveContentConfig['collections'][C]['loader']> |
141 | | - : import('astro/zod').infer< |
142 | | - Exclude<LiveContentConfig['collections'][C]['schema'], undefined> |
143 | | - >; |
144 | | - type LiveLoaderEntryFilterType<C extends keyof LiveContentConfig['collections']> = |
145 | | - ExtractEntryFilterType<LiveContentConfig['collections'][C]['loader']>; |
146 | | - type LiveLoaderCollectionFilterType<C extends keyof LiveContentConfig['collections']> = |
147 | | - ExtractCollectionFilterType<LiveContentConfig['collections'][C]['loader']>; |
148 | | - type LiveLoaderErrorType<C extends keyof LiveContentConfig['collections']> = ExtractErrorType< |
149 | | - LiveContentConfig['collections'][C]['loader'] |
150 | | - >; |
151 | | - |
152 | | - export type ContentConfig = never; |
153 | | - export type LiveContentConfig = never; |
| 1 | +declare module "astro:content" { |
| 2 | + export interface RenderResult { |
| 3 | + Content: import("astro/runtime/server/index.js").AstroComponentFactory; |
| 4 | + headings: import("astro").MarkdownHeading[]; |
| 5 | + remarkPluginFrontmatter: Record<string, any>; |
| 6 | + } |
| 7 | + interface Render { |
| 8 | + ".md": Promise<RenderResult>; |
| 9 | + } |
| 10 | + |
| 11 | + export interface RenderedContent { |
| 12 | + html: string; |
| 13 | + metadata?: { |
| 14 | + imagePaths: Array<string>; |
| 15 | + [key: string]: unknown; |
| 16 | + }; |
| 17 | + } |
| 18 | + |
| 19 | + type Flatten<T> = T extends { [K: string]: infer U } ? U : never; |
| 20 | + |
| 21 | + export type CollectionKey = keyof DataEntryMap; |
| 22 | + export type CollectionEntry<C extends CollectionKey> = Flatten<DataEntryMap[C]>; |
| 23 | + |
| 24 | + type AllValuesOf<T> = T extends any ? T[keyof T] : never; |
| 25 | + |
| 26 | + export type ReferenceDataEntry< |
| 27 | + C extends CollectionKey, |
| 28 | + E extends keyof DataEntryMap[C] = string, |
| 29 | + > = { |
| 30 | + collection: C; |
| 31 | + id: E; |
| 32 | + }; |
| 33 | + |
| 34 | + export type ReferenceLiveEntry<C extends keyof LiveContentConfig["collections"]> = { |
| 35 | + collection: C; |
| 36 | + id: string; |
| 37 | + }; |
| 38 | + |
| 39 | + export function getCollection<C extends keyof DataEntryMap, E extends CollectionEntry<C>>( |
| 40 | + collection: C, |
| 41 | + filter?: (entry: CollectionEntry<C>) => entry is E, |
| 42 | + ): Promise<E[]>; |
| 43 | + export function getCollection<C extends keyof DataEntryMap>( |
| 44 | + collection: C, |
| 45 | + filter?: (entry: CollectionEntry<C>) => unknown, |
| 46 | + ): Promise<CollectionEntry<C>[]>; |
| 47 | + |
| 48 | + export function getLiveCollection<C extends keyof LiveContentConfig["collections"]>( |
| 49 | + collection: C, |
| 50 | + filter?: LiveLoaderCollectionFilterType<C>, |
| 51 | + ): Promise< |
| 52 | + import("astro").LiveDataCollectionResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>> |
| 53 | + >; |
| 54 | + |
| 55 | + export function getEntry< |
| 56 | + C extends keyof DataEntryMap, |
| 57 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 58 | + >( |
| 59 | + entry: ReferenceDataEntry<C, E>, |
| 60 | + ): E extends keyof DataEntryMap[C] |
| 61 | + ? Promise<DataEntryMap[C][E]> |
| 62 | + : Promise<CollectionEntry<C> | undefined>; |
| 63 | + export function getEntry< |
| 64 | + C extends keyof DataEntryMap, |
| 65 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 66 | + >( |
| 67 | + collection: C, |
| 68 | + id: E, |
| 69 | + ): E extends keyof DataEntryMap[C] |
| 70 | + ? string extends keyof DataEntryMap[C] |
| 71 | + ? Promise<DataEntryMap[C][E]> | undefined |
| 72 | + : Promise<DataEntryMap[C][E]> |
| 73 | + : Promise<CollectionEntry<C> | undefined>; |
| 74 | + export function getLiveEntry<C extends keyof LiveContentConfig["collections"]>( |
| 75 | + collection: C, |
| 76 | + filter: string | LiveLoaderEntryFilterType<C>, |
| 77 | + ): Promise<import("astro").LiveDataEntryResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>>; |
| 78 | + |
| 79 | + /** Resolve an array of entry references from the same collection */ |
| 80 | + export function getEntries<C extends keyof DataEntryMap>( |
| 81 | + entries: ReferenceDataEntry<C, keyof DataEntryMap[C]>[], |
| 82 | + ): Promise<CollectionEntry<C>[]>; |
| 83 | + |
| 84 | + export function render<C extends keyof DataEntryMap>( |
| 85 | + entry: DataEntryMap[C][string], |
| 86 | + ): Promise<RenderResult>; |
| 87 | + |
| 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 | + >( |
| 96 | + collection: C, |
| 97 | + ): import("astro/zod").ZodPipe< |
| 98 | + import("astro/zod").ZodString, |
| 99 | + import("astro/zod").ZodTransform< |
| 100 | + C extends keyof DataEntryMap |
| 101 | + ? { |
| 102 | + collection: C; |
| 103 | + id: string; |
| 104 | + } |
| 105 | + : never, |
| 106 | + string |
| 107 | + > |
| 108 | + >; |
| 109 | + |
| 110 | + type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T; |
| 111 | + type InferEntrySchema<C extends keyof DataEntryMap> = import("astro/zod").infer< |
| 112 | + ReturnTypeOrOriginal<Required<ContentConfig["collections"][C]>["schema"]> |
| 113 | + >; |
| 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; |
| 121 | + |
| 122 | + type DataEntryMap = {}; |
| 123 | + |
| 124 | + type ExtractLoaderTypes<T> = T extends import("astro/loaders").LiveLoader< |
| 125 | + infer TData, |
| 126 | + infer TEntryFilter, |
| 127 | + infer TCollectionFilter, |
| 128 | + infer TError |
| 129 | + > |
| 130 | + ? { data: TData; entryFilter: TEntryFilter; collectionFilter: TCollectionFilter; error: TError } |
| 131 | + : { data: never; entryFilter: never; collectionFilter: never; error: never }; |
| 132 | + type ExtractEntryFilterType<T> = ExtractLoaderTypes<T>["entryFilter"]; |
| 133 | + type ExtractCollectionFilterType<T> = ExtractLoaderTypes<T>["collectionFilter"]; |
| 134 | + type ExtractErrorType<T> = ExtractLoaderTypes<T>["error"]; |
| 135 | + |
| 136 | + type LiveLoaderDataType<C extends keyof LiveContentConfig["collections"]> = |
| 137 | + LiveContentConfig["collections"][C]["schema"] extends undefined |
| 138 | + ? ExtractDataType<LiveContentConfig["collections"][C]["loader"]> |
| 139 | + : import("astro/zod").infer< |
| 140 | + Exclude<LiveContentConfig["collections"][C]["schema"], undefined> |
| 141 | + >; |
| 142 | + type LiveLoaderEntryFilterType<C extends keyof LiveContentConfig["collections"]> = |
| 143 | + ExtractEntryFilterType<LiveContentConfig["collections"][C]["loader"]>; |
| 144 | + type LiveLoaderCollectionFilterType<C extends keyof LiveContentConfig["collections"]> = |
| 145 | + ExtractCollectionFilterType<LiveContentConfig["collections"][C]["loader"]>; |
| 146 | + type LiveLoaderErrorType<C extends keyof LiveContentConfig["collections"]> = ExtractErrorType< |
| 147 | + LiveContentConfig["collections"][C]["loader"] |
| 148 | + >; |
| 149 | + |
| 150 | + export type ContentConfig = never; |
| 151 | + export type LiveContentConfig = never; |
154 | 152 | } |
0 commit comments