-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1176a1
commit c6d0e3d
Showing
92 changed files
with
1,260 additions
and
895 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Adds support for Zod discriminated unions on Action form inputs. This allows forms with different inputs to be submitted to the same action, using a given input to decide which object should be used for validation. | ||
|
||
This example accepts either a `create` or `update` form submission, and uses the `type` field to determine which object to validate against. | ||
|
||
```ts | ||
import { defineAction } from 'astro:actions'; | ||
import { z } from 'astro:schema'; | ||
|
||
export const server = { | ||
changeUser: defineAction({ | ||
accept: 'form', | ||
input: z.discriminatedUnion('type', [ | ||
z.object({ | ||
type: z.literal('create'), | ||
name: z.string(), | ||
email: z.string().email(), | ||
}), | ||
z.object({ | ||
type: z.literal('update'), | ||
id: z.number(), | ||
name: z.string(), | ||
email: z.string().email(), | ||
}), | ||
]), | ||
async handler(input) { | ||
if (input.type === 'create') { | ||
// input is { type: 'create', name: string, email: string } | ||
} else { | ||
// input is { type: 'update', id: number, name: string, email: string } | ||
} | ||
}, | ||
}), | ||
} | ||
``` | ||
|
||
The corresponding `create` and `update` forms may look like this: | ||
|
||
```astro | ||
--- | ||
import { actions } from 'astro:actions'; | ||
--- | ||
<!--Create--> | ||
<form action={actions.changeUser} method="POST"> | ||
<input type="hidden" name="type" value="create" /> | ||
<input type="text" name="name" required /> | ||
<input type="email" name="email" required /> | ||
<button type="submit">Create User</button> | ||
</form> | ||
<!--Update--> | ||
<form action={actions.changeUser} method="POST"> | ||
<input type="hidden" name="type" value="update" /> | ||
<input type="hidden" name="id" value="user-123" /> | ||
<input type="text" name="name" required /> | ||
<input type="email" name="email" required /> | ||
<button type="submit">Update User</button> | ||
</form> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
}, | ||
"dependencies": { | ||
"astro": "^5.0.0-alpha.6", | ||
"sass": "^1.77.8", | ||
"sass": "^1.78.0", | ||
"sharp": "^0.33.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ | |
"dependencies": { | ||
"@astrojs/vue": "workspace:*", | ||
"astro": "workspace:*", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ | |
"react-dom": "^18.3.1", | ||
"solid-js": "^1.8.22", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"sass": "^1.77.8" | ||
"sass": "^1.78.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
"private": true, | ||
"devDependencies": { | ||
"astro": "workspace:*", | ||
"sass": "^1.77.8" | ||
"sass": "^1.78.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,6 @@ | |
"react-dom": "^18.3.1", | ||
"solid-js": "^1.8.22", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ | |
"react-dom": "^18.3.1", | ||
"solid-js": "^1.8.22", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ | |
"react-dom": "^18.3.1", | ||
"solid-js": "^1.8.22", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ | |
"react-dom": "^18.3.1", | ||
"solid-js": "^1.8.22", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ | |
"react-dom": "^18.3.1", | ||
"solid-js": "^1.8.22", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,6 @@ | |
"react-dom": "^18.3.1", | ||
"solid-js": "^1.8.22", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/astro/e2e/fixtures/server-islands-key/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import node from '@astrojs/node'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
output: 'server', | ||
adapter: node({ mode: 'standalone' }), | ||
integrations: [], | ||
experimental: { | ||
serverIslands: true, | ||
} | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/astro/e2e/fixtures/server-islands-key/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@e2e/server-islands-key", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev" | ||
}, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/node": "^8.3.3" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/astro/e2e/fixtures/server-islands-key/src/components/Island.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
const { secret } = Astro.props; | ||
--- | ||
<h2 id="island">I am an island</h2> | ||
<slot /> | ||
<h3 id="secret">{secret}</h3> |
14 changes: 14 additions & 0 deletions
14
packages/astro/e2e/fixtures/server-islands-key/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
import Island from '../components/Island.astro'; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<!-- Head Stuff --> | ||
</head> | ||
<body> | ||
<Island server:defer secret="test"> | ||
<h3 id="children">children</h3> | ||
</Island> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,6 @@ | |
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"svelte": "^4.2.19", | ||
"vue": "^3.4.38" | ||
"vue": "^3.5.3" | ||
} | ||
} |
Oops, something went wrong.