From e5500c4cc12d69ebac77c1cc0f43f31f4672e8ae Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 29 Jul 2024 19:22:48 +0200 Subject: [PATCH] fix(api-reference): add missing Since and Types in Content collections * See https://github.com/withastro/astro/pull/7607 for the most recent exported types * See https://github.com/withastro/astro/pull/6850 for `reference()` * See `packages/astro/types/content.d.ts` for `schema` type (might need a refactor) * `getDataEntryById` is missing but since `getEntryBySlug` is announced as deprecated I don't know if we should add it (so no change here) --- src/content/docs/en/reference/api-reference.mdx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/content/docs/en/reference/api-reference.mdx b/src/content/docs/en/reference/api-reference.mdx index ae1201fb929903..96b578a0f9e419 100644 --- a/src/content/docs/en/reference/api-reference.mdx +++ b/src/content/docs/en/reference/api-reference.mdx @@ -1149,6 +1149,8 @@ Content collections offer APIs to configure and query your Markdown or MDX docum ### `defineCollection()` +**Type:** `(input: CollectionConfig) => CollectionConfig` + `defineCollection()` is a utility to configure a collection in a `src/content/config.*` file. ```ts @@ -1187,7 +1189,7 @@ This means collections **cannot** store a mix of content and data formats. You m #### `schema` -**Type:** `TSchema extends ZodType` +**Type:** `TSchema extends ZodType | (context: SchemaContext) => TSchema extends ZodType` `schema` is an optional Zod object to configure the type and shape of document frontmatter for a collection. Each value must use [a Zod validator](https://github.com/colinhacks/zod). @@ -1195,6 +1197,8 @@ This means collections **cannot** store a mix of content and data formats. You m ### `reference()` +

+ **Type:** `(collection: string) => ZodEffects` The `reference()` function is used in the content config to define a relationship, or "reference," from one collection to another. This accepts a collection name and validates the entry identifier(s) specified in your content frontmatter or data file. @@ -1395,6 +1399,8 @@ The `astro:content` module also exports the following types for use in your Astr #### `CollectionKey` +

+ A string union of all collection names defined in your `src/content/config.*` file. This type can be useful when defining a generic function that accepts any collection name. ```ts @@ -1407,10 +1413,14 @@ async function getCollection(collection: CollectionKey) { #### `ContentCollectionKey` +

+ A string union of all the names of `type: 'content'` collections defined in your `src/content/config.*` file. #### `DataCollectionKey` +

+ A string union of all the names of `type: 'data'` collection defined in your `src/content/config.*` file. #### `SchemaContext`