Home / File/ index.ts — astro Source File

index.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 6 imports 12 functions

Entity Profile

Dependency Diagram

graph LR
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694["index.ts"]
  97fa73a6_cf67_73a5_b60d_d52bfb00c7d8["./core/types.js"]
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694 --> 97fa73a6_cf67_73a5_b60d_d52bfb00c7d8
  22a59779_880d_0799_08b9_126d5432bad6["./types.js"]
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694 --> 22a59779_880d_0799_08b9_126d5432bad6
  e4a7cb59_3c1e_4823_8146_150431eedb41["./utils.js"]
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694 --> e4a7cb59_3c1e_4823_8146_150431eedb41
  5e5ea2f4_4ff1_f558_0bea_0b3ded79b0ac["drizzle-orm"]
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694 --> 5e5ea2f4_4ff1_f558_0bea_0b3ded79b0ac
  512bd4d0_25e3_774d_1dff_0825d694fa9f["libsql"]
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694 --> 512bd4d0_25e3_774d_1dff_0825d694fa9f
  fb1af543_c710_bc94_95c6_6f94e01b66dd["sqlite-core"]
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694 --> fb1af543_c710_bc94_95c6_6f94e01b66dd
  style 80ef4dc8_c183_c77f_e09f_d40d9a6ca694 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { type ColumnBuilderBaseConfig, type ColumnDataType, sql } from 'drizzle-orm';
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
import {
	customType,
	type IndexBuilder,
	index,
	integer,
	type SQLiteColumnBuilderBase,
	sqliteTable,
	text,
} from 'drizzle-orm/sqlite-core';
import type { DBColumn, DBTable } from '../core/types.js';
import { isSerializedSQL, type SerializedSQL } from './types.js';
import { hasPrimaryKey, pathToFileURL } from './utils.js';
export type Database = LibSQLDatabase;
export type { Table } from './types.js';
export { hasPrimaryKey } from './utils.js';

// Taken from:
// https://stackoverflow.com/questions/52869695/check-if-a-date-string-is-in-iso-and-utc-format
const isISODateString = (str: string) => /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str);

const dateType = customType<{ data: Date; driverData: string }>({
	dataType() {
		return 'text';
	},
	toDriver(value) {
		return value.toISOString();
	},
	fromDriver(value) {
		if (!isISODateString(value)) {
			// values saved using CURRENT_TIMESTAMP are not valid ISO strings
			// but *are* in UTC, so append the UTC zone.
			value += 'Z';
		}
		return new Date(value);
	},
});

const jsonType = customType<{ data: unknown; driverData: string }>({
	dataType() {
		return 'text';
	},
	toDriver(value) {
		return JSON.stringify(value);
	},
	fromDriver(value) {
		return JSON.parse(value);
	},
});

type D1ColumnBuilder = SQLiteColumnBuilderBase<
	ColumnBuilderBaseConfig<ColumnDataType, string> & { data: unknown }
>;

export function asDrizzleTable(name: string, table: DBTable) {
	const columns: Record<string, D1ColumnBuilder> = {};
	if (!Object.entries(table.columns).some(([, column]) => hasPrimaryKey(column))) {
		columns['_id'] = integer('_id').primaryKey();
	}
// ... (94 more lines)

Domain

Subdomains

Dependencies

  • ./core/types.js
  • ./types.js
  • ./utils.js
  • drizzle-orm
  • libsql
  • sqlite-core

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, RoutingSystem subdomain.
What functions are defined in index.ts?
index.ts defines 12 function(s): asDrizzleTable, atLeastOne, columnMapper, dateType.dataType, dateType.fromDriver, dateType.toDriver, handleSerializedSQL, isISODateString, jsonType.dataType, jsonType.fromDriver, and 2 more.
What does index.ts depend on?
index.ts imports 6 module(s): ./core/types.js, ./types.js, ./utils.js, drizzle-orm, libsql, sqlite-core.
Where is index.ts in the architecture?
index.ts is located at packages/db/src/runtime/index.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