validation.ts — astro Source File
Architecture documentation for validation.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 026c8980_c8fc_05c8_19cb_d7abee54a53f["validation.ts"] e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"] 026c8980_c8fc_05c8_19cb_d7abee54a53f --> e9b74c5a_8d34_34a7_e196_5e41b87214aa 135a8084_d596_67c2_9209_cca6693604e6["../types/public/common.js"] 026c8980_c8fc_05c8_19cb_d7abee54a53f --> 135a8084_d596_67c2_9209_cca6693604e6 10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"] 026c8980_c8fc_05c8_19cb_d7abee54a53f --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05 ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"] 026c8980_c8fc_05c8_19cb_d7abee54a53f --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9 style 026c8980_c8fc_05c8_19cb_d7abee54a53f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { ComponentInstance } from '../../types/astro.js';
import type { GetStaticPathsResult } from '../../types/public/common.js';
import type { RouteData } from '../../types/public/internal.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
const VALID_PARAM_TYPES = ['string', 'undefined'];
/** Throws error for invalid parameter in getStaticPaths() response */
export function validateGetStaticPathsParameter([key, value]: [string, any], route: string) {
if (!VALID_PARAM_TYPES.includes(typeof value)) {
throw new AstroError({
...AstroErrorData.GetStaticPathsInvalidRouteParam,
message: AstroErrorData.GetStaticPathsInvalidRouteParam.message(key, value, typeof value),
location: {
file: route,
},
});
}
}
/** Error for deprecated or malformed route components */
export function validateDynamicRouteModule(
mod: ComponentInstance,
{
ssr,
route,
}: {
ssr: boolean;
route: RouteData;
},
) {
if ((!ssr || route.prerender) && !mod.getStaticPaths) {
throw new AstroError({
...AstroErrorData.GetStaticPathsRequired,
location: { file: route.component },
});
}
}
/** Throw error and log warnings for malformed getStaticPaths() response */
export function validateGetStaticPathsResult(result: GetStaticPathsResult, route: RouteData) {
if (!Array.isArray(result)) {
throw new AstroError({
...AstroErrorData.InvalidGetStaticPathsReturn,
message: AstroErrorData.InvalidGetStaticPathsReturn.message(typeof result),
location: {
file: route.component,
},
});
}
result.forEach((pathObject) => {
if ((typeof pathObject === 'object' && Array.isArray(pathObject)) || pathObject === null) {
throw new AstroError({
...AstroErrorData.InvalidGetStaticPathsEntry,
message: AstroErrorData.InvalidGetStaticPathsEntry.message(
Array.isArray(pathObject) ? 'array' : typeof pathObject,
),
});
}
if (
pathObject.params === undefined ||
pathObject.params === null ||
(pathObject.params && Object.keys(pathObject.params).length === 0)
) {
throw new AstroError({
...AstroErrorData.GetStaticPathsExpectedParams,
location: {
file: route.component,
},
});
}
});
}
Domain
Subdomains
Functions
Dependencies
- ../core/errors/index.js
- ../types/astro.js
- ../types/public/common.js
- ../types/public/internal.js
Source
Frequently Asked Questions
What does validation.ts do?
validation.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 validation.ts?
validation.ts defines 3 function(s): validateDynamicRouteModule, validateGetStaticPathsParameter, validateGetStaticPathsResult.
What does validation.ts depend on?
validation.ts imports 4 module(s): ../core/errors/index.js, ../types/astro.js, ../types/public/common.js, ../types/public/internal.js.
Where is validation.ts in the architecture?
validation.ts is located at packages/astro/src/core/routing/validation.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/routing).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free