Skip to content

Commit

Permalink
fix(api-reference): add missing Since and Types in Content collections
Browse files Browse the repository at this point in the history
* See withastro/astro#7607 for the most recent
exported types
* See withastro/astro#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)
  • Loading branch information
ArmandPhilippot committed Jul 29, 2024
1 parent 6c4017c commit 8025c4d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/content/docs/en/reference/api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1187,14 +1189,16 @@ 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).

[See the `Content Collection` guide](/en/guides/content-collections/#defining-a-collection-schema) for example usage.

### `reference()`

<p><Since v="2.5.0" /></p>

**Type:** `(collection: string) => ZodEffects<ZodString, { collection, id: string } | { collection, slug: string }>`

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.
Expand Down Expand Up @@ -1395,6 +1399,8 @@ The `astro:content` module also exports the following types for use in your Astr

#### `CollectionKey`

<p><Since v="3.1.0" /></p>

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
Expand All @@ -1407,10 +1413,14 @@ async function getCollection(collection: CollectionKey) {

#### `ContentCollectionKey`

<p><Since v="3.1.0" /></p>

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

#### `DataCollectionKey`

<p><Since v="3.1.0" /></p>

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

#### `SchemaContext`
Expand Down

0 comments on commit 8025c4d

Please sign in to comment.