|
1 | | -declare module 'astro:content' { |
2 | | - 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 | | - ? Promise<DataEntryMap[C][E]> |
96 | | - : Promise<CollectionEntry<C> | undefined>; |
97 | | - |
98 | | - /** Resolve an array of entry references from the same collection */ |
99 | | - export function getEntries<C extends keyof ContentEntryMap>( |
100 | | - entries: { |
101 | | - collection: C; |
102 | | - slug: ValidContentEntrySlug<C>; |
103 | | - }[], |
104 | | - ): Promise<CollectionEntry<C>[]>; |
105 | | - export function getEntries<C extends keyof DataEntryMap>( |
106 | | - entries: { |
107 | | - collection: C; |
108 | | - id: keyof DataEntryMap[C]; |
109 | | - }[], |
110 | | - ): Promise<CollectionEntry<C>[]>; |
111 | | - |
112 | | - export function render<C extends keyof AnyEntryMap>( |
113 | | - entry: AnyEntryMap[C][string], |
114 | | - ): Promise<RenderResult>; |
115 | | - |
116 | | - export function reference<C extends keyof AnyEntryMap>( |
117 | | - collection: C, |
118 | | - ): import('astro/zod').ZodEffects< |
119 | | - import('astro/zod').ZodString, |
120 | | - C extends keyof ContentEntryMap |
121 | | - ? { |
122 | | - collection: C; |
123 | | - slug: ValidContentEntrySlug<C>; |
124 | | - } |
125 | | - : { |
126 | | - collection: C; |
127 | | - id: keyof DataEntryMap[C]; |
128 | | - } |
129 | | - >; |
130 | | - // Allow generic `string` to avoid excessive type errors in the config |
131 | | - // if `dev` is not running to update as you edit. |
132 | | - // Invalid collection names will be caught at build time. |
133 | | - export function reference<C extends string>( |
134 | | - collection: C, |
135 | | - ): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>; |
136 | | - |
137 | | - type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T; |
138 | | - type InferEntrySchema<C extends keyof AnyEntryMap> = import('astro/zod').infer< |
139 | | - ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']> |
140 | | - >; |
141 | | - |
142 | | - type ContentEntryMap = { |
143 | | - |
144 | | - }; |
145 | | - |
146 | | - type DataEntryMap = { |
147 | | - |
148 | | - }; |
149 | | - |
150 | | - type AnyEntryMap = ContentEntryMap & DataEntryMap; |
151 | | - |
152 | | - export type ContentConfig = never; |
153 | | -} |
0 commit comments