|
| 1 | +declare module 'astro:content' { |
| 2 | + interface Render { |
| 3 | + '.mdx': Promise<{ |
| 4 | + Content: import('astro').MarkdownInstance<{}>['Content']; |
| 5 | + headings: import('astro').MarkdownHeading[]; |
| 6 | + remarkPluginFrontmatter: Record<string, any>; |
| 7 | + }>; |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +declare module 'astro:content' { |
| 12 | + interface Render { |
| 13 | + '.md': Promise<{ |
| 14 | + Content: import('astro').MarkdownInstance<{}>['Content']; |
| 15 | + headings: import('astro').MarkdownHeading[]; |
| 16 | + remarkPluginFrontmatter: Record<string, any>; |
| 17 | + }>; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +declare module 'astro:content' { |
| 22 | + type Flatten<T> = T extends { [K: string]: infer U } ? U : never; |
| 23 | + |
| 24 | + export type CollectionKey = keyof AnyEntryMap; |
| 25 | + export type CollectionEntry<C extends CollectionKey> = Flatten<AnyEntryMap[C]>; |
| 26 | + |
| 27 | + export type ContentCollectionKey = keyof ContentEntryMap; |
| 28 | + export type DataCollectionKey = keyof DataEntryMap; |
| 29 | + |
| 30 | + type AllValuesOf<T> = T extends any ? T[keyof T] : never; |
| 31 | + type ValidContentEntrySlug<C extends keyof ContentEntryMap> = AllValuesOf< |
| 32 | + ContentEntryMap[C] |
| 33 | + >['slug']; |
| 34 | + |
| 35 | + export function getEntryBySlug< |
| 36 | + C extends keyof ContentEntryMap, |
| 37 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 38 | + >( |
| 39 | + collection: C, |
| 40 | + // Note that this has to accept a regular string too, for SSR |
| 41 | + entrySlug: E |
| 42 | + ): E extends ValidContentEntrySlug<C> |
| 43 | + ? Promise<CollectionEntry<C>> |
| 44 | + : Promise<CollectionEntry<C> | undefined>; |
| 45 | + |
| 46 | + export function getDataEntryById<C extends keyof DataEntryMap, E extends keyof DataEntryMap[C]>( |
| 47 | + collection: C, |
| 48 | + entryId: E |
| 49 | + ): Promise<CollectionEntry<C>>; |
| 50 | + |
| 51 | + export function getCollection<C extends keyof AnyEntryMap, E extends CollectionEntry<C>>( |
| 52 | + collection: C, |
| 53 | + filter?: (entry: CollectionEntry<C>) => entry is E |
| 54 | + ): Promise<E[]>; |
| 55 | + export function getCollection<C extends keyof AnyEntryMap>( |
| 56 | + collection: C, |
| 57 | + filter?: (entry: CollectionEntry<C>) => unknown |
| 58 | + ): Promise<CollectionEntry<C>[]>; |
| 59 | + |
| 60 | + export function getEntry< |
| 61 | + C extends keyof ContentEntryMap, |
| 62 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 63 | + >(entry: { |
| 64 | + collection: C; |
| 65 | + slug: E; |
| 66 | + }): E extends ValidContentEntrySlug<C> |
| 67 | + ? Promise<CollectionEntry<C>> |
| 68 | + : Promise<CollectionEntry<C> | undefined>; |
| 69 | + export function getEntry< |
| 70 | + C extends keyof DataEntryMap, |
| 71 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 72 | + >(entry: { |
| 73 | + collection: C; |
| 74 | + id: E; |
| 75 | + }): E extends keyof DataEntryMap[C] |
| 76 | + ? Promise<DataEntryMap[C][E]> |
| 77 | + : Promise<CollectionEntry<C> | undefined>; |
| 78 | + export function getEntry< |
| 79 | + C extends keyof ContentEntryMap, |
| 80 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 81 | + >( |
| 82 | + collection: C, |
| 83 | + slug: E |
| 84 | + ): E extends ValidContentEntrySlug<C> |
| 85 | + ? Promise<CollectionEntry<C>> |
| 86 | + : Promise<CollectionEntry<C> | undefined>; |
| 87 | + export function getEntry< |
| 88 | + C extends keyof DataEntryMap, |
| 89 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 90 | + >( |
| 91 | + collection: C, |
| 92 | + id: E |
| 93 | + ): E extends keyof DataEntryMap[C] |
| 94 | + ? Promise<DataEntryMap[C][E]> |
| 95 | + : Promise<CollectionEntry<C> | undefined>; |
| 96 | + |
| 97 | + /** Resolve an array of entry references from the same collection */ |
| 98 | + export function getEntries<C extends keyof ContentEntryMap>( |
| 99 | + entries: { |
| 100 | + collection: C; |
| 101 | + slug: ValidContentEntrySlug<C>; |
| 102 | + }[] |
| 103 | + ): Promise<CollectionEntry<C>[]>; |
| 104 | + export function getEntries<C extends keyof DataEntryMap>( |
| 105 | + entries: { |
| 106 | + collection: C; |
| 107 | + id: keyof DataEntryMap[C]; |
| 108 | + }[] |
| 109 | + ): Promise<CollectionEntry<C>[]>; |
| 110 | + |
| 111 | + export function reference<C extends keyof AnyEntryMap>( |
| 112 | + collection: C |
| 113 | + ): import('astro/zod').ZodEffects< |
| 114 | + import('astro/zod').ZodString, |
| 115 | + C extends keyof ContentEntryMap |
| 116 | + ? { |
| 117 | + collection: C; |
| 118 | + slug: ValidContentEntrySlug<C>; |
| 119 | + } |
| 120 | + : { |
| 121 | + collection: C; |
| 122 | + id: keyof DataEntryMap[C]; |
| 123 | + } |
| 124 | + >; |
| 125 | + // Allow generic `string` to avoid excessive type errors in the config |
| 126 | + // if `dev` is not running to update as you edit. |
| 127 | + // Invalid collection names will be caught at build time. |
| 128 | + export function reference<C extends string>( |
| 129 | + collection: C |
| 130 | + ): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>; |
| 131 | + |
| 132 | + type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T; |
| 133 | + type InferEntrySchema<C extends keyof AnyEntryMap> = import('astro/zod').infer< |
| 134 | + ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']> |
| 135 | + >; |
| 136 | + |
| 137 | + type ContentEntryMap = { |
| 138 | + "blog": { |
| 139 | +"words-as-vectors.mdx": { |
| 140 | + id: "words-as-vectors.mdx"; |
| 141 | + slug: "words-vectors-sparse-vectors-dense-vectors"; |
| 142 | + body: string; |
| 143 | + collection: "blog"; |
| 144 | + data: InferEntrySchema<"blog"> |
| 145 | +} & { render(): Render[".mdx"] }; |
| 146 | +}; |
| 147 | +"events": { |
| 148 | +"hello-foss.md": { |
| 149 | + id: "hello-foss.md"; |
| 150 | + slug: "hello-foss-2023"; |
| 151 | + body: string; |
| 152 | + collection: "events"; |
| 153 | + data: InferEntrySchema<"events"> |
| 154 | +} & { render(): Render[".md"] }; |
| 155 | +"oss24_workshop1.md": { |
| 156 | + id: "oss24_workshop1.md"; |
| 157 | + slug: "oss24-devops-101-workshop"; |
| 158 | + body: string; |
| 159 | + collection: "events"; |
| 160 | + data: InferEntrySchema<"events"> |
| 161 | +} & { render(): Render[".md"] }; |
| 162 | +"oss24_workshop2.md": { |
| 163 | + id: "oss24_workshop2.md"; |
| 164 | + slug: "oss24_workshop2"; |
| 165 | + body: string; |
| 166 | + collection: "events"; |
| 167 | + data: InferEntrySchema<"events"> |
| 168 | +} & { render(): Render[".md"] }; |
| 169 | +"oss24_workshop3.md": { |
| 170 | + id: "oss24_workshop3.md"; |
| 171 | + slug: "oss24_workshop3"; |
| 172 | + body: string; |
| 173 | + collection: "events"; |
| 174 | + data: InferEntrySchema<"events"> |
| 175 | +} & { render(): Render[".md"] }; |
| 176 | +"oss24_workshop4.md": { |
| 177 | + id: "oss24_workshop4.md"; |
| 178 | + slug: "oss24_workshop4"; |
| 179 | + body: string; |
| 180 | + collection: "events"; |
| 181 | + data: InferEntrySchema<"events"> |
| 182 | +} & { render(): Render[".md"] }; |
| 183 | +"oss24_workshop5.md": { |
| 184 | + id: "oss24_workshop5.md"; |
| 185 | + slug: "oss24_workshop5"; |
| 186 | + body: string; |
| 187 | + collection: "events"; |
| 188 | + data: InferEntrySchema<"events"> |
| 189 | +} & { render(): Render[".md"] }; |
| 190 | +"oss24_workshop6.md": { |
| 191 | + id: "oss24_workshop6.md"; |
| 192 | + slug: "oss24_workshop6"; |
| 193 | + body: string; |
| 194 | + collection: "events"; |
| 195 | + data: InferEntrySchema<"events"> |
| 196 | +} & { render(): Render[".md"] }; |
| 197 | +"streamline_git_worksflows.md": { |
| 198 | + id: "streamline_git_worksflows.md"; |
| 199 | + slug: "streamline_git_worksflows"; |
| 200 | + body: string; |
| 201 | + collection: "events"; |
| 202 | + data: InferEntrySchema<"events"> |
| 203 | +} & { render(): Render[".md"] }; |
| 204 | +"webdev101.md": { |
| 205 | + id: "webdev101.md"; |
| 206 | + slug: "webdev101"; |
| 207 | + body: string; |
| 208 | + collection: "events"; |
| 209 | + data: InferEntrySchema<"events"> |
| 210 | +} & { render(): Render[".md"] }; |
| 211 | +}; |
| 212 | +"static": { |
| 213 | +"code-of-conduct.md": { |
| 214 | + id: "code-of-conduct.md"; |
| 215 | + slug: "code-of-conduct"; |
| 216 | + body: string; |
| 217 | + collection: "static"; |
| 218 | + data: InferEntrySchema<"static"> |
| 219 | +} & { render(): Render[".md"] }; |
| 220 | +"sponsorship.md": { |
| 221 | + id: "sponsorship.md"; |
| 222 | + slug: "sponsorship"; |
| 223 | + body: string; |
| 224 | + collection: "static"; |
| 225 | + data: InferEntrySchema<"static"> |
| 226 | +} & { render(): Render[".md"] }; |
| 227 | +}; |
| 228 | + |
| 229 | + }; |
| 230 | + |
| 231 | + type DataEntryMap = { |
| 232 | + |
| 233 | + }; |
| 234 | + |
| 235 | + type AnyEntryMap = ContentEntryMap & DataEntryMap; |
| 236 | + |
| 237 | + export type ContentConfig = typeof import("./../src/content/config.js"); |
| 238 | +} |
0 commit comments