content.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. export interface RenderedContent {
  11. html: string;
  12. metadata?: {
  13. imagePaths: Array<string>;
  14. [key: string]: unknown;
  15. };
  16. }
  17. }
  18. declare module 'astro:content' {
  19. type Flatten<T> = T extends { [K: string]: infer U } ? U : never;
  20. export type CollectionKey = keyof AnyEntryMap;
  21. export type CollectionEntry<C extends CollectionKey> = Flatten<AnyEntryMap[C]>;
  22. export type ContentCollectionKey = keyof ContentEntryMap;
  23. export type DataCollectionKey = keyof DataEntryMap;
  24. type AllValuesOf<T> = T extends any ? T[keyof T] : never;
  25. type ValidContentEntrySlug<C extends keyof ContentEntryMap> = AllValuesOf<
  26. ContentEntryMap[C]
  27. >['slug'];
  28. export type ReferenceDataEntry<
  29. C extends CollectionKey,
  30. E extends keyof DataEntryMap[C] = string,
  31. > = {
  32. collection: C;
  33. id: E;
  34. };
  35. export type ReferenceContentEntry<
  36. C extends keyof ContentEntryMap,
  37. E extends ValidContentEntrySlug<C> | (string & {}) = string,
  38. > = {
  39. collection: C;
  40. slug: E;
  41. };
  42. export type ReferenceLiveEntry<C extends keyof LiveContentConfig['collections']> = {
  43. collection: C;
  44. id: string;
  45. };
  46. /** @deprecated Use `getEntry` instead. */
  47. export function getEntryBySlug<
  48. C extends keyof ContentEntryMap,
  49. E extends ValidContentEntrySlug<C> | (string & {}),
  50. >(
  51. collection: C,
  52. // Note that this has to accept a regular string too, for SSR
  53. entrySlug: E,
  54. ): E extends ValidContentEntrySlug<C>
  55. ? Promise<CollectionEntry<C>>
  56. : Promise<CollectionEntry<C> | undefined>;
  57. /** @deprecated Use `getEntry` instead. */
  58. export function getDataEntryById<C extends keyof DataEntryMap, E extends keyof DataEntryMap[C]>(
  59. collection: C,
  60. entryId: E,
  61. ): Promise<CollectionEntry<C>>;
  62. export function getCollection<C extends keyof AnyEntryMap, E extends CollectionEntry<C>>(
  63. collection: C,
  64. filter?: (entry: CollectionEntry<C>) => entry is E,
  65. ): Promise<E[]>;
  66. export function getCollection<C extends keyof AnyEntryMap>(
  67. collection: C,
  68. filter?: (entry: CollectionEntry<C>) => unknown,
  69. ): Promise<CollectionEntry<C>[]>;
  70. export function getLiveCollection<C extends keyof LiveContentConfig['collections']>(
  71. collection: C,
  72. filter?: LiveLoaderCollectionFilterType<C>,
  73. ): Promise<
  74. import('astro').LiveDataCollectionResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>
  75. >;
  76. export function getEntry<
  77. C extends keyof ContentEntryMap,
  78. E extends ValidContentEntrySlug<C> | (string & {}),
  79. >(
  80. entry: ReferenceContentEntry<C, E>,
  81. ): E extends ValidContentEntrySlug<C>
  82. ? Promise<CollectionEntry<C>>
  83. : Promise<CollectionEntry<C> | undefined>;
  84. export function getEntry<
  85. C extends keyof DataEntryMap,
  86. E extends keyof DataEntryMap[C] | (string & {}),
  87. >(
  88. entry: ReferenceDataEntry<C, E>,
  89. ): E extends keyof DataEntryMap[C]
  90. ? Promise<DataEntryMap[C][E]>
  91. : Promise<CollectionEntry<C> | undefined>;
  92. export function getEntry<
  93. C extends keyof ContentEntryMap,
  94. E extends ValidContentEntrySlug<C> | (string & {}),
  95. >(
  96. collection: C,
  97. slug: E,
  98. ): E extends ValidContentEntrySlug<C>
  99. ? Promise<CollectionEntry<C>>
  100. : Promise<CollectionEntry<C> | undefined>;
  101. export function getEntry<
  102. C extends keyof DataEntryMap,
  103. E extends keyof DataEntryMap[C] | (string & {}),
  104. >(
  105. collection: C,
  106. id: E,
  107. ): E extends keyof DataEntryMap[C]
  108. ? string extends keyof DataEntryMap[C]
  109. ? Promise<DataEntryMap[C][E]> | undefined
  110. : Promise<DataEntryMap[C][E]>
  111. : Promise<CollectionEntry<C> | undefined>;
  112. export function getLiveEntry<C extends keyof LiveContentConfig['collections']>(
  113. collection: C,
  114. filter: string | LiveLoaderEntryFilterType<C>,
  115. ): Promise<import('astro').LiveDataEntryResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>>;
  116. /** Resolve an array of entry references from the same collection */
  117. export function getEntries<C extends keyof ContentEntryMap>(
  118. entries: ReferenceContentEntry<C, ValidContentEntrySlug<C>>[],
  119. ): Promise<CollectionEntry<C>[]>;
  120. export function getEntries<C extends keyof DataEntryMap>(
  121. entries: ReferenceDataEntry<C, keyof DataEntryMap[C]>[],
  122. ): Promise<CollectionEntry<C>[]>;
  123. export function render<C extends keyof AnyEntryMap>(
  124. entry: AnyEntryMap[C][string],
  125. ): Promise<RenderResult>;
  126. export function reference<C extends keyof AnyEntryMap>(
  127. collection: C,
  128. ): import('astro/zod').ZodEffects<
  129. import('astro/zod').ZodString,
  130. C extends keyof ContentEntryMap
  131. ? ReferenceContentEntry<C, ValidContentEntrySlug<C>>
  132. : ReferenceDataEntry<C, keyof DataEntryMap[C]>
  133. >;
  134. // Allow generic `string` to avoid excessive type errors in the config
  135. // if `dev` is not running to update as you edit.
  136. // Invalid collection names will be caught at build time.
  137. export function reference<C extends string>(
  138. collection: C,
  139. ): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>;
  140. type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T;
  141. type InferEntrySchema<C extends keyof AnyEntryMap> = import('astro/zod').infer<
  142. ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']>
  143. >;
  144. type ContentEntryMap = {
  145. };
  146. type DataEntryMap = {
  147. };
  148. type AnyEntryMap = ContentEntryMap & DataEntryMap;
  149. type ExtractLoaderTypes<T> = T extends import('astro/loaders').LiveLoader<
  150. infer TData,
  151. infer TEntryFilter,
  152. infer TCollectionFilter,
  153. infer TError
  154. >
  155. ? { data: TData; entryFilter: TEntryFilter; collectionFilter: TCollectionFilter; error: TError }
  156. : { data: never; entryFilter: never; collectionFilter: never; error: never };
  157. type ExtractDataType<T> = ExtractLoaderTypes<T>['data'];
  158. type ExtractEntryFilterType<T> = ExtractLoaderTypes<T>['entryFilter'];
  159. type ExtractCollectionFilterType<T> = ExtractLoaderTypes<T>['collectionFilter'];
  160. type ExtractErrorType<T> = ExtractLoaderTypes<T>['error'];
  161. type LiveLoaderDataType<C extends keyof LiveContentConfig['collections']> =
  162. LiveContentConfig['collections'][C]['schema'] extends undefined
  163. ? ExtractDataType<LiveContentConfig['collections'][C]['loader']>
  164. : import('astro/zod').infer<
  165. Exclude<LiveContentConfig['collections'][C]['schema'], undefined>
  166. >;
  167. type LiveLoaderEntryFilterType<C extends keyof LiveContentConfig['collections']> =
  168. ExtractEntryFilterType<LiveContentConfig['collections'][C]['loader']>;
  169. type LiveLoaderCollectionFilterType<C extends keyof LiveContentConfig['collections']> =
  170. ExtractCollectionFilterType<LiveContentConfig['collections'][C]['loader']>;
  171. type LiveLoaderErrorType<C extends keyof LiveContentConfig['collections']> = ExtractErrorType<
  172. LiveContentConfig['collections'][C]['loader']
  173. >;
  174. export type ContentConfig = typeof import("../src/content.config.mjs");
  175. export type LiveContentConfig = never;
  176. }