|
| 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 | + |
| 20 | +declare module 'astro:content' { |
| 21 | + type Flatten<T> = T extends { [K: string]: infer U } ? U : never; |
| 22 | + |
| 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; |
| 28 | + |
| 29 | + type AllValuesOf<T> = T extends any ? T[keyof T] : never; |
| 30 | + type ValidContentEntrySlug<C extends keyof ContentEntryMap> = AllValuesOf< |
| 31 | + ContentEntryMap[C] |
| 32 | + >['slug']; |
| 33 | + |
| 34 | + /** @deprecated Use `getEntry` instead. */ |
| 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 | + /** @deprecated Use `getEntry` instead. */ |
| 47 | + export function getDataEntryById<C extends keyof DataEntryMap, E extends keyof DataEntryMap[C]>( |
| 48 | + collection: C, |
| 49 | + entryId: E, |
| 50 | + ): Promise<CollectionEntry<C>>; |
| 51 | + |
| 52 | + export function getCollection<C extends keyof AnyEntryMap, E extends CollectionEntry<C>>( |
| 53 | + collection: C, |
| 54 | + filter?: (entry: CollectionEntry<C>) => entry is E, |
| 55 | + ): Promise<E[]>; |
| 56 | + export function getCollection<C extends keyof AnyEntryMap>( |
| 57 | + collection: C, |
| 58 | + filter?: (entry: CollectionEntry<C>) => unknown, |
| 59 | + ): Promise<CollectionEntry<C>[]>; |
| 60 | + |
| 61 | + export function getEntry< |
| 62 | + C extends keyof ContentEntryMap, |
| 63 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 64 | + >(entry: { |
| 65 | + collection: C; |
| 66 | + slug: E; |
| 67 | + }): E extends ValidContentEntrySlug<C> |
| 68 | + ? Promise<CollectionEntry<C>> |
| 69 | + : Promise<CollectionEntry<C> | undefined>; |
| 70 | + export function getEntry< |
| 71 | + C extends keyof DataEntryMap, |
| 72 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 73 | + >(entry: { |
| 74 | + collection: C; |
| 75 | + id: E; |
| 76 | + }): E extends keyof DataEntryMap[C] |
| 77 | + ? Promise<DataEntryMap[C][E]> |
| 78 | + : Promise<CollectionEntry<C> | undefined>; |
| 79 | + export function getEntry< |
| 80 | + C extends keyof ContentEntryMap, |
| 81 | + E extends ValidContentEntrySlug<C> | (string & {}), |
| 82 | + >( |
| 83 | + collection: C, |
| 84 | + slug: E, |
| 85 | + ): E extends ValidContentEntrySlug<C> |
| 86 | + ? Promise<CollectionEntry<C>> |
| 87 | + : Promise<CollectionEntry<C> | undefined>; |
| 88 | + export function getEntry< |
| 89 | + C extends keyof DataEntryMap, |
| 90 | + E extends keyof DataEntryMap[C] | (string & {}), |
| 91 | + >( |
| 92 | + collection: C, |
| 93 | + id: E, |
| 94 | + ): E extends keyof DataEntryMap[C] |
| 95 | + ? string extends keyof DataEntryMap[C] |
| 96 | + ? Promise<DataEntryMap[C][E]> | undefined |
| 97 | + : Promise<DataEntryMap[C][E]> |
| 98 | + : Promise<CollectionEntry<C> | undefined>; |
| 99 | + |
| 100 | + /** Resolve an array of entry references from the same collection */ |
| 101 | + export function getEntries<C extends keyof ContentEntryMap>( |
| 102 | + entries: { |
| 103 | + collection: C; |
| 104 | + slug: ValidContentEntrySlug<C>; |
| 105 | + }[], |
| 106 | + ): Promise<CollectionEntry<C>[]>; |
| 107 | + export function getEntries<C extends keyof DataEntryMap>( |
| 108 | + entries: { |
| 109 | + collection: C; |
| 110 | + id: keyof DataEntryMap[C]; |
| 111 | + }[], |
| 112 | + ): Promise<CollectionEntry<C>[]>; |
| 113 | + |
| 114 | + export function render<C extends keyof AnyEntryMap>( |
| 115 | + entry: AnyEntryMap[C][string], |
| 116 | + ): Promise<RenderResult>; |
| 117 | + |
| 118 | + export function reference<C extends keyof AnyEntryMap>( |
| 119 | + collection: C, |
| 120 | + ): import('astro/zod').ZodEffects< |
| 121 | + import('astro/zod').ZodString, |
| 122 | + C extends keyof ContentEntryMap |
| 123 | + ? { |
| 124 | + collection: C; |
| 125 | + slug: ValidContentEntrySlug<C>; |
| 126 | + } |
| 127 | + : { |
| 128 | + collection: C; |
| 129 | + id: keyof DataEntryMap[C]; |
| 130 | + } |
| 131 | + >; |
| 132 | + // Allow generic `string` to avoid excessive type errors in the config |
| 133 | + // if `dev` is not running to update as you edit. |
| 134 | + // Invalid collection names will be caught at build time. |
| 135 | + export function reference<C extends string>( |
| 136 | + collection: C, |
| 137 | + ): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>; |
| 138 | + |
| 139 | + type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T; |
| 140 | + type InferEntrySchema<C extends keyof AnyEntryMap> = import('astro/zod').infer< |
| 141 | + ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']> |
| 142 | + >; |
| 143 | + |
| 144 | + type ContentEntryMap = { |
| 145 | + |
| 146 | + }; |
| 147 | + |
| 148 | + type DataEntryMap = { |
| 149 | + |
| 150 | + }; |
| 151 | + |
| 152 | + type AnyEntryMap = ContentEntryMap & DataEntryMap; |
| 153 | + |
| 154 | + export type ContentConfig = typeof import("../src/content.config.mjs"); |
| 155 | +} |
0 commit comments