Home / File/ index.ts — astro Source File

index.ts — astro Source File

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

File typescript CoreAstro CoreMiddleware 4 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  2294057a_aeb5_9170_f933_78f104855727["index.ts"]
  49fbaf05_0dfa_cb97_d06e_040957f39092["../load-file.js"]
  2294057a_aeb5_9170_f933_78f104855727 --> 49fbaf05_0dfa_cb97_d06e_040957f39092
  ee0b547a_6190_adb1_b6f6_9c4e58e8b7e7["./print-help.js"]
  2294057a_aeb5_9170_f933_78f104855727 --> ee0b547a_6190_adb1_b6f6_9c4e58e8b7e7
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  2294057a_aeb5_9170_f933_78f104855727 --> f16d8c76_2866_6150_bd14_0347b59abfe9
  efd0f150_4239_ba62_fbb9_bcf24bd27236["yargs-parser"]
  2294057a_aeb5_9170_f933_78f104855727 --> efd0f150_4239_ba62_fbb9_bcf24bd27236
  style 2294057a_aeb5_9170_f933_78f104855727 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { AstroConfig } from 'astro';
import type { Arguments } from 'yargs-parser';
import { resolveDbConfig } from '../load-file.js';
import { printHelp } from './print-help.js';

export async function cli({
	flags,
	config: astroConfig,
}: {
	flags: Arguments;
	config: AstroConfig;
}) {
	const args = flags._ as string[];
	// Most commands are `astro db foo`, but for now login/logout
	// are also handled by this package, so first check if this is a db command.
	const command = args[2] === 'db' ? args[3] : args[2];
	validateDbAppTokenFlag(command, flags);
	const { dbConfig } = await resolveDbConfig(astroConfig);

	switch (command) {
		case 'shell': {
			const { cmd } = await import('./commands/shell/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		case 'gen': {
			console.log('"astro db gen" is no longer needed! Visit the docs for more information.');
			return;
		}
		case 'sync': {
			console.log('"astro db sync" is no longer needed! Visit the docs for more information.');
			return;
		}
		case 'push': {
			const { cmd } = await import('./commands/push/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		case 'verify': {
			const { cmd } = await import('./commands/verify/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		case 'execute': {
			const { cmd } = await import('./commands/execute/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		default: {
			if (command != null) {
				console.error(`Unknown command: ${command}`);
			}
			printHelp({
				commandName: 'astro db',
				usage: '[command] [...flags]',
				headline: ' ',
				tables: {
					Commands: [
						['push', 'Push table schema updates to libSQL.'],
						['verify', 'Test schema updates with libSQL (good for CI).'],
						[
							'astro db execute <file-path>',
							'Execute a ts/js file using astro:db. Use --remote to connect to libSQL.',
						],
						[
							'astro db shell --query <sql-string>',
							'Execute a SQL string. Use --remote to connect to libSQL.',
						],
					],
				},
			});
			return;
		}
	}
}

function validateDbAppTokenFlag(command: string | undefined, flags: Arguments) {
	if (command !== 'execute' && command !== 'push' && command !== 'verify' && command !== 'shell')
		return;

	const dbAppToken = (flags as Arguments & { dbAppToken?: unknown }).dbAppToken;
	if (dbAppToken == null) return;
	if (typeof dbAppToken !== 'string') {
		console.error(`Invalid value for --db-app-token; expected a string.`);
		process.exit(1);
	}
}

Domain

Subdomains

Dependencies

  • ../load-file.js
  • ./print-help.js
  • astro
  • yargs-parser

Frequently Asked Questions

What does index.ts do?
index.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 index.ts?
index.ts defines 2 function(s): cli, validateDbAppTokenFlag.
What does index.ts depend on?
index.ts imports 4 module(s): ../load-file.js, ./print-help.js, astro, yargs-parser.
Where is index.ts in the architecture?
index.ts is located at packages/db/src/core/cli/index.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/db/src/core/cli).

Analyze Your Own Codebase

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

Try Supermodel Free