Home / File/ server.ts — astro Source File

server.ts — astro Source File

Architecture documentation for server.ts, a typescript file in the astro codebase. 12 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 12 imports 16 functions

Entity Profile

Dependency Diagram

graph LR
  12df90c3_b0fe_d858_b821_5011b6067fdb["server.ts"]
  be18ffb8_46cb_5266_8b78_659c01f80146["../core/base-pipeline.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> be18ffb8_46cb_5266_8b78_659c01f80146
  c396bb1c_7eee_221a_d665_5744d13dc23f["../core/build/util.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> c396bb1c_7eee_221a_d665_5744d13dc23f
  7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b
  8df634da_0f30_1e1f_1314_2439b0c9baab["../core/errors/errors-data.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> 8df634da_0f30_1e1f_1314_2439b0c9baab
  dd6187d6_53c4_ce90_a1d1_3a0b5e7e7d3f["../../core/errors/errors.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> dd6187d6_53c4_ce90_a1d1_3a0b5e7e7d3f
  7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> 7e4494c0_5563_4329_1bff_a84be66e1bc2
  baa53824_73a3_1e03_2043_4d0c058ecca5["../types/public/index.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> baa53824_73a3_1e03_2043_4d0c058ecca5
  9f5b84fa_f8a8_ed7f_2a86_7ecc740bf1d4["../actions/consts.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> 9f5b84fa_f8a8_ed7f_2a86_7ecc740bf1d4
  b0bf0fd2_1ce5_745d_58fc_02deee5192bf["../actions/runtime/client.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> b0bf0fd2_1ce5_745d_58fc_02deee5192bf
  a1711a94_f06c_214e_28b9_0d6031277c04["../../actions/runtime/types.js"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> a1711a94_f06c_214e_28b9_0d6031277c04
  ca52ff61_c81f_c2ca_81b6_5a678b65fd31["devalue"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> ca52ff61_c81f_c2ca_81b6_5a678b65fd31
  a2586aae_ce09_613d_4444_659268b61a89["core"]
  12df90c3_b0fe_d858_b821_5011b6067fdb --> a2586aae_ce09_613d_4444_659268b61a89
  style 12df90c3_b0fe_d858_b821_5011b6067fdb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { stringify as devalueStringify } from 'devalue';
import * as z from 'zod/v4/core';
import type { Pipeline } from '../../core/base-pipeline.js';
import { shouldAppendForwardSlash } from '../../core/build/util.js';
import { pipelineSymbol, REDIRECT_STATUS_CODES } from '../../core/constants.js';
import {
	ActionCalledFromServerError,
	ActionNotFoundError,
	ActionsReturnedInvalidDataError,
} from '../../core/errors/errors-data.js';
import { AstroError } from '../../core/errors/errors.js';
import { removeTrailingForwardSlash } from '../../core/path.js';
import type { APIContext } from '../../types/public/index.js';
import { ACTION_QUERY_PARAMS, ACTION_RPC_ROUTE_PATTERN } from '../consts.js';
import {
	ActionError,
	ActionInputError,
	actionResultErrorStack,
	deserializeActionResult,
} from './client.js';
import type {
	ActionAccept,
	ActionAPIContext,
	ActionClient,
	ActionHandler,
	ActionsLocals,
	MaybePromise,
	SafeResult,
	SerializedActionResult,
} from './types.js';

export function defineAction<
	TOutput,
	TAccept extends ActionAccept | undefined = undefined,
	TInputSchema extends z.$ZodType | undefined = TAccept extends 'form'
		? // If `input` is omitted, default to `FormData` for forms and `any` for JSON.
			z.$ZodType<FormData>
		: undefined,
>({
	accept,
	input: inputSchema,
	handler,
}: {
	input?: TInputSchema;
	accept?: TAccept;
	handler: ActionHandler<TInputSchema, TOutput>;
}): ActionClient<TOutput, TAccept, TInputSchema> & string {
	const serverHandler =
		accept === 'form'
			? getFormServerHandler(handler, inputSchema)
			: getJsonServerHandler(handler, inputSchema);

	async function safeServerHandler(this: ActionAPIContext, unparsedInput: unknown) {
		// The ActionAPIContext should always contain the `params` property
		if (typeof this === 'function' || !isActionAPIContext(this)) {
			throw new AstroError(ActionCalledFromServerError);
		}
		return callSafely(() => serverHandler(unparsedInput, this));
	}

// ... (387 more lines)

Domain

Subdomains

Dependencies

  • ../../actions/runtime/types.js
  • ../../core/errors/errors.js
  • ../actions/consts.js
  • ../actions/runtime/client.js
  • ../core/base-pipeline.js
  • ../core/build/util.js
  • ../core/constants.js
  • ../core/errors/errors-data.js
  • ../core/path.js
  • ../types/public/index.js
  • core
  • devalue

Frequently Asked Questions

What does server.ts do?
server.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 server.ts?
server.ts defines 16 function(s): Promise, callSafely, defineAction, formDataToObject, getActionContext, getCallerInfo, getFormServerHandler, getJsonServerHandler, handleFormDataGet, handleFormDataGetAll, and 6 more.
What does server.ts depend on?
server.ts imports 12 module(s): ../../actions/runtime/types.js, ../../core/errors/errors.js, ../actions/consts.js, ../actions/runtime/client.js, ../core/base-pipeline.js, ../core/build/util.js, ../core/constants.js, ../core/errors/errors-data.js, and 4 more.
Where is server.ts in the architecture?
server.ts is located at packages/astro/src/actions/runtime/server.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/actions/runtime).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free