client.ts — astro Source File
Architecture documentation for client.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR de871608_3ba9_f938_cdef_8bded16fa30e["client.ts"] b0bf0fd2_1ce5_745d_58fc_02deee5192bf["../actions/runtime/client.js"] de871608_3ba9_f938_cdef_8bded16fa30e --> b0bf0fd2_1ce5_745d_58fc_02deee5192bf 2286831f_6846_d12f_ee48_bb914b8174cc["options"] de871608_3ba9_f938_cdef_8bded16fa30e --> 2286831f_6846_d12f_ee48_bb914b8174cc e71ad64b_c09a_453c_08ca_769c94c725b5["client"] de871608_3ba9_f938_cdef_8bded16fa30e --> e71ad64b_c09a_453c_08ca_769c94c725b5 style de871608_3ba9_f938_cdef_8bded16fa30e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { shouldAppendTrailingSlash } from 'virtual:astro:actions/options';
import { internalFetchHeaders } from 'virtual:astro:adapter-config/client';
import {
ActionError,
createActionsProxy,
createGetActionPath,
deserializeActionResult,
getActionPathFromString,
getActionQueryString,
} from '../client.js';
export { ACTION_QUERY_PARAMS } from '../../consts.js';
export {
ActionError,
isActionError,
isInputError,
} from '../client.js';
export type {
ActionAPIContext,
ActionClient,
ActionErrorCode,
ActionInputSchema,
ActionReturnType,
SafeResult,
} from '../types.js';
export function defineAction() {
throw new Error('[astro:actions] `defineAction()` unexpectedly used on the client.');
}
export function getActionContext() {
throw new Error('[astro:actions] `getActionContext()` unexpectedly used on the client.');
}
export const getActionPath = createGetActionPath({
baseUrl: import.meta.env.BASE_URL,
shouldAppendTrailingSlash,
});
export const actions = createActionsProxy({
handleAction: async (param, path) => {
const headers = new Headers();
headers.set('Accept', 'application/json');
// Apply adapter-specific headers for internal fetches
for (const [key, value] of Object.entries(internalFetchHeaders)) {
headers.set(key, value);
}
let body = param;
if (!(body instanceof FormData)) {
try {
body = JSON.stringify(param);
} catch (e) {
throw new ActionError({
code: 'BAD_REQUEST',
message: `Failed to serialize request body to JSON. Full error: ${(e as Error).message}`,
});
}
if (body) {
headers.set('Content-Type', 'application/json');
} else {
headers.set('Content-Length', '0');
}
}
const rawResult = await fetch(
getActionPathFromString({
baseUrl: import.meta.env.BASE_URL,
shouldAppendTrailingSlash,
path: getActionQueryString(path),
}),
{
method: 'POST',
body,
headers,
},
);
if (rawResult.status === 204) {
return deserializeActionResult({ type: 'empty', status: 204 });
}
const bodyText = await rawResult.text();
if (rawResult.ok) {
return deserializeActionResult({
type: 'data',
body: bodyText,
status: 200,
contentType: 'application/json+devalue',
});
}
return deserializeActionResult({
type: 'error',
body: bodyText,
status: rawResult.status,
contentType: 'application/json',
});
},
});
Domain
Subdomains
Dependencies
- ../actions/runtime/client.js
- client
- options
Source
Frequently Asked Questions
What does client.ts do?
client.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in client.ts?
client.ts defines 3 function(s): actions.handleAction, defineAction, getActionContext.
What does client.ts depend on?
client.ts imports 3 module(s): ../actions/runtime/client.js, client, options.
Where is client.ts in the architecture?
client.ts is located at packages/astro/src/actions/runtime/entrypoints/client.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/actions/runtime/entrypoints).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free