Home / File/ utils.ts — astro Source File

utils.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 3 imports 4 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  99e40dcb_3c3c_9f4c_eb6e_551c6ac52da6["utils.ts"]
  97fa73a6_cf67_73a5_b60d_d52bfb00c7d8["./core/types.js"]
  99e40dcb_3c3c_9f4c_eb6e_551c6ac52da6 --> 97fa73a6_cf67_73a5_b60d_d52bfb00c7d8
  91decf0f_8a76_7391_4c56_d2f49dbb7487["client"]
  99e40dcb_3c3c_9f4c_eb6e_551c6ac52da6 --> 91decf0f_8a76_7391_4c56_d2f49dbb7487
  b77270e1_f0f2_7ea7_00a0_eedcb9ad6bdb["errors"]
  99e40dcb_3c3c_9f4c_eb6e_551c6ac52da6 --> b77270e1_f0f2_7ea7_00a0_eedcb9ad6bdb
  style 99e40dcb_3c3c_9f4c_eb6e_551c6ac52da6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { LibsqlError } from '@libsql/client';
import { AstroError } from 'astro/errors';
import type { DBColumn } from '../core/types.js';

export function hasPrimaryKey(column: DBColumn) {
	return 'primaryKey' in column.schema && !!column.schema.primaryKey;
}

const isWindows = process?.platform === 'win32';

export class AstroDbError extends AstroError {
	name = 'Astro DB Error';
}

export function isDbError(err: unknown): err is LibsqlError {
	return err instanceof LibsqlError || (err instanceof Error && (err as any).libsqlError === true);
}

function slash(path: string) {
	const isExtendedLengthPath = path.startsWith('\\\\?\\');

	if (isExtendedLengthPath) {
		return path;
	}

	return path.replace(/\\/g, '/');
}

export function pathToFileURL(path: string): URL {
	if (isWindows) {
		let slashed = slash(path);
		// Windows like C:/foo/bar
		if (!slashed.startsWith('/')) {
			slashed = '/' + slashed;
		}
		return new URL('file://' + slashed);
	}

	// Unix is easy
	return new URL('file://' + path);
}

Domain

Subdomains

Classes

Dependencies

  • ./core/types.js
  • client
  • errors

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, RoutingSystem subdomain.
What functions are defined in utils.ts?
utils.ts defines 4 function(s): hasPrimaryKey, isDbError, pathToFileURL, slash.
What does utils.ts depend on?
utils.ts imports 3 module(s): ./core/types.js, client, errors.
Where is utils.ts in the architecture?
utils.ts is located at packages/db/src/runtime/utils.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/db/src/runtime).

Analyze Your Own Codebase

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

Try Supermodel Free