Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/content/docs/en/guides/actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Actions are defined in a `server` object exported from `src/actions/index.ts`:

```ts title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
myAction: defineAction({ /* ... */ })
Expand Down Expand Up @@ -62,11 +62,11 @@ Follow these steps to define an action and call it in a `script` tag in your Ast
}
```

2. Import the `defineAction()` utility from `astro:actions`, and the `z` object from `astro:schema`.
2. Import the `defineAction()` utility from `astro:actions`, and the `z` object from `astro/zod`.

```ts ins={1-2} title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
// action declarations
Expand All @@ -77,7 +77,7 @@ Follow these steps to define an action and call it in a `script` tag in your Ast

```ts ins={5-12} title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
getGreeting: defineAction({
Expand Down Expand Up @@ -213,7 +213,7 @@ This example throws an error from a `likePost` action when a user is not logged

```ts title="src/actions/index.ts" ins=/ActionError(?= )/ ins={9-12}
import { defineAction, ActionError } from "astro:actions";
import { z } from "astro:schema";
import { z } from "astro/zod";

export const server = {
likePost: defineAction({
Expand Down Expand Up @@ -290,7 +290,7 @@ Actions accept JSON data by default. To accept form data from an HTML form, set

```ts title="src/actions/index.ts" ins={6}
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
comment: defineAction({
Expand Down Expand Up @@ -319,7 +319,7 @@ To apply a union of different validators, use the `z.discriminatedUnion()` wrapp

```ts title="src/actions/index.ts" {7-21} "create" "update"
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
changeUser: defineAction({
Expand Down Expand Up @@ -378,7 +378,7 @@ The following example shows a validated newsletter registration form that accept

```ts title="src/actions/index.ts" ins={5-12}
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
newsletter: defineAction({
Expand Down Expand Up @@ -492,7 +492,7 @@ For example, say you have a `createProduct` action that returns the generated pr

```ts title="src/actions/index.ts" mark={10}
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
createProduct: defineAction({
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/en/guides/astro-db.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ You can also use [Astro actions](/en/guides/actions/) to insert data into an Ast
// src/actions/index.ts
import { db, Comment } from 'astro:db';
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
addComment: defineAction({
Expand Down
21 changes: 13 additions & 8 deletions src/content/docs/en/guides/content-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ Individual collections use `defineCollection()` to configure:
To define collections, you must create a `src/content.config.ts` file in your project (`.js` and `.mjs` extensions are also supported.) This is a special file that Astro will use to configure your content collections based on the following structure:

```ts title="src/content.config.ts"
// 1. Import utilities from `astro:content`
import { defineCollection, z } from 'astro:content';
// 1. Import utilities from `astro:content` and `astro/zod`
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';

// 2. Import loader(s)
import { glob, file } from 'astro/loaders';
Expand All @@ -89,8 +90,9 @@ The [`glob()` loader](/en/reference/content-loader-reference/#glob-loader) creat

The [`file()` loader](/en/reference/content-loader-reference/#file-loader) creates multiple entries from a single local file. Each entry in the file must have a unique `id` key property. It accepts a `base` file path to your file and optionally a [`parser` function](#parser-function) for data files it cannot parse automatically. Use this loader when your data file can be parsed as an array of objects.

```ts title="src/content.config.ts" {5,9}
import { defineCollection, z } from 'astro:content';
```ts title="src/content.config.ts" {6,10}
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob, file } from 'astro/loaders'; // Not available with legacy API

const blog = defineCollection({
Expand Down Expand Up @@ -210,8 +212,9 @@ In order for Astro to recognize a new or updated schema, you may need to restart

Every frontmatter or data property of your collection entries must be defined using a Zod data type:

```ts title="src/content.config.ts" {6-11,15-19}
import { defineCollection, z } from 'astro:content';
```ts title="src/content.config.ts" {7-12,16-20}
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob, file } from 'astro/loaders'; // Not available with legacy API

const blog = defineCollection({
Expand Down Expand Up @@ -243,7 +246,8 @@ To use Zod in Astro, import the `z` utility from `"astro:content"`. This is a re

```ts
// Example: A cheatsheet of many common Zod datatypes
import { z, defineCollection } from 'astro:content';
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';

defineCollection({
schema: z.object({
Expand Down Expand Up @@ -286,7 +290,8 @@ With the [`reference()` function](/en/reference/modules/astro-content/#reference
A common example is a blog post that references reusable author profiles stored as JSON, or related post URLs stored in the same collection:

```ts title="src/content.config.ts"
import { defineCollection, reference, z } from 'astro:content';
import { defineCollection, reference } from 'astro:content';
import { z } from 'astro/zod';
import { glob } from 'astro/loaders';

const blog = defineCollection({
Expand Down
3 changes: 2 additions & 1 deletion src/content/docs/en/guides/images.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ This is a blog post
The `image` helper for the content collections schema lets you validate and import the image.

```ts title="src/content.config.ts"
import { defineCollection, z } from "astro:content";
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';

const blogCollection = defineCollection({
schema: ({ image }) => z.object({
Expand Down
3 changes: 2 additions & 1 deletion src/content/docs/en/guides/integrations-guide/mdx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ It also adds extra features to standard MDX, including support for Markdown-styl
To include MDX files in a content collection, make sure that your [collection loader](/en/guides/content-collections/#defining-the-collection-loader) is configured to load content from `.mdx` files:

```js title="src/content.config.ts" ins="mdx"
import { defineCollection, z } from 'astro:content';
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob } from 'astro/loaders';

const blog = defineCollection({
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/en/guides/integrations-guide/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ The example below gets the current value of likes from a counter, typed as a num

```ts title="actions.ts" ins={3,11}
import { defineAction, type SafeResult } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';
import { getActionState } from '@astrojs/react/actions';

export const server = {
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/en/guides/sessions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ In actions, the session object is available on the `context` object. For example

```ts title="src/actions/addToCart.ts" "context.session"
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
addToCart: defineAction({
Expand Down
35 changes: 31 additions & 4 deletions src/content/docs/en/guides/upgrade-to/v6.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,31 @@ someLogic(build.assetsPrefix)

<ReadMore>Read more about the [`astro:config` virtual modules](/en/reference/modules/astro-config/).</ReadMore>

### Deprecated: `astro:schema` and `z` from `astro:content`

<SourcePR number="14923" title="feat!: consolidate zod export" />

In Astro 5.x, `astro:schema` was introduced as an alias of `astro/zod`. `z` was also exported from `astro:content` for convenience. However that created confusion for users who did not know what to import from where.

Astro 6.0 deprecates `astro:schema` and `z` from `astro:content` in favor of `astro/zod`.

#### What should I do?

Replace any occurrences of `astro:schema` with `astro/zod`:

```ts del={1} ins={2}
import { z } from "astro:schema"
import { z } from "astro/zod"
```

Check your `astro:content` imports and update them if you import `z`:

```ts title="src/content.config.ts" del={1} ins={2-3}
import { defineCollection, z } from "astro:content"
import { defineCollection } from "astro:content"
import { z } from "astro/zod"
```

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add a ReadMore here because we don't have a page for astro/zod yet, see #12814

## Removed

The following features have now been entirely removed from the code base and can no longer be used. Some of these features may have continued to work in your project even after deprecation. Others may have silently had no effect.
Expand Down Expand Up @@ -207,9 +232,10 @@ Rename and move this file to `src/content.config.ts`

Import [Astro's built-in `glob()` loader](/en/guides/content-collections/#built-in-loaders) and define the `pattern` and `base` for your collection entries:

```ts ins={3,6}
```ts ins={4,7}
// src/content.config.ts
import { defineCollection, z } from 'astro:content';
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob } from 'astro/loaders';

const blog = defineCollection({
Expand All @@ -228,9 +254,10 @@ const blog = defineCollection({
<summary>a collection that defines a collection type (`type: 'content'` or `type: 'data'`) / ([`ContentCollectionInvalidTypeError`](/en/reference/errors/content-collection-invalid-type/))</summary>
There are no longer different types of collections. This must be deleted from your collection definition.

```ts del={7}
```ts del={8}
// src/content.config.ts
import { defineCollection, z } from 'astro:content';
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob } from 'astro/loaders';

const blog = defineCollection({
Expand Down
3 changes: 2 additions & 1 deletion src/content/docs/en/recipes/i18n.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ If you prefer the default language to not be visible in the URL unlike other lan

```ts
//src/content.config.ts
import { defineCollection, z } from 'astro:content';
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';

const blogCollection = defineCollection({
schema: z.object({
Expand Down
7 changes: 4 additions & 3 deletions src/content/docs/en/reference/content-loader-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ The recommended pattern is to define a function that accepts configuration optio

```ts title=loader.ts
import type { Loader, LoaderContext } from 'astro/loaders';
import { z } from 'astro:content';
import { z } from 'astro/zod';
import { loadFeedData } from "./feed.js";

// Define any options that the loader needs
Expand All @@ -209,8 +209,9 @@ export function myLoader(options: { url: string, apiKey: string }): Loader {

These configuration options can then be set when defining a collection:

```ts title="src/content.config.ts" {2,5-8}
import { defineCollection, z } from 'astro:content';
```ts title="src/content.config.ts" {3,6-9}
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import myLoader from '../../loader.ts';

const blog = defineCollection({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ if (error) {
Just like with build-time collections, you can use [Zod schemas](/en/guides/content-collections/#defining-the-collection-schema) with live collections to validate and transform data at runtime. When you define a schema, it takes precedence over [the loader's types](#type-safe-data) when you query the collection:

```ts title="src/live.config.ts"
import { z, defineLiveCollection } from 'astro:content';
import { defineLiveCollection } from 'astro:content';
import { z } from 'astro/zod';
import { apiLoader } from './loaders/api-loader';

const products = defineLiveCollection({
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/en/reference/modules/astro-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ A utility to define new actions in the `src/actions/index.ts` file. This accepts

```ts title="src/actions/index.ts"
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { z } from 'astro/zod';

export const server = {
getGreeting: defineAction({
Expand Down
10 changes: 6 additions & 4 deletions src/content/docs/en/reference/modules/astro-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Content collections offer APIs to configure and query your Markdown or MDX docum

```js
import {
z,
defineCollection,
getCollection,
getEntry,
Expand All @@ -38,7 +37,8 @@ import {
`defineCollection()` is a utility to configure a collection in a `src/content.config.*` file.

```ts title="src/content.config.ts"
import { z, defineCollection } from 'astro:content';
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob } from 'astro/loaders';

const blog = defineCollection({
Expand Down Expand Up @@ -94,7 +94,8 @@ The `reference()` function is used in the content config to define a relationshi
This example defines references from a blog author to the `authors` collection and an array of related posts to the same `blog` collection:

```ts
import { defineCollection, reference, z } from 'astro:content';
import { defineCollection, reference } from 'astro:content';
import { z } from 'astro/zod';
import { glob, file } from 'astro/loaders';

const blog = defineCollection({
Expand Down Expand Up @@ -304,7 +305,8 @@ This includes the following property:
- `image` - The `image()` schema helper that allows you [to use local images in Content Collections](/en/guides/images/#images-in-content-collections)

```ts
import { defineCollection, z, type SchemaContext } from "astro:content";
import { defineCollection, type SchemaContext } from 'astro:content';
import { z } from 'astro/zod';

export const imageSchema = ({ image }: SchemaContext) =>
z.object({
Expand Down