|
| 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 | + |
| 178 | + }; |
| 179 | + |
| 180 | + type DataEntryMap = { |
| 181 | + |
| 182 | + }; |
| 183 | + |
| 184 | + type AnyEntryMap = ContentEntryMap & DataEntryMap; |
| 185 | + |
| 186 | + type ContentConfig = never; |
| 187 | +} |
0 commit comments