Home / File/ table.ts — astro Source File

table.ts — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  2861a46b_944c_2058_0b06_cd7f0c629f49["table.ts"]
  f41841f7_ae8b_eb32_b5dc_d3d2286b2189["../../dist/_internal/runtime/virtual.d.ts"]
  2861a46b_944c_2058_0b06_cd7f0c629f49 --> f41841f7_ae8b_eb32_b5dc_d3d2286b2189
  270980c1_198c_fa0d_1be9_7fa4ce6885d0["../../dist/runtime/virtual.js"]
  2861a46b_944c_2058_0b06_cd7f0c629f49 --> 270980c1_198c_fa0d_1be9_7fa4ce6885d0
  cae6f9d7_538c_49ee_f71b_ed87c8df6458["../../dist/utils.js"]
  2861a46b_944c_2058_0b06_cd7f0c629f49 --> cae6f9d7_538c_49ee_f71b_ed87c8df6458
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  2861a46b_944c_2058_0b06_cd7f0c629f49 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  687364c6_0b6b_44e7_012a_aa483da82c1b["expect-type"]
  2861a46b_944c_2058_0b06_cd7f0c629f49 --> 687364c6_0b6b_44e7_012a_aa483da82c1b
  style 2861a46b_944c_2058_0b06_cd7f0c629f49 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { describe, it } from 'node:test';
import { expectTypeOf } from 'expect-type';
import type {
	column as TColumn,
	defineTable as TDefineTable,
} from '../../dist/_internal/runtime/virtual.d.ts';
import { column as _column, defineTable as _defineTable } from '../../dist/runtime/virtual.js';
import { asDrizzleTable } from '../../dist/utils.js';

// Ensure the correct types are being used for tests...
// This is a workaround due to the types being exported under /_internal/ path
// and not under /runtime/ path.
const column: typeof TColumn = _column;
const defineTable: typeof TDefineTable = _defineTable;

describe('Table Type Tests', () => {
	it('basic table', async () => {
		const testTable = defineTable({
			columns: {
				id: column.number({ primaryKey: true }),
				name: column.text(),
				createdAt: column.date(),
			},
		});

		const tsTestTable = asDrizzleTable('testTable', testTable);

		expectTypeOf(tsTestTable.$inferInsert).toEqualTypeOf<{
			name: string;
			createdAt: Date;
			id?: number | undefined;
		}>();

		expectTypeOf(tsTestTable.$inferSelect).toEqualTypeOf<{
			id: number;
			name: string;
			createdAt: Date;
		}>();
	});

	it('table with optional column', async () => {
		const optionalTable = defineTable({
			columns: {
				id: column.number({ primaryKey: true }),
				name: column.text(),
				description: column.text({ optional: true }),
			},
		});

		const tsOptionalTable = asDrizzleTable('optionalTable', optionalTable);

		expectTypeOf(tsOptionalTable.$inferInsert).toEqualTypeOf<{
			name: string;
			id?: number | undefined;
			description?: string | null | undefined;
		}>();

		expectTypeOf(tsOptionalTable.$inferSelect).toEqualTypeOf<{
			id: number;
			name: string;
			description: string | null;
		}>();
	});

	it('table with enum column', async () => {
		const enumTable = defineTable({
			columns: {
				id: column.number({ primaryKey: true }),
				name: column.text(),
				status: column.text({ enum: ['active', 'inactive'] }),
			},
		});

		const tsEnumTable = asDrizzleTable('enumTable', enumTable);

		expectTypeOf(tsEnumTable.$inferInsert).toEqualTypeOf<{
			name: string;
			id?: number | undefined;
			status: 'active' | 'inactive';
		}>();

		expectTypeOf(tsEnumTable.$inferSelect).toEqualTypeOf<{
			id: number;
			name: string;
			status: 'active' | 'inactive';
		}>();
	});

	it('table with optional enum column', async () => {
		const enumTable = defineTable({
			columns: {
				id: column.number({ primaryKey: true }),
				name: column.text(),
				status: column.text({ enum: ['active', 'inactive'], optional: true }),
			},
		});

		const tsEnumTable = asDrizzleTable('enumTable', enumTable);

		expectTypeOf(tsEnumTable.$inferInsert).toEqualTypeOf<{
			name: string;
			id?: number | undefined;
			status?: 'active' | 'inactive' | null | undefined;
		}>();

		expectTypeOf(tsEnumTable.$inferSelect).toEqualTypeOf<{
			id: number;
			name: string;
			status: 'active' | 'inactive' | null;
		}>();
	});
});

Domain

Dependencies

  • ../../dist/_internal/runtime/virtual.d.ts
  • ../../dist/runtime/virtual.js
  • ../../dist/utils.js
  • expect-type
  • node:test

Frequently Asked Questions

What does table.ts do?
table.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain.
What does table.ts depend on?
table.ts imports 5 module(s): ../../dist/_internal/runtime/virtual.d.ts, ../../dist/runtime/virtual.js, ../../dist/utils.js, expect-type, node:test.
Where is table.ts in the architecture?
table.ts is located at packages/db/test/types/table.ts (domain: CoreAstro, directory: packages/db/test/types).

Analyze Your Own Codebase

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

Try Supermodel Free