|
| 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 | + export type CollectionEntry<C extends keyof typeof entryMap> = |
| 14 | + (typeof entryMap)[C][keyof (typeof entryMap)[C]]; |
| 15 | + |
| 16 | + // TODO: Remove this when having this fallback is no longer relevant. 2.3? 3.0? - erika, 2023-04-04 |
| 17 | + /** |
| 18 | + * @deprecated |
| 19 | + * `astro:content` no longer provide `image()`. |
| 20 | + * |
| 21 | + * Please use it through `schema`, like such: |
| 22 | + * ```ts |
| 23 | + * import { defineCollection, z } from "astro:content"; |
| 24 | + * |
| 25 | + * defineCollection({ |
| 26 | + * schema: ({ image }) => |
| 27 | + * z.object({ |
| 28 | + * image: image(), |
| 29 | + * }), |
| 30 | + * }); |
| 31 | + * ``` |
| 32 | + */ |
| 33 | + export const image: never; |
| 34 | + |
| 35 | + // This needs to be in sync with ImageMetadata |
| 36 | + export type ImageFunction = () => import('astro/zod').ZodObject<{ |
| 37 | + src: import('astro/zod').ZodString; |
| 38 | + width: import('astro/zod').ZodNumber; |
| 39 | + height: import('astro/zod').ZodNumber; |
| 40 | + format: import('astro/zod').ZodUnion< |
| 41 | + [ |
| 42 | + import('astro/zod').ZodLiteral<'png'>, |
| 43 | + import('astro/zod').ZodLiteral<'jpg'>, |
| 44 | + import('astro/zod').ZodLiteral<'jpeg'>, |
| 45 | + import('astro/zod').ZodLiteral<'tiff'>, |
| 46 | + import('astro/zod').ZodLiteral<'webp'>, |
| 47 | + import('astro/zod').ZodLiteral<'gif'>, |
| 48 | + import('astro/zod').ZodLiteral<'svg'> |
| 49 | + ] |
| 50 | + >; |
| 51 | + }>; |
| 52 | + |
| 53 | + type BaseSchemaWithoutEffects = |
| 54 | + | import('astro/zod').AnyZodObject |
| 55 | + | import('astro/zod').ZodUnion<import('astro/zod').AnyZodObject[]> |
| 56 | + | import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]> |
| 57 | + | import('astro/zod').ZodIntersection< |
| 58 | + import('astro/zod').AnyZodObject, |
| 59 | + import('astro/zod').AnyZodObject |
| 60 | + >; |
| 61 | + |
| 62 | + type BaseSchema = |
| 63 | + | BaseSchemaWithoutEffects |
| 64 | + | import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>; |
| 65 | + |
| 66 | + export type SchemaContext = { image: ImageFunction }; |
| 67 | + |
| 68 | + type BaseCollectionConfig<S extends BaseSchema> = { |
| 69 | + schema?: S | ((context: SchemaContext) => S); |
| 70 | + }; |
| 71 | + export function defineCollection<S extends BaseSchema>( |
| 72 | + input: BaseCollectionConfig<S> |
| 73 | + ): BaseCollectionConfig<S>; |
| 74 | + |
| 75 | + type EntryMapKeys = keyof typeof entryMap; |
| 76 | + type AllValuesOf<T> = T extends any ? T[keyof T] : never; |
| 77 | + type ValidEntrySlug<C extends EntryMapKeys> = AllValuesOf<(typeof entryMap)[C]>['slug']; |
| 78 | + |
| 79 | + export function getEntryBySlug< |
| 80 | + C extends keyof typeof entryMap, |
| 81 | + E extends ValidEntrySlug<C> | (string & {}) |
| 82 | + >( |
| 83 | + collection: C, |
| 84 | + // Note that this has to accept a regular string too, for SSR |
| 85 | + entrySlug: E |
| 86 | + ): E extends ValidEntrySlug<C> |
| 87 | + ? Promise<CollectionEntry<C>> |
| 88 | + : Promise<CollectionEntry<C> | undefined>; |
| 89 | + export function getCollection<C extends keyof typeof entryMap, E extends CollectionEntry<C>>( |
| 90 | + collection: C, |
| 91 | + filter?: (entry: CollectionEntry<C>) => entry is E |
| 92 | + ): Promise<E[]>; |
| 93 | + export function getCollection<C extends keyof typeof entryMap>( |
| 94 | + collection: C, |
| 95 | + filter?: (entry: CollectionEntry<C>) => unknown |
| 96 | + ): Promise<CollectionEntry<C>[]>; |
| 97 | + |
| 98 | + type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T; |
| 99 | + type InferEntrySchema<C extends keyof typeof entryMap> = import('astro/zod').infer< |
| 100 | + ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']> |
| 101 | + >; |
| 102 | + |
| 103 | + const entryMap: { |
| 104 | + "docs": { |
| 105 | +"about.md": { |
| 106 | + id: "about.md", |
| 107 | + slug: "about", |
| 108 | + body: string, |
| 109 | + collection: "docs", |
| 110 | + data: InferEntrySchema<"docs"> |
| 111 | +} & { render(): Render[".md"] }, |
| 112 | +"advanced.md": { |
| 113 | + id: "advanced.md", |
| 114 | + slug: "advanced", |
| 115 | + body: string, |
| 116 | + collection: "docs", |
| 117 | + data: InferEntrySchema<"docs"> |
| 118 | +} & { render(): Render[".md"] }, |
| 119 | +"cli.md": { |
| 120 | + id: "cli.md", |
| 121 | + slug: "cli", |
| 122 | + body: string, |
| 123 | + collection: "docs", |
| 124 | + data: InferEntrySchema<"docs"> |
| 125 | +} & { render(): Render[".md"] }, |
| 126 | +"introduction.md": { |
| 127 | + id: "introduction.md", |
| 128 | + slug: "introduction", |
| 129 | + body: string, |
| 130 | + collection: "docs", |
| 131 | + data: InferEntrySchema<"docs"> |
| 132 | +} & { render(): Render[".md"] }, |
| 133 | +"node.md": { |
| 134 | + id: "node.md", |
| 135 | + slug: "node", |
| 136 | + body: string, |
| 137 | + collection: "docs", |
| 138 | + data: InferEntrySchema<"docs"> |
| 139 | +} & { render(): Render[".md"] }, |
| 140 | +"openapi-fetch/about.md": { |
| 141 | + id: "openapi-fetch/about.md", |
| 142 | + slug: "openapi-fetch/about", |
| 143 | + body: string, |
| 144 | + collection: "docs", |
| 145 | + data: InferEntrySchema<"docs"> |
| 146 | +} & { render(): Render[".md"] }, |
| 147 | +"openapi-fetch/api.md": { |
| 148 | + id: "openapi-fetch/api.md", |
| 149 | + slug: "openapi-fetch/api", |
| 150 | + body: string, |
| 151 | + collection: "docs", |
| 152 | + data: InferEntrySchema<"docs"> |
| 153 | +} & { render(): Render[".md"] }, |
| 154 | +"openapi-fetch/examples.md": { |
| 155 | + id: "openapi-fetch/examples.md", |
| 156 | + slug: "openapi-fetch/examples", |
| 157 | + body: string, |
| 158 | + collection: "docs", |
| 159 | + data: InferEntrySchema<"docs"> |
| 160 | +} & { render(): Render[".md"] }, |
| 161 | +"openapi-fetch/index.md": { |
| 162 | + id: "openapi-fetch/index.md", |
| 163 | + slug: "openapi-fetch", |
| 164 | + body: string, |
| 165 | + collection: "docs", |
| 166 | + data: InferEntrySchema<"docs"> |
| 167 | +} & { render(): Render[".md"] }, |
| 168 | +}, |
| 169 | + |
| 170 | + }; |
| 171 | + |
| 172 | + type ContentConfig = typeof import("../src/content/config"); |
| 173 | +} |
0 commit comments