ì¡ì API 참조
ì¶ê°ë ë²ì :
astro@4.15.0
ì¡ì
ì ì¬ì©íë©´ í´ë¼ì´ì¸í¸ ì½ë ë° HTML ìììì í¸ì¶í ì ìë íì
ìì ì±ì ê°ì¶ ë°±ìë를 구ì¶í ì ììµëë¤. ì¡ì
ì ì ìíê³ í¸ì¶íë 모ë ì í¸ë¦¬í°ë astro:actions 모ëì ìí´ ë
¸ì¶ë©ëë¤. ìì ë° ì¬ì© ì§ì¹¨ì ì¡ì
ê°ì´ë를 참조íì¸ì.
astro:actionsìì ê°ì ¸ì¤ê¸°
ì¹ì
ì 목: âastro:actionsìì ê°ì ¸ì¤ê¸°âimport { ACTION_QUERY_PARAMS, ActionError, actions, defineAction, getActionContext, getActionPath, isActionError, isInputError, } from 'astro:actions';defineAction()
ì¹ì
ì 목: âdefineAction()âíì
: ({ accept, input, handler }) => ActionClient
src/actions/index.ts íì¼ìì ì ì¡ì
ì ì ìí기 ìí ì í¸ë¦¬í°ì
ëë¤. ì´ í¨ìë ì¤íí ìë² ë¡ì§ì´ í¬í¨ë handler() í¨ìì ë°íìì ì
ë ¥ 매ê°ë³ì를 ê²ì¬íë ì íì ì¸ input ìì±ì ë°ìµëë¤.
import { defineAction } from 'astro:actions';import { z } from 'astro/zod';
export const server = { getGreeting: defineAction({ input: z.object({ name: z.string(), }), handler: async (input, context) => { return `Hello, ${input.name}!` } })}handler() ìì±
ì¹ì
ì 목: âhandler() ìì±âíì
: (input: TInputSchema, context: ActionAPIContext) => TOutput | Promise<TOutput>
ì¡ì
ì í¸ì¶í ë ì¤íí ìë² ë¡ì§ì í¬í¨íë íì í¨ìì
ëë¤. handler()ìì ë°íë ë°ì´í°ë ìëì¼ë¡ ì§ë ¬íëì´ í¸ì¶ììê² ì ì¡ë©ëë¤.
handler()ë ì¬ì©ì ì
ë ¥ì 첫 ë²ì§¸ ì¸ìë¡ ë°ì í¸ì¶ë©ëë¤. input ì í¨ì± ê²ì¬ê¸°ê° ì¤ì ëì´ ìì¼ë©´ ì¬ì©ì ì
ë ¥ì í¸ë¤ë¬ë¡ ì ë¬ë기 ì ì ì í¨ì±ì´ ê²ì¬ë©ëë¤. ë ë²ì§¸ ì¸ìë Astro context ê°ì²´ì íì ì§í©ì
ëë¤.
ë°í ê°ì devalue ë¼ì´ë¸ë¬ë¦¬ë¥¼ ì¬ì©íì¬ êµ¬ë¬¸ ë¶ìë©ëë¤. ì´ ë¼ì´ë¸ë¬ë¦¬ë Date(), Map(), Set(), URL()ì ì¸ì¤í´ì¤ì JSON ê°ì ì§ìí©ëë¤.
input ì í¨ì± ê²ì¬ê¸°
ì¹ì
ì 목: âinput ì í¨ì± ê²ì¬ê¸°âíì
: ZodType | undefined
ë°íìì í¸ë¤ë¬ ì
ë ¥ì ì í¨ì±ì ê²ì¬í기 ìí´ Zod ì í¨ì± ê²ì¬ê¸° (ì: Zod ê°ì²´, Zod 구ë³ë ì ëì¨)를 íì©íë ì íì ìì±ì
ëë¤. ì¡ì
ì´ ì í¨ì± ê²ì¬ì ì¤í¨íë©´ BAD_REQUEST ì¤ë¥ê° ë°íëê³ handlerê° í¸ì¶ëì§ ììµëë¤.
inputì ìëµíë©´ handlerë JSON ìì²ì ê²½ì° unknown íì
ì ì
ë ¥ì, ìì ìì²ì ê²½ì° FormData íì
ì ì
ë ¥ì ë°ìµëë¤.
accept ìì±
ì¹ì
ì 목: âaccept ìì±âíì
: "form" | "json"
기본ê°: json
ì¡ì ì´ ììíë íìì ì ìí©ëë¤.
- ì¡ì
ì´
FormData를 íì©íë ê²½ì°formì ì¬ì©í©ëë¤. - 기본ê°ì¸
jsonì ë¤ë¥¸ 모ë ê²½ì°ì ì¬ì©ë©ëë¤.
ì¡ì
ì´ ìì ì
ë ¥ì íì©íë ê²½ì°, z.object() ì í¨ì± ê²ì¬ê¸°ê° FormData를 íì
ì´ ì ìë ê°ì²´ë¡ 구문 ë¶ìí©ëë¤. ì
ë ¥ì ê²ì¦í기 ìí´ ëª¨ë Zod ì í¨ì± ê²ì¬ê¸°ë¥¼ ì¬ì©í ì ììµëë¤.
actions
ì¹ì
ì 목: âactionsâíì
: Record<string, ActionClient>
모ë ì¡ì ì ë´ê³ ìë ê°ì²´ì´ë©°, ì¡ì ì´ë¦ì´ í¤ê° ëê³ í´ë¹ ì¡ì ì í¸ì¶íë í¨ìê° ê°ì´ ë©ëë¤.
------
<script>import { actions } from 'astro:actions';
async () => { const { data, error } = await actions.myAction({ /* ... */ });}</script>Astroê° ì´ ìì±ì ì¸ìíê² íë ¤ë©´ ê°ë° ìë²ë¥¼ ë¤ì ììíê±°ë astro sync ëª
ë ¹ì ì¤í(s + enter)í´ì¼ í ì ììµëë¤.
isInputError()
ì¹ì
ì 목: âisInputError()âíì
: (error?: unknown) => boolean
ActionErrorê° ì
ë ¥ ì í¨ì± ê²ì¬ ì¤ë¥ì¸ì§ íì¸íë ë° ì¬ì©ëë ì í¸ë¦¬í°ì
ëë¤. input ì í¨ì± ê²ì¬ê¸°ê° z.object()ì¸ ê²½ì° ì
ë ¥ ì¤ë¥ìë ì´ë¦ë³ë¡ 그룹íë ì¤ë¥ ë©ìì§ê° ìë fields ê°ì²´ê° í¬í¨ë©ëë¤.
isInputError() ì¬ì©ì ëí ìì¸í ë´ì©ì 참조íì¸ì.
isActionError()
ì¹ì
ì 목: âisActionError()âíì
: (error?: unknown) => boolean
handler ìì±ìì ì¡ì ì´ ActionError를 ë°ììì¼°ëì§ íì¸íë ë° ì¬ì©ëë ì í¸ë¦¬í°ì ëë¤. ì´ë ì¼ë°ì ì¸ ì¤ë¥ì ì íì ì¢í ë ì ì©í©ëë¤.
------
<script>import { isActionError, actions } from 'astro:actions';
async () => { const { data, error } = await actions.myAction({ /* ... */ }); if (isActionError(error)) { // ì¡ì
ë³ ì¤ë¥ë¥¼ ì²ë¦¬í©ëë¤. console.log(error.code); }}</script>ActionError
ì¹ì
ì 목: âActionErrorâì¡ì
handlerê° ëì§ë ì¤ë¥ë¥¼ ìì±íë ë° ActionError() ìì±ìê° ì¬ì©ë©ëë¤. ì´ë ë°ìí ì¤ë¥ (ì: "UNAUTHORIZED")를 ì¤ëª
íë code ìì±ê³¼ ì¶ê° ì¸ë¶ì ë³´ê° í¬í¨ë ì íì message ìì±ì íì©í©ëë¤.
ë¤ìì ì¬ì©ìê° ë¡ê·¸ì¸íì§ ììì ë ì ActionError를 ìì±íë ììì
ëë¤.
import { defineAction, ActionError } from "astro:actions";
export const server = { getUserOrThrow: defineAction({ accept: 'form', handler: async (_, { locals }) => { if (locals.user?.name !== 'florian') { throw new ActionError({ code: 'UNAUTHORIZED', message: 'ë¡ê·¸ì¸íì§ ìììµëë¤.', }); } return locals.user; }, }),}ActionError를 ì¬ì©íì¬ ì¡ì
ê²°ê³¼ ì²ë¦¬ ì ì¤ë¥ ì íì ì¢í ìë ììµëë¤.
------
<script>import { ActionError, actions } from 'astro:actions';
async () => { const { data, error } = await actions.myAction({ /* ... */ }); if (error instanceof ActionError) { // ì¡ì
ë³ ì¤ë¥ë¥¼ ì²ë¦¬í©ëë¤. console.log(error.code); }}</script>íì
: ActionErrorCode
ì¬ëì´ ì½ì ì ìë ë²ì ì HTTP ìí ì½ë를 ì ìí©ëë¤.
message
ì¹ì
ì 목: âmessageâíì
: string
ì íì ìì±ì¼ë¡, ì¤ë¥ë¥¼ ì¤ëª í©ëë¤. (ì: âì¬ì©ìë ë¡ê·¸ì¸í´ì¼ í©ëë¤.â)
íì
: string
ì íì ìì±ì¼ë¡, ì¤í í¸ë ì´ì¤ë¥¼ ì ë¬í©ëë¤.
getActionContext()
ì¹ì
ì 목: âgetActionContext()âíì
: (context: APIContext) => AstroActionContext
astro@5.0.0
미ë¤ì¨ì´ í¸ë¤ë¬ìì í¸ì¶ëì´, ë¤ì´ì¤ë ì¡ì
ìì²ì ëí ì 보를 ê²ìíë í¨ìì
ëë¤. ì´ í¨ìë ìì²ì ëí ì ë³´ê° ë´ê¸´ action ê°ì²´, deserializeActionResult() ë©ìë, ê·¸ë¦¬ê³ Astro.getActionResult()ê° ë°ííë ê°ì íë¡ê·¸ëë° ë°©ìì¼ë¡ ì¤ì í기 ìí setActionResult() ë° serializeActionResult() í¨ì를 ë°íí©ëë¤.
getActionContext()를 ì¬ì©íë©´ 미ë¤ì¨ì´ë¥¼ íµí´ ì¡ì
결과를 íë¡ê·¸ëë° ë°©ìì¼ë¡ ê°ì ¸ì ì¤ì í ì ìì´, HTML ììì ì¡ì
결과를 ì ì§íê³ ë³´ì ê²ì¬ë¥¼ ì¶ê°íì¬ ì¡ì
ìì²ì ì ííë ë±ì ìì
ì´ ê°ë¥í©ëë¤.
import { defineMiddleware } from 'astro:middleware';import { getActionContext } from 'astro:actions';
export const onRequest = defineMiddleware(async (context, next) => { const { action, setActionResult, serializeActionResult } = getActionContext(context); if (action?.calledFrom === 'form') { const result = await action.handler(); setActionResult(action.name, serializeActionResult(result)); } return next();});íì
: { calledFrom: ârpcâ | âformâ; name: string; handler: () => Promise<SafeResult>; } | undefined
ë¤ì´ì¤ë ì¡ì
ìì²ì ëí ì 보를 ë´ê³ ìë ê°ì²´ì
ëë¤. getActionContext()ìì ì¬ì©í ì ìì¼ë©°, ì¡ì
ì name, handler, ê·¸ë¦¬ê³ ì¡ì
ì´ í´ë¼ì´ì¸í¸ 측 RPC í¨ì(ì: actions.newsletter()) ëë HTML ìì ì¡ì
ìì í¸ì¶ëìëì§ ì¬ë¶ë¥¼ ì ê³µí©ëë¤.
import { defineMiddleware } from 'astro:middleware';import { getActionContext } from 'astro:actions';
export const onRequest = defineMiddleware(async (context, next) => { const { action, setActionResult, serializeActionResult } = getActionContext(context); if (action?.calledFrom === 'rpc' && action.name.startsWith('private')) { // ì í¨í ì¸ì
í í° ê²ì¬ } // ...});action.calledFrom
ì¹ì
ì 목: âaction.calledFromâíì
: "rpc" | "form"
ì¡ì ì´ RPC í¨ì ëë HTML ìì ì¡ì ì ì¬ì©íì¬ í¸ì¶ëìëì§ ì¬ë¶ì ëë¤.
action.name
ì¹ì
ì 목: âaction.nameâíì
: string
ì¡ì ì ì´ë¦ì ëë¤. 리ëë ì ì¤ì ì¡ì ê²°ê³¼ì ì¶ì²ë¥¼ ì¶ì íë ë° ì ì©í©ëë¤.
action.handler()
ì¹ì
ì 목: âaction.handler()âíì
: () => Promise<SafeResult>
결과를 ì»ê¸° ìí´ ì¡ì ì íë¡ê·¸ëë° ë°©ìì¼ë¡ í¸ì¶íë ë©ìëì ëë¤.
setActionResult()
ì¹ì
ì 목: âsetActionResult()âíì
: (actionName: string, actionResult: SerializedActionResult) => void
미ë¤ì¨ì´ìì Astro.getActionResult()ê° ë°ííë ê°ì íë¡ê·¸ëë° ë°©ìì¼ë¡ ì¤ì íë í¨ìì
ëë¤. ì´ í¨ììë ì¡ì
ì´ë¦ê³¼ serializeActionResult()ë¡ ì§ë ¬íë ì¡ì
ê²°ê³¼ê° ì ë¬ë©ëë¤. ì´ í¨ì를 미ë¤ì¨ì´ìì í¸ì¶íë©´ Astro ìì²´ì ì¡ì
ê²°ê³¼ ì²ë¦¬ê° ë¹íì±íë©ëë¤.
ì´ë HTML ìììì ì¡ì ì í¸ì¶íì¬ ì¸ì ìì 결과를 ì ì§íê³ ë¡ëí ë ì ì©í©ëë¤.
import { defineMiddleware } from 'astro:middleware';import { getActionContext } from 'astro:actions';export const onRequest = defineMiddleware(async (context, next) => { const { action, setActionResult, serializeActionResult } = getActionContext(context); if (action?.calledFrom === 'form') { const result = await action.handler(); // ... ì¡ì
ê²°ê³¼ ì²ë¦¬ setActionResult(action.name, serializeActionResult(result)); } return next();});serializeActionResult()
ì¹ì
ì 목: âserializeActionResult()âíì
: (res: SafeResult) => SerializedActionResult
ì§ìì±ì ìí´ ì¡ì
결과를 JSONì¼ë¡ ì§ë ¬íí©ëë¤. ì´ë Mapì´ë Dateì ê°ì JSONì´ ìë ë°í ê°ê³¼ ActionError ê°ì²´ë¥¼ ì¬ë°ë¥´ê² ì²ë¦¬í기 ìí´ íìí©ëë¤.
setActionResult()ì ì ë¬í ì¡ì
결과를 ì§ë ¬íí ë ì´ í¨ì를 í¸ì¶íì¸ì:
import { defineMiddleware } from 'astro:middleware';import { getActionContext } from 'astro:actions';
export const onRequest = defineMiddleware(async (context, next) => { const { action, setActionResult, serializeActionResult } = getActionContext(context); if (action) { const result = await action.handler(); setActionResult(action.name, serializeActionResult(result)); } // ...});deserializeActionResult()
ì¹ì
ì 목: âdeserializeActionResult()âíì
: (res: SerializedActionResult) => SafeResult
serializeActionResult()ì í¨ê³¼ë¥¼ ìì ìì¼ ì¡ì
결과를 ìë ìíë¡ ëë립ëë¤. ì´ë ì§ë ¬íë ì¡ì
ê²°ê³¼ìì dataì error ê°ì²´ì ì ê·¼í ë ì ì©í©ëë¤.
getActionPath()
ì¹ì
ì 목: âgetActionPath()âíì
: (action: ActionClient) => string
astro@5.1.0
ì¡ì
ì ë°ìì URL ê²½ë¡ë¥¼ ë°ííë ì í¸ë¦¬í°ì
ëë¤. ì´ë¥¼ íµí´ fetch() ìì
ì¼ë¡ ì¡ì
í¸ì¶ì ì§ì ì¤íí ì ììµëë¤. ëí, ì¡ì
ì í¸ì¶í ë ì¬ì©ì ì§ì í¤ëì ê°ì ì¸ë¶ ì 보를 ì ê³µí ì ììµëë¤. ê·¸ë° ë¤ì ì¡ì
ì ì§ì í¸ì¶í ê²ì²ë¼ íìì ë°ë¼ ì¬ì©ì ì§ì íìì ë°íë ë°ì´í°ë¥¼ ì²ë¦¬í ì ììµëë¤.
ë¤ì ìì ë Authorization í¤ëì keepalive ìµì
ì ì ë¬íë ì ìë like ì¡ì
ì í¸ì¶íë ë°©ë²ì ë³´ì¬ì¤ëë¤:
<script>import { actions, getActionPath } from 'astro:actions'
await fetch(getActionPath(actions.like), { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer YOUR_TOKEN' }, body: JSON.stringify({ id: 'YOUR_ID' }), keepalive: true})</script>ë¤ì ìì ë sendBeacon API를 ì¬ì©íì¬ ëì¼í like ì¡ì
ì í¸ì¶íë ë°©ë²ì ë³´ì¬ì¤ëë¤:
<script>import { actions, getActionPath } from 'astro:actions'
navigator.sendBeacon( getActionPath(actions.like), new Blob([JSON.stringify({ id: 'YOUR_ID' })], { type: 'application/json' }))</script>ACTION_QUERY_PARAMS
ì¹ì
ì 목: âACTION_QUERY_PARAMSâíì
: { actionName: string, actionPayload: string }
ìì ì¡ì ì ì¶ì ì²ë¦¬í ë Astro ë´ë¶ì ì¼ë¡ ì¬ì©íë 쿼리 매ê°ë³ì ì´ë¦ì í¬í¨íë ê°ì²´ì ëë¤.
ì¡ì ì ì¬ì©íì¬ ììì ì ì¶íë©´ ì¡ì í¸ì¶ì ì¶ì í기 ìí´ ë¤ìê³¼ ê°ì 쿼리 매ê°ë³ìê° URLì ì¶ê°ë©ëë¤.
actionName- í¸ì¶ëë ì¡ì ì ì´ë¦ì í¬í¨íë 쿼리 매ê°ë³ìì ëë¤.actionPayload- ì§ë ¬íë ìì ë°ì´í°ë¥¼ í¬í¨íë 쿼리 매ê°ë³ìì ëë¤.
ì´ ììë ìì ì ì¶ í URLì ì 리í´ì¼ í ë ì ì©í ì ììµëë¤. ì를 ë¤ì´, 리ëë ì ì¤ì ì¡ì ê´ë ¨ 쿼리 매ê°ë³ì를 ì ê±°íê³ ì¶ì ì ììµëë¤.
import type { APIRoute } from "astro";import { ACTION_QUERY_PARAMS } from "astro:actions";
export const GET: APIRoute = ({ redirect, request }) => { const link = new URL(request.url).searchParams; link.delete(ACTION_QUERY_PARAMS.actionName); link.delete(ACTION_QUERY_PARAMS.actionPayload);
return redirect(link.toString(), 303);};astro:actions íì
ì¹ì
ì 목: âastro:actions íì
âimport type { ActionAPIContext, ActionClient, ActionErrorCode, ActionInputSchema, ActionReturnType, SafeResult, } from 'astro:actions';ActionAPIContext
ì¹ì
ì 목: âActionAPIContextâAstro 컨í
ì¤í¸ ê°ì²´ì íì ì§í©ì
ëë¤. ë¤ì ìì±ì ì¬ì©í ì ììµëë¤: callAction, getActionResult, props, redirect.
ActionClient
ì¹ì
ì 목: âActionClientâíì :
-
(input?: any) => Promise<SafeResult> { queryString?: string; orThrow: (input?: any) => Promise<Awaited<TOutput>>; }
í´ë¼ì´ì¸í¸ìì í¸ì¶ëë ì¡ì
ì ëíë
ëë¤. ì
ë ¥ ë°ì´í°ë¥¼ ë°ì ì¡ì
ê²°ê³¼ ëë ì í¨ì± ê²ì¬ ì¤ë¥ê° í¬í¨ë SafeResult ê°ì²´ê° ë´ê¸´ Promise를 ë°ííë í¨ìë¡ ì¬ì©í ì ììµëë¤.
ë¤ìì ì¢ìì ì를 ì¦ê°ìí¤ë ¤ í ë ì¤í¨íë ê²½ì° if 문ì ì¬ì©íì¬ ì¤ë¥ ì²ë¦¬ë¥¼ ì ê³µíë ë°©ë²ì ë³´ì¬ì£¼ë ììì
ëë¤.
------
<!-- í
í릿 -->
<script>import { actions } from 'astro:actions';
const post = document.querySelector('article');const button = document.querySelector('button');button?.addEventListener('click', async () => { const { data: updatedLikes, error } = await actions.likePost({ postId: post?.id }); if (error) { /* ì¤ë¥ ì²ë¦¬ */ }})</script>ëë ê°ì²´ë¡ ì¬ì©í´ queryStringì ì ê·¼íê±°ë, ëì orThrow() ë©ìë를 í¸ì¶í ìë ììµëë¤.
ActionClient.queryString
ì¹ì
ì 목: âActionClient.queryStringâíì
: string
ìì ì¡ì URLì 구ì±íë ë° ì¬ì©í ì ìë ì¡ì ì 문ìì´ ííì ëë¤. ìì ì»´í¬ëí¸ê° ì¬ë¬ ê³³ìì ì¬ì©ëì§ë§ ì ì¶ ì ë¤ë¥¸ URLë¡ ë¦¬ëë ì í´ì¼ íë ê²½ì° ì ì©í ì ììµëë¤.
ë¤ìì queryStringì ì¬ì©íì¬ ì¬ì©ì ì ì propì íµí´ ìì action ìì±ì¼ë¡ ì ë¬í URLì 구ì±íë ììì
ëë¤.
---import { actions } from 'astro:actions';import FeedbackForm from "../components/FeedbackForm.astro";
const feedbackUrl = new URL('/feedback', Astro.url);feedbackUrl.search = actions.myAction.queryString;---<FeedbackForm sendTo={feedbackUrl.pathname} />ActionClient.orThrow()
ì¹ì
ì 목: âActionClient.orThrow()âíì
: (input?: any) => Promise<Awaited<TOutput>>
ì¤í¨ ì ì¤ë¥ë¥¼ ë°ííë ëì ì¤ë¥ë¥¼ ë°ììí¤ë ë©ìëì ëë¤. ì´ë ì¤ë¥ ì²ë¦¬ë¥¼ ì§ì íë ëì ìì¸ë¥¼ ì¬ì©íê³ ì í ë ì ì©í©ëë¤.
ë¤ìì ì¢ìì ì ì¦ê°ì ì¤í¨íì ë ì¤ë¥ ì²ë¦¬ë¥¼ ê±´ëë°ê¸° ìí´ orThrow()를 ì¬ì©íë ììì
ëë¤.
------
<!-- í
í릿 -->
<script>import { actions } from 'astro:actions';
const post = document.querySelector('article');const button = document.querySelector('button');button?.addEventListener('click', async () => { const updatedLikes = await actions.likePost.orThrow({ postId: post?.id });})</script>ActionErrorCode
ì¹ì
ì 목: âActionErrorCodeâíì
: string
IANAìì ì ìí íì¤ HTTP ìí ì½ëì ì ëì¸ íì
ì¼ë¡, ì¬ëì´ ì½ì ì ìë ë²ì ì ë문ì 문ìì´ì´ë©°, ì¸ëì¤ì½ì´ë¡ 구ë¶í©ëë¤. (ì: BAD_REQUEST ëë PAYLOAD_TOO_LARGE)
ActionInputSchema
ì¹ì
ì 목: âActionInputSchemaâíì
: ZodType
astro@5.16.0
Zod ì¤í¤ë§ë¥¼ 기ë°ì¼ë¡ ì¡ì
ì
ë ¥ì TypeScript íì
ì ì¶ë¡ íë ì í¸ë¦¬í° íì
ì
ëë¤. ì´ë ìì²´ íì
ì ììì ì¡ì
ì input ì í¨ì± ê²ì¬ê¸° íì
ì ê°ì²´ë¡ 참조í ë ì ì©í ì ììµëë¤.
input ì í¨ì± ê²ì¬ê¸°ê° ìëµëë©´ never를 ë°íí©ëë¤.
ë¤ìì ì´ë¦ì´ contactì¸ ì¡ì
ìì ActionInputSchema를 ì¬ì©íë ììì
ëë¤.
- ì¡ì ì ë ¥ì ëí Zod ì¤í¤ë§ íì ì ê²ìí©ëë¤.
- ì¡ì ì í¨ì± ê²ì¬ê¸°ì ìì ì ë ¥ íì ì ê²ìí©ëë¤.
---import { actions, type ActionInputSchema } from "astro:actions";import { z } from "astro/zod";
type ContactSchema = ActionInputSchema<typeof actions.contact>;type ContactInput = z.input<ContactSchema>;---ActionReturnType
ì¹ì
ì 목: âActionReturnTypeâíì
: Awaited<ReturnType<ActionHandler>>
ì¡ì
í¸ë¤ë¬ìì ì¶ë ¥ íì
ì ì¶ì¶íë ì í¸ë¦¬í° íì
ì
ëë¤. ì´ë Promise(í¸ë¤ë¬ê° ë¹ëê¸°ì¸ ê²½ì°)ì ReturnTypeì 모ë ì¸ëííì¬ ì¤ì ì¶ë ¥ íì
ì ì ê³µí©ëë¤. ëí ìì²´ íì
ì ììì ì¡ì
ì ì¶ë ¥ íì
ì 참조í´ì¼ íë ê²½ì°ì ì ì©í ì ììµëë¤.
ë¤ìì ActionReturnTypeì ì¬ì©íì¬ contactë¼ë ì¡ì
ì ìì ì¶ë ¥ íì
ì ê²ìíë ììì
ëë¤.
---import { actions, type ActionReturnType } from "astro:actions";
type ContactResult = ActionReturnType<typeof actions.contact>;---SafeResult
ì¹ì
ì 목: âSafeResultâíì
: { data: TOutput, error: undefined } | { data: undefined, error: ActionError }
ì¡ì í¸ì¶ 결과를 ëíë ëë¤.
- ì±ê³µ ì
dataìë ì¡ì ì ì¶ë ¥ì´ í¬í¨ëê³errorëundefinedì ëë¤. - ì¤í¨ ì
errorìë ì í¨ì± ê²ì¬ ì¤ë¥ ëë ë°íì ì¤ë¥ê° í¬í¨ëActionErrorê° í¬í¨ëê³dataëundefinedì ëë¤.