mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix(actions): internal symbol check (#12424)
This commit is contained in:
parent
b745e382f1
commit
4364bff273
4 changed files with 13 additions and 3 deletions
5
.changeset/brown-bulldogs-share.md
Normal file
5
.changeset/brown-bulldogs-share.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes an issue where an incorrect usage of Astro actions was lost when porting the fix from v4 to v5
|
|
@ -4,11 +4,13 @@ import { AstroError } from '../../../core/errors/errors.js';
|
|||
import type { APIContext } from '../../../types/public/index.js';
|
||||
import { ACTION_RPC_ROUTE_PATTERN } from '../../consts.js';
|
||||
import {
|
||||
ACTION_API_CONTEXT_SYMBOL,
|
||||
type ActionAPIContext,
|
||||
type ErrorInferenceObject,
|
||||
type MaybePromise,
|
||||
formContentTypes,
|
||||
hasContentType,
|
||||
isActionAPIContext,
|
||||
} from '../utils.js';
|
||||
import type { Locals } from '../utils.js';
|
||||
import { getAction } from './get-action.js';
|
||||
|
@ -79,7 +81,8 @@ export function defineAction<
|
|||
: getJsonServerHandler(handler, inputSchema);
|
||||
|
||||
async function safeServerHandler(this: ActionAPIContext, unparsedInput: unknown) {
|
||||
if (typeof this === 'function') {
|
||||
// The ActionAPIContext should always contain the `params` property
|
||||
if (typeof this === 'function' || !isActionAPIContext(this)) {
|
||||
throw new AstroError(ActionCalledFromServerError);
|
||||
}
|
||||
return callSafely(() => serverHandler(unparsedInput, this));
|
||||
|
@ -293,6 +296,7 @@ export function getActionContext(context: APIContext): ActionMiddlewareContext {
|
|||
redirect: _redirect,
|
||||
...actionAPIContext
|
||||
} = context;
|
||||
Reflect.set(actionAPIContext, ACTION_API_CONTEXT_SYMBOL, true);
|
||||
const handler = baseAction.bind(actionAPIContext satisfies ActionAPIContext);
|
||||
return handler(input);
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type fsMod from 'node:fs';
|
||||
import * as eslexer from 'es-module-lexer';
|
||||
import type { APIContext } from '../types/public/context.js';
|
||||
import type { ActionAPIContext, Locals } from './runtime/utils.js';
|
||||
import { ACTION_API_CONTEXT_SYMBOL, type ActionAPIContext, type Locals } from './runtime/utils.js';
|
||||
import { deserializeActionResult, getActionQueryString } from './runtime/virtual/shared.js';
|
||||
|
||||
export function hasActionPayload(locals: APIContext['locals']): locals is Locals {
|
||||
|
@ -22,6 +22,7 @@ export function createGetActionResult(locals: APIContext['locals']): APIContext[
|
|||
|
||||
export function createCallAction(context: ActionAPIContext): APIContext['callAction'] {
|
||||
return (baseAction, input) => {
|
||||
Reflect.set(context, ACTION_API_CONTEXT_SYMBOL, true);
|
||||
const action = baseAction.bind(context);
|
||||
return action(input) as any;
|
||||
};
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
import { actions } from "astro:actions";
|
||||
|
||||
// this is invalid, it should fail
|
||||
const result = await actions.imageUploadInChunks();
|
||||
const result = await actions.subscribe({ channel: "hey" });
|
||||
---
|
||||
|
|
Loading…
Reference in a new issue