Skip to content

Commit

Permalink
New astro:schema module (#11810)
Browse files Browse the repository at this point in the history
* feat: expose zod from astro:schema

* chore: changeset

* chore: update release strategy in changeset

* fix: move deprecated notice to type def

* fix: update config doc reference

* chore: remove z from astro:actions

* edit: changeset with minor release note remove

* wip: increase button click timeouts

* Revert "wip: increase button click timeouts"

This reverts commit a870bc2.

* chore: remove content collections disclaimer

* fix: undo biome change

* agh tabs

* agh newlines

* fix: bad docs merge

* wip: add back timeout extension

* fix(test): astro schema import
  • Loading branch information
bholmesdev authored Aug 28, 2024
1 parent 5caf8f2 commit 5a64889
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 16 deletions.
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' {
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db, Likes, eq, sql } from 'astro:db';
import { defineAction, z, type SafeResult } from 'astro:actions';
import { defineAction, type SafeResult } from 'astro:actions';
import { z } from 'astro:schema';
import { experimental_getActionState } from '@astrojs/react/actions';

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

0 comments on commit 5a64889

Please sign in to comment.