createActionsProxy() — astro Function Reference
Architecture documentation for the createActionsProxy() function in client.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD d64c600b_125e_5a3d_1d55_71e27608d4cb["createActionsProxy()"] eb04bc4a_f415_2ce3_c34b_e7ef77fb812f["client.ts"] d64c600b_125e_5a3d_1d55_71e27608d4cb -->|defined in| eb04bc4a_f415_2ce3_c34b_e7ef77fb812f 535e34a8_81a5_0c05_d63d_82b8a2e62de9["getActionQueryString()"] d64c600b_125e_5a3d_1d55_71e27608d4cb -->|calls| 535e34a8_81a5_0c05_d63d_82b8a2e62de9 style d64c600b_125e_5a3d_1d55_71e27608d4cb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/actions/runtime/client.ts lines 242–304
export function createActionsProxy({
actionCallback = {},
aggregatedPath = '',
handleAction,
}: {
actionCallback?: Record<string | symbol, any>;
aggregatedPath?: string;
handleAction: (
param: any,
path: string,
context: APIContext | undefined,
) => Promise<SafeResult<any, any>>;
}) {
return new Proxy(actionCallback, {
get(target, objKey) {
if (target.hasOwnProperty(objKey) || typeof objKey === 'symbol') {
return target[objKey];
}
// Add the key, encoding dots so they're not interpreted as nested properties.
const path =
aggregatedPath + encodeURIComponent(objKey.toString()).replaceAll('.', ENCODED_DOT);
function action(this: APIContext | undefined, param: any) {
return handleAction(param, path, this);
}
Object.assign(action, {
queryString: getActionQueryString(path),
toString: () => (action as any).queryString,
// redefine prototype methods as the object's own property, not the prototype's
bind: action.bind,
valueOf: () => action.valueOf,
// Progressive enhancement info for React.
$$FORM_ACTION: function () {
const searchParams = new URLSearchParams(action.toString());
return {
method: 'POST',
// `name` creates a hidden input.
// It's unused by Astro, but we can't turn this off.
// At least use a name that won't conflict with a user's formData.
name: '_astroAction',
action: '?' + searchParams.toString(),
};
},
// Note: `orThrow` does not have progressive enhancement info.
// If you want to throw exceptions,
// you must handle those exceptions with client JS.
async orThrow(this: APIContext | undefined, param: any) {
const { data, error } = await handleAction(param, path, this);
if (error) throw error;
return data;
},
});
// recurse to construct queries for nested object paths
// ex. actions.user.admins.auth()
return createActionsProxy({
actionCallback: action,
aggregatedPath: path + '.',
handleAction,
});
},
});
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does createActionsProxy() do?
createActionsProxy() is a function in the astro codebase, defined in packages/astro/src/actions/runtime/client.ts.
Where is createActionsProxy() defined?
createActionsProxy() is defined in packages/astro/src/actions/runtime/client.ts at line 242.
What does createActionsProxy() call?
createActionsProxy() calls 1 function(s): getActionQueryString.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free