Home / File/ helpers.ts — astro Source File

helpers.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 4 imports 5 functions

Entity Profile

Dependency Diagram

graph LR
  e6d21753_0e5c_2eb6_07f1_f37ecca3fa77["helpers.ts"]
  10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"]
  e6d21753_0e5c_2eb6_07f1_f37ecca3fa77 --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05
  a4f2698c_5256_262a_ba7c_f72b51878d10["../core/app/types.js"]
  e6d21753_0e5c_2eb6_07f1_f37ecca3fa77 --> a4f2698c_5256_262a_ba7c_f72b51878d10
  e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"]
  e6d21753_0e5c_2eb6_07f1_f37ecca3fa77 --> e9b74c5a_8d34_34a7_e196_5e41b87214aa
  a3d56727_13c4_68fd_1bf6_c0b09d68466f["../core/routing/match.js"]
  e6d21753_0e5c_2eb6_07f1_f37ecca3fa77 --> a3d56727_13c4_68fd_1bf6_c0b09d68466f
  style e6d21753_0e5c_2eb6_07f1_f37ecca3fa77 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { RouteData } from '../../types/public/internal.js';
import type { RouteInfo } from '../app/types.js';
import type { RoutesList } from '../../types/astro.js';
import { isRoute404, isRoute500 } from './match.js';

type RedirectRouteData = RouteData & {
	redirect: string;
};

/**
 * Function guard that checks if a route is redirect. If so, `RouteData.redirectRoute` and
 * `RouteData.redirect` aren't `undefined` anymore
 * @param route
 */
export function routeIsRedirect(route: RouteData | undefined): route is RedirectRouteData {
	return route?.type === 'redirect';
}

export function routeIsFallback(route: RouteData | undefined): boolean {
	return route?.type === 'fallback';
}

/**
 * Give a route, it returns its fallback routes from a `list` of `RouteInfo[]`.
 *
 * It throws an error if no fallback routes were found. This means there's an error
 * when we construct the list of routes
 * @param route
 * @param routeList
 */
export function getFallbackRoute(route: RouteData, routeList: RouteInfo[]): RouteData {
	const fallbackRoute = routeList.find((r) => {
		// The index doesn't have a fallback route
		if (route.route === '/' && r.routeData.route === '/') {
			return true;
		}
		return r.routeData.fallbackRoutes.find((f) => {
			return f.route === route.route;
		});
	});

	if (!fallbackRoute) {
		throw new Error(`No fallback route found for route ${route.route}`);
	}

	return fallbackRoute.routeData;
}

export function getCustom404Route(manifestData: RoutesList): RouteData | undefined {
	return manifestData.routes.find((r) => isRoute404(r.route));
}

export function getCustom500Route(manifestData: RoutesList): RouteData | undefined {
	return manifestData.routes.find((r) => isRoute500(r.route));
}

Domain

Subdomains

Dependencies

  • ../core/app/types.js
  • ../core/routing/match.js
  • ../types/astro.js
  • ../types/public/internal.js

Frequently Asked Questions

What does helpers.ts do?
helpers.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in helpers.ts?
helpers.ts defines 5 function(s): getCustom404Route, getCustom500Route, getFallbackRoute, routeIsFallback, routeIsRedirect.
What does helpers.ts depend on?
helpers.ts imports 4 module(s): ../core/app/types.js, ../core/routing/match.js, ../types/astro.js, ../types/public/internal.js.
Where is helpers.ts in the architecture?
helpers.ts is located at packages/astro/src/core/routing/helpers.ts (domain: CoreAstro, subdomain: RoutingSystem, 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