|
| 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 | + "leetcode-solutions": { |
| 105 | +"0003-longest-substring-without-repeating-characters.md": { |
| 106 | + id: "0003-longest-substring-without-repeating-characters.md", |
| 107 | + slug: "0003-longest-substring-without-repeating-characters", |
| 108 | + body: string, |
| 109 | + collection: "leetcode-solutions", |
| 110 | + data: InferEntrySchema<"leetcode-solutions"> |
| 111 | +} & { render(): Render[".md"] }, |
| 112 | +"0008-string-to-integer-atoi.md": { |
| 113 | + id: "0008-string-to-integer-atoi.md", |
| 114 | + slug: "0008-string-to-integer-atoi", |
| 115 | + body: string, |
| 116 | + collection: "leetcode-solutions", |
| 117 | + data: InferEntrySchema<"leetcode-solutions"> |
| 118 | +} & { render(): Render[".md"] }, |
| 119 | +"0053-maximum-subarray.md": { |
| 120 | + id: "0053-maximum-subarray.md", |
| 121 | + slug: "0053-maximum-subarray", |
| 122 | + body: string, |
| 123 | + collection: "leetcode-solutions", |
| 124 | + data: InferEntrySchema<"leetcode-solutions"> |
| 125 | +} & { render(): Render[".md"] }, |
| 126 | +"0231-power-of-two.md": { |
| 127 | + id: "0231-power-of-two.md", |
| 128 | + slug: "0231-power-of-two", |
| 129 | + body: string, |
| 130 | + collection: "leetcode-solutions", |
| 131 | + data: InferEntrySchema<"leetcode-solutions"> |
| 132 | +} & { render(): Render[".md"] }, |
| 133 | +"0628-maximum-product-of-three-numbers.md": { |
| 134 | + id: "0628-maximum-product-of-three-numbers.md", |
| 135 | + slug: "0628-maximum-product-of-three-numbers", |
| 136 | + body: string, |
| 137 | + collection: "leetcode-solutions", |
| 138 | + data: InferEntrySchema<"leetcode-solutions"> |
| 139 | +} & { render(): Render[".md"] }, |
| 140 | +"2400-number-of-ways-to-reach-a-position-after-exactly-k-steps.md": { |
| 141 | + id: "2400-number-of-ways-to-reach-a-position-after-exactly-k-steps.md", |
| 142 | + slug: "2400-number-of-ways-to-reach-a-position-after-exactly-k-steps", |
| 143 | + body: string, |
| 144 | + collection: "leetcode-solutions", |
| 145 | + data: InferEntrySchema<"leetcode-solutions"> |
| 146 | +} & { render(): Render[".md"] }, |
| 147 | +"2464-split-message-based-on-limit.md": { |
| 148 | + id: "2464-split-message-based-on-limit.md", |
| 149 | + slug: "2468-split-message-based-on-limit", |
| 150 | + body: string, |
| 151 | + collection: "leetcode-solutions", |
| 152 | + data: InferEntrySchema<"leetcode-solutions"> |
| 153 | +} & { render(): Render[".md"] }, |
| 154 | +}, |
| 155 | + |
| 156 | + }; |
| 157 | + |
| 158 | + type ContentConfig = typeof import("../src/content/config"); |
| 159 | +} |
0 commit comments