-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actions: Add
devalue
for serializing complex values (#11593)
* wip: move getActionResult setup to render * feat: serialize action data for edge * refactor: serializeActionResult util * feat: introduce devalue for body parsing * refactor: orthrow -> main * feat(test): Date and Set * refactor: move getAction to separate file for bundling * docs: changeset * Revert "refactor: move getAction to separate file for bundling" This reverts commit ef2b409. * Revert "Revert "refactor: move getAction to separate file for bundling"" This reverts commit 40deaed. * fix: actions import from client * feat: add support for URL objects * refactor: new isActionError utility * refactor: reuse isInputError in fromJson * fix: use INTERNAL_SERVER_ERROR for unknown errors
- Loading branch information
1 parent
3f27c9d
commit 81d7150
Showing
12 changed files
with
260 additions
and
190 deletions.
There are no files selected for viewing
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,7 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Adds support for `Date()`, `Map()`, and `Set()` from action results. See [devalue](https://github.com/Rich-Harris/devalue) for a complete list of supported values. | ||
|
||
Also fixes serialization exceptions when deploying Actions with edge middleware on Netlify and Vercel. |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { ZodType } from 'zod'; | ||
import type { ActionAccept, ActionClient } from './server.js'; | ||
|
||
/** | ||
* Get server-side action based on the route path. | ||
* Imports from the virtual module `astro:internal-actions`, which maps to | ||
* the user's `src/actions/index.ts` file at build-time. | ||
*/ | ||
export async function getAction( | ||
path: string | ||
): Promise<ActionClient<unknown, ActionAccept, ZodType> | undefined> { | ||
const pathKeys = path.replace('/_actions/', '').split('.'); | ||
// @ts-expect-error virtual module | ||
let { server: actionLookup } = await import('astro:internal-actions'); | ||
|
||
for (const key of pathKeys) { | ||
if (!(key in actionLookup)) { | ||
return undefined; | ||
} | ||
actionLookup = actionLookup[key]; | ||
} | ||
if (typeof actionLookup !== 'function') { | ||
return undefined; | ||
} | ||
return actionLookup; | ||
} |
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
Oops, something went wrong.