Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New astro:schema module #11810

Merged
merged 17 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
17 changes: 17 additions & 0 deletions .changeset/perfect-wasps-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'astro': minor
---

Exposes `z` from the new `astro:schema` module. This is the new recommended import source for all Zod utilities when using Astro Actions.

## Migration for Astro Actions users

`z` will no longer be exposed from `astro:actions`. To use `z` in your actions, import it from `astro:schema` instead:

```diff
import {
defineAction,
- z,
} from 'astro:actions';
+ import { z } from 'astro:schema';
```
4 changes: 4 additions & 0 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ declare module 'astro:components' {
export * from 'astro/components';
}

declare module 'astro:schema' {
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
export * from 'astro/zod';
}

type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>;
interface ExportedMarkdownModuleEntities {
frontmatter: MD['frontmatter'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db, Comment, Likes, eq, sql } from 'astro:db';
import { ActionError, defineAction, z } from 'astro:actions';
import { ActionError, defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { getCollection } from 'astro:content';

export const server = {
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ process.stdout.isTTY = false;

export default defineConfig({
testMatch: 'e2e/*.test.js',
timeout: 40000,
timeout: 40_000,
expect: {
timeout: 6_000,
},
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/playwright.firefox.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ process.stdout.isTTY = false;
export default defineConfig({
// TODO: add more tests like view transitions and audits, and fix them. Some of them are failing.
testMatch: ['e2e/css.test.js', 'e2e/prefetch.test.js', 'e2e/view-transitions.test.js'],
timeout: 40000,
timeout: 40_000,
expect: {
timeout: 6_000,
},
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
Expand Down
9 changes: 0 additions & 9 deletions packages/astro/src/actions/runtime/virtual/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,3 @@ export * from './shared.js';
export function defineAction() {
throw new Error('[astro:action] `defineAction()` unexpectedly used on the client.');
}

export const z = new Proxy(
{},
{
get() {
throw new Error('[astro:action] `z` unexpectedly used on the client.');
},
},
);
2 changes: 0 additions & 2 deletions packages/astro/src/actions/runtime/virtual/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { ActionError, ActionInputError, type SafeResult, callSafely } from './sh

export * from './shared.js';

export { z } from 'zod';

export type ActionAccept = 'form' | 'json';

export type ActionHandler<TInputSchema, TOutput> = TInputSchema extends z.ZodType
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export async function createVite(
find: 'astro:middleware',
replacement: 'astro/virtual-modules/middleware.js',
},
{
find: 'astro:schema',
replacement: 'astro/zod',
},
{
find: 'astro:components',
replacement: 'astro/components',
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/test/fixtures/actions/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineAction, ActionError, z } from 'astro:actions';
import { defineAction, ActionError } from 'astro:actions';
import { z } from 'astro:schema';

const passwordSchema = z
.string()
Expand Down
Loading