import { alias, getTableConfig, integer, pgTable } from "drizzle-orm/pg-core"; import { describe, expect, it } from "vitest"; import { parseModuleSchemaDefinition } from "../src/modules/legacy-schema-definition.js"; describe("the legacy module schema definition", () => { it("normalizes and freezes a typed schema definition without freezing its tables", () => { const records = pgTable("example_records", { id: integer().primaryKey() }); const definition = parseModuleSchemaDefinition({ moduleId: "example", tables: { records }, }); expect(definition.tables.records).toBe(records); expect(getTableConfig(records).name).toBe("example_records"); expect(Object.isFrozen(definition)).toBe(true); expect(Object.isFrozen(definition.tables)).toBe(true); expect(Object.isFrozen(records)).toBe(false); }); it("rejects malformed, empty, unknown, and non-PostgreSQL table definitions", () => { const records = pgTable("example_records", { id: integer() }); const disguisedRecords = alias(records, "example_disguised_records"); expect(() => parseModuleSchemaDefinition({ moduleId: "example", tables: {} })).toThrow(); expect(() => parseModuleSchemaDefinition({ moduleId: "example", tables: { records: {} } }), ).toThrow(); expect(() => parseModuleSchemaDefinition({ moduleId: "example", tables: { records }, extra: true }), ).toThrow(); expect(() => parseModuleSchemaDefinition({ moduleId: "example", tables: { disguisedRecords } }), ).toThrow(); }); });