Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/content/docs/de/tutorial/6-islands/4.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ Aktualisiere Astro und alle Integrationen auf die neuesten Versionen, indem du i

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

const blog = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }),
Expand Down
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
16 changes: 10 additions & 6 deletions src/content/docs/en/guides/content-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ Each individual collection configures:
- [a build-time `schema`](#defining-the-collection-schema) for type safety (optional, but highly recommended!)

```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 } from 'astro/loaders';
Expand Down Expand Up @@ -332,7 +333,8 @@ In order for Astro to recognize a new or updated schema, you may need to restart
Providing a `schema` is optional, but highly recommended! If you choose to use a schema, then every frontmatter or data property of your collection entries must be defined using a [Zod data type](#defining-datatypes-with-zod):

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

const blog = defineCollection({
Expand Down Expand Up @@ -360,11 +362,12 @@ export const collections = { blog, dogs };

Astro uses [Zod](https://github.com/colinhacks/zod) to power its content schemas. With Zod, Astro is able to validate every file's data within a collection *and* provide automatic TypeScript types when you query content from inside your project.

To use Zod in Astro, import the `z` utility from `"astro:content"`. This is a re-export of the Zod library, and it supports all of the features of Zod 3.
To use Zod in Astro, import the `z` utility from `"astro/zod"`. This is a re-export of the Zod library, and it supports all of the features of Zod 3.

```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 @@ -405,7 +408,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 your local MDX files in a content collection, make sure that your [collection loader](/en/guides/content-collections/#build-time-collection-loaders) 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 this occasionally created confusion for users who were unsure about where they should be importing from.

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"
```

Remove `z` from your `astro:content` imports and import `z` separately from `astro/zod` instead:

```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"
```
<ReadMore>See more about [defining collection schemas with Zod](/en/guides/content-collections/#defining-datatypes-with-zod).</ReadMore>
## 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/#the-glob-loader) 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
2 changes: 1 addition & 1 deletion src/content/docs/en/reference/content-loader-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ The following example shows a loader that fetches data from a provided feed URL
```ts title="src/feed-loader.ts"
// 1. Import the `Loader` type and any other dependencies needed
import type { Loader } from 'astro/loaders';
import { z } from 'astro:content';
import { z } from 'astro/zod';
import { loadFeedData } from "./feed.js";

// 2. Define any options that your loader needs
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 @@ -24,7 +24,6 @@ For features and usage examples, [see our content collections guide](/en/guides/

```js
import {
z,
defineCollection,
defineLiveCollection,
getCollection,
Expand All @@ -48,7 +47,8 @@ import {
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 @@ -157,7 +157,8 @@ A function used in the content config to define a relationship, or "reference",
This example defines references from a blog author to the `authors` collection and an array of related posts to the same `blog` 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, file } from 'astro/loaders';

const blog = defineCollection({
Expand Down Expand Up @@ -450,7 +451,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 title="src/content.config.ts" "SchemaContext" {4-8,12,15}
import { defineCollection, z, type SchemaContext } from "astro:content";
import { defineCollection, type SchemaContext } from "astro:content";
import { z } from 'astro/zod';
import { glob } from 'astro/loaders';

export const imageSchema = ({ image }: SchemaContext) =>
Expand Down
5 changes: 3 additions & 2 deletions src/content/docs/en/tutorial/6-islands/4.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ Upgrade to the latest version of Astro, and upgrade all integrations to their la
```ts title="src/content.config.ts"
// Import the glob loader
import { glob } from "astro/loaders";
// Import utilities from `astro:content`
import { z, defineCollection } from "astro:content";
// Import utilities from `astro:content` and `astro/zod`
import { defineCollection } from "astro:content";
import { z } from 'astro/zod';
// Define a `loader` and `schema` for each collection
const blog = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }),
Expand Down
3 changes: 2 additions & 1 deletion src/content/docs/es/guides/images.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ Contenido del post de blog.
El helper `image` para el esquema de colecciones de contenido te permite validar e importar la imagen.

```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/es/reference/legacy-flags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Cuando estés listo para eliminar este flag y migrar a la nueva API de Content L

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

const blog = defineCollection({ })

Expand Down
5 changes: 3 additions & 2 deletions src/content/docs/es/tutorial/6-islands/4.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ Actualiza a la última versión de Astro y actualiza todas las integraciones a s
```ts title="src/content.config.ts"
// Importa el cargador glob
import { glob } from "astro/loaders";
// Importa utilidades de `astro:content`
import { z, defineCollection } from "astro:content";
// Importa utilidades de `astro:content` y `astro/zod`
import { defineCollection } from "astro:content";
import { z } from "astro/zod";
// Define un `loader` y un `schema` para cada colección
const blog = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }),
Expand Down
Loading
Loading