|
| 1 | +declare module 'astro:content' { |
| 2 | + interface Render { |
| 3 | + '.md': 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 | + export { z } from 'astro/zod'; |
| 13 | + |
| 14 | + type Flatten<T> = T extends { [K: string]: infer U } ? U : never; |
| 15 | + |
| 16 | + export type CollectionKey = keyof AnyEntryMap; |
| 17 | + export type CollectionEntry<C extends CollectionKey> = Flatten<AnyEntryMap[C]>; |
| 18 | + |
| 19 | + export type ContentCollectionKey = keyof ContentEntryMap; |
| 20 | + export type DataCollectionKey = keyof DataEntryMap; |
| 21 | + |
| 22 | + // This needs to be in sync with ImageMetadata |
| 23 | + export type ImageFunction = () => import('astro/zod').ZodObject<{ |
| 24 | + src: import('astro/zod').ZodString; |
| 25 | + width: import('astro/zod').ZodNumber; |
| 26 | + height: import('astro/zod').ZodNumber; |
| 27 | + format: import('astro/zod').ZodUnion< |
| 28 | + [ |
| 29 | + import('astro/zod').ZodLiteral<'png'>, |
| 30 | + import('astro/zod').ZodLiteral<'jpg'>, |
| 31 | + import('astro/zod').ZodLiteral<'jpeg'>, |
| 32 | + import('astro/zod').ZodLiteral<'tiff'>, |
| 33 | + import('astro/zod').ZodLiteral<'webp'>, |
| 34 | + import('astro/zod').ZodLiteral<'gif'>, |
| 35 | + import('astro/zod').ZodLiteral<'svg'>, |
| 36 | + import('astro/zod').ZodLiteral<'avif'>, |
| 37 | + ] |
| 38 | + >; |
| 39 | + }>; |
| 40 | + |
| 41 | + type BaseSchemaWithoutEffects = |
| 42 | + | import('astro/zod').AnyZodObject |
| 43 | + | import('astro/zod').ZodUnion<[BaseSchemaWithoutEffects, ...BaseSchemaWithoutEffects[]]> |
| 44 | + | import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]> |
| 45 | + | import('astro/zod').ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>; |
| 46 | + |
| 47 | + type BaseSchema = |
| 48 | + | BaseSchemaWithoutEffects |
| 49 | + | import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>; |
| 50 | + |
| 51 | + export type SchemaContext = { image: ImageFunction }; |
| 52 | + |
| 53 | + type DataCollectionConfig<S extends BaseSchema> = { |
| 54 | + type: 'data'; |
| 55 | + schema?: S | ((context: SchemaContext) => S); |
| 56 | + }; |
| 57 | + |
| 58 | + type ContentCollectionConfig<S extends BaseSchema> = { |
| 59 | + type?: 'content'; |
| 60 | + schema?: S | ((context: SchemaContext) => S); |
| 61 | + }; |
| 62 | + |
| 63 | + type CollectionConfig<S> = ContentCollectionConfig<S> | DataCollectionConfig<S>; |
| 64 | + |
| 65 | + export function defineCollection<S extends BaseSchema>( |
| 66 | + input: CollectionConfig<S> |
| 67 | + ): CollectionConfig<S>; |
| 68 | + |
| 69 | + type AllValuesOf<T> = T extends any ? T[keyof T] : never; |
| 70 | + type ValidContentEntrySlug<C extends keyof ContentEntryMap> = AllValuesOf< |
| 71 | + ContentEntryMap[C] |
| 72 | + >['slug']; |
| 73 | + |
| 74 | + export function getEntryBySlug< |
| 75 | + C extends keyof ContentEntryMap, |
| 76 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 77 | + >( |
| 78 | + collection: C, |
| 79 | + // Note that this has to accept a regular string too, for SSR |
| 80 | + entrySlug: E |
| 81 | + ): E extends ValidContentEntrySlug<C> |
| 82 | + ? Promise<CollectionEntry<C>> |
| 83 | + : Promise<CollectionEntry<C> | undefined>; |
| 84 | + |
| 85 | + export function getDataEntryById<C extends keyof DataEntryMap, E extends keyof DataEntryMap[C]>( |
| 86 | + collection: C, |
| 87 | + entryId: E |
| 88 | + ): Promise<CollectionEntry<C>>; |
| 89 | + |
| 90 | + export function getCollection<C extends keyof AnyEntryMap, E extends CollectionEntry<C>>( |
| 91 | + collection: C, |
| 92 | + filter?: (entry: CollectionEntry<C>) => entry is E |
| 93 | + ): Promise<E[]>; |
| 94 | + export function getCollection<C extends keyof AnyEntryMap>( |
| 95 | + collection: C, |
| 96 | + filter?: (entry: CollectionEntry<C>) => unknown |
| 97 | + ): Promise<CollectionEntry<C>[]>; |
| 98 | + |
| 99 | + export function getEntry< |
| 100 | + C extends keyof ContentEntryMap, |
| 101 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 102 | + >(entry: { |
| 103 | + collection: C; |
| 104 | + slug: E; |
| 105 | + }): E extends ValidContentEntrySlug<C> |
| 106 | + ? Promise<CollectionEntry<C>> |
| 107 | + : Promise<CollectionEntry<C> | undefined>; |
| 108 | + export function getEntry< |
| 109 | + C extends keyof DataEntryMap, |
| 110 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 111 | + >(entry: { |
| 112 | + collection: C; |
| 113 | + id: E; |
| 114 | + }): E extends keyof DataEntryMap[C] |
| 115 | + ? Promise<DataEntryMap[C][E]> |
| 116 | + : Promise<CollectionEntry<C> | undefined>; |
| 117 | + export function getEntry< |
| 118 | + C extends keyof ContentEntryMap, |
| 119 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 120 | + >( |
| 121 | + collection: C, |
| 122 | + slug: E |
| 123 | + ): E extends ValidContentEntrySlug<C> |
| 124 | + ? Promise<CollectionEntry<C>> |
| 125 | + : Promise<CollectionEntry<C> | undefined>; |
| 126 | + export function getEntry< |
| 127 | + C extends keyof DataEntryMap, |
| 128 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 129 | + >( |
| 130 | + collection: C, |
| 131 | + id: E |
| 132 | + ): E extends keyof DataEntryMap[C] |
| 133 | + ? Promise<DataEntryMap[C][E]> |
| 134 | + : Promise<CollectionEntry<C> | undefined>; |
| 135 | + |
| 136 | + /** Resolve an array of entry references from the same collection */ |
| 137 | + export function getEntries<C extends keyof ContentEntryMap>( |
| 138 | + entries: { |
| 139 | + collection: C; |
| 140 | + slug: ValidContentEntrySlug<C>; |
| 141 | + }[] |
| 142 | + ): Promise<CollectionEntry<C>[]>; |
| 143 | + export function getEntries<C extends keyof DataEntryMap>( |
| 144 | + entries: { |
| 145 | + collection: C; |
| 146 | + id: keyof DataEntryMap[C]; |
| 147 | + }[] |
| 148 | + ): Promise<CollectionEntry<C>[]>; |
| 149 | + |
| 150 | + export function reference<C extends keyof AnyEntryMap>( |
| 151 | + collection: C |
| 152 | + ): import('astro/zod').ZodEffects< |
| 153 | + import('astro/zod').ZodString, |
| 154 | + C extends keyof ContentEntryMap |
| 155 | + ? { |
| 156 | + collection: C; |
| 157 | + slug: ValidContentEntrySlug<C>; |
| 158 | + } |
| 159 | + : { |
| 160 | + collection: C; |
| 161 | + id: keyof DataEntryMap[C]; |
| 162 | + } |
| 163 | + >; |
| 164 | + // Allow generic `string` to avoid excessive type errors in the config |
| 165 | + // if `dev` is not running to update as you edit. |
| 166 | + // Invalid collection names will be caught at build time. |
| 167 | + export function reference<C extends string>( |
| 168 | + collection: C |
| 169 | + ): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>; |
| 170 | + |
| 171 | + type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T; |
| 172 | + type InferEntrySchema<C extends keyof AnyEntryMap> = import('astro/zod').infer< |
| 173 | + ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']> |
| 174 | + >; |
| 175 | + |
| 176 | + type ContentEntryMap = { |
| 177 | + "docs": { |
| 178 | +"about.md": { |
| 179 | + id: "about.md"; |
| 180 | + slug: "about"; |
| 181 | + body: string; |
| 182 | + collection: "docs"; |
| 183 | + data: InferEntrySchema<"docs"> |
| 184 | +} & { render(): Render[".md"] }; |
| 185 | +"advanced.md": { |
| 186 | + id: "advanced.md"; |
| 187 | + slug: "advanced"; |
| 188 | + body: string; |
| 189 | + collection: "docs"; |
| 190 | + data: InferEntrySchema<"docs"> |
| 191 | +} & { render(): Render[".md"] }; |
| 192 | +"cli.md": { |
| 193 | + id: "cli.md"; |
| 194 | + slug: "cli"; |
| 195 | + body: string; |
| 196 | + collection: "docs"; |
| 197 | + data: InferEntrySchema<"docs"> |
| 198 | +} & { render(): Render[".md"] }; |
| 199 | +"introduction.md": { |
| 200 | + id: "introduction.md"; |
| 201 | + slug: "introduction"; |
| 202 | + body: string; |
| 203 | + collection: "docs"; |
| 204 | + data: InferEntrySchema<"docs"> |
| 205 | +} & { render(): Render[".md"] }; |
| 206 | +"migration-guide.md": { |
| 207 | + id: "migration-guide.md"; |
| 208 | + slug: "migration-guide"; |
| 209 | + body: string; |
| 210 | + collection: "docs"; |
| 211 | + data: InferEntrySchema<"docs"> |
| 212 | +} & { render(): Render[".md"] }; |
| 213 | +"node.md": { |
| 214 | + id: "node.md"; |
| 215 | + slug: "node"; |
| 216 | + body: string; |
| 217 | + collection: "docs"; |
| 218 | + data: InferEntrySchema<"docs"> |
| 219 | +} & { render(): Render[".md"] }; |
| 220 | +"openapi-fetch/about.md": { |
| 221 | + id: "openapi-fetch/about.md"; |
| 222 | + slug: "openapi-fetch/about"; |
| 223 | + body: string; |
| 224 | + collection: "docs"; |
| 225 | + data: InferEntrySchema<"docs"> |
| 226 | +} & { render(): Render[".md"] }; |
| 227 | +"openapi-fetch/api.md": { |
| 228 | + id: "openapi-fetch/api.md"; |
| 229 | + slug: "openapi-fetch/api"; |
| 230 | + body: string; |
| 231 | + collection: "docs"; |
| 232 | + data: InferEntrySchema<"docs"> |
| 233 | +} & { render(): Render[".md"] }; |
| 234 | +"openapi-fetch/examples.md": { |
| 235 | + id: "openapi-fetch/examples.md"; |
| 236 | + slug: "openapi-fetch/examples"; |
| 237 | + body: string; |
| 238 | + collection: "docs"; |
| 239 | + data: InferEntrySchema<"docs"> |
| 240 | +} & { render(): Render[".md"] }; |
| 241 | +"openapi-fetch/index.md": { |
| 242 | + id: "openapi-fetch/index.md"; |
| 243 | + slug: "openapi-fetch"; |
| 244 | + body: string; |
| 245 | + collection: "docs"; |
| 246 | + data: InferEntrySchema<"docs"> |
| 247 | +} & { render(): Render[".md"] }; |
| 248 | +"v6/about.md": { |
| 249 | + id: "v6/about.md"; |
| 250 | + slug: "v6/about"; |
| 251 | + body: string; |
| 252 | + collection: "docs"; |
| 253 | + data: InferEntrySchema<"docs"> |
| 254 | +} & { render(): Render[".md"] }; |
| 255 | +"v6/advanced.md": { |
| 256 | + id: "v6/advanced.md"; |
| 257 | + slug: "v6/advanced"; |
| 258 | + body: string; |
| 259 | + collection: "docs"; |
| 260 | + data: InferEntrySchema<"docs"> |
| 261 | +} & { render(): Render[".md"] }; |
| 262 | +"v6/cli.md": { |
| 263 | + id: "v6/cli.md"; |
| 264 | + slug: "v6/cli"; |
| 265 | + body: string; |
| 266 | + collection: "docs"; |
| 267 | + data: InferEntrySchema<"docs"> |
| 268 | +} & { render(): Render[".md"] }; |
| 269 | +"v6/introduction.md": { |
| 270 | + id: "v6/introduction.md"; |
| 271 | + slug: "v6/introduction"; |
| 272 | + body: string; |
| 273 | + collection: "docs"; |
| 274 | + data: InferEntrySchema<"docs"> |
| 275 | +} & { render(): Render[".md"] }; |
| 276 | +"v6/node.md": { |
| 277 | + id: "v6/node.md"; |
| 278 | + slug: "v6/node"; |
| 279 | + body: string; |
| 280 | + collection: "docs"; |
| 281 | + data: InferEntrySchema<"docs"> |
| 282 | +} & { render(): Render[".md"] }; |
| 283 | +}; |
| 284 | + |
| 285 | + }; |
| 286 | + |
| 287 | + type DataEntryMap = { |
| 288 | + |
| 289 | + }; |
| 290 | + |
| 291 | + type AnyEntryMap = ContentEntryMap & DataEntryMap; |
| 292 | + |
| 293 | + type ContentConfig = typeof import("../src/content/config"); |
| 294 | +} |
0 commit comments