Home / File/ utils.ts — astro Source File

utils.ts — astro Source File

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

File typescript CoreAstro CoreMiddleware 4 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  95e69b07_9c8c_ee50_db4b_fc142c3918a7["utils.ts"]
  97fa73a6_cf67_73a5_b60d_d52bfb00c7d8["./core/types.js"]
  95e69b07_9c8c_ee50_db4b_fc142c3918a7 --> 97fa73a6_cf67_73a5_b60d_d52bfb00c7d8
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  95e69b07_9c8c_ee50_db4b_fc142c3918a7 --> f16d8c76_2866_6150_bd14_0347b59abfe9
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  95e69b07_9c8c_ee50_db4b_fc142c3918a7 --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  efd0f150_4239_ba62_fbb9_bcf24bd27236["yargs-parser"]
  95e69b07_9c8c_ee50_db4b_fc142c3918a7 --> efd0f150_4239_ba62_fbb9_bcf24bd27236
  style 95e69b07_9c8c_ee50_db4b_fc142c3918a7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { AstroConfig, AstroIntegration } from 'astro';
import { loadEnv } from 'vite';
import type { Arguments } from 'yargs-parser';
import './types.js';

export type VitePlugin = Required<AstroConfig['vite']>['plugins'][number];

export function getAstroEnv(envMode = ''): Record<`ASTRO_${string}`, string> {
	const env = loadEnv(envMode, process.cwd(), 'ASTRO_');
	return env;
}

export type RemoteDatabaseInfo = {
	url: string;
	token: string;
};

export function getRemoteDatabaseInfo(): RemoteDatabaseInfo {
	const astroEnv = getAstroEnv();

	return {
		url: astroEnv.ASTRO_DB_REMOTE_URL,
		token: astroEnv.ASTRO_DB_APP_TOKEN,
	};
}

export function resolveDbAppToken(flags: Arguments, envToken: string): string;
export function resolveDbAppToken(
	flags: Arguments,
	envToken: string | undefined,
): string | undefined;
export function resolveDbAppToken(
	flags: Arguments,
	envToken: string | undefined,
): string | undefined {
	const dbAppToken = (flags as Arguments & { dbAppToken?: unknown }).dbAppToken;
	if (typeof dbAppToken === 'string') return dbAppToken;

	return envToken;
}

export function getDbDirectoryUrl(root: URL | string) {
	return new URL('db/', root);
}

export function defineDbIntegration(integration: AstroIntegration): AstroIntegration {
	return integration;
}

/**
 * Map an object's values to a new set of values
 * while preserving types.
 */
export function mapObject<T, U = T>(
	item: Record<string, T>,
	callback: (key: string, value: T) => U,
): Record<string, U> {
	return Object.fromEntries(
		Object.entries(item).map(([key, value]) => [key, callback(key, value)]),
	);
}

Domain

Subdomains

Dependencies

  • ./core/types.js
  • astro
  • vite
  • yargs-parser

Frequently Asked Questions

What does utils.ts do?
utils.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in utils.ts?
utils.ts defines 6 function(s): defineDbIntegration, getAstroEnv, getDbDirectoryUrl, getRemoteDatabaseInfo, mapObject, resolveDbAppToken.
What does utils.ts depend on?
utils.ts imports 4 module(s): ./core/types.js, astro, vite, yargs-parser.
Where is utils.ts in the architecture?
utils.ts is located at packages/db/src/core/utils.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/db/src/core).

Analyze Your Own Codebase

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

Try Supermodel Free