import { EntitySchema, newColDefinition, newEntity, newOverloadEntity } from "../src/entity-schema"; export class DocumentEntitySchema implements EntitySchema { public column = { createdAt: { columnName: "created_at", columnType: "datetime", type: "string", }, id: { type: "number", }, name: { type: "string", }, key: { columnName: "key", columnType: "varchar", length: 255, type: "string", }, } as const; public tableName = "document_table" as const; } describe("Test entity schema", () => { test("test schema", async (done) => { const documentRepo = newColDefinition(new DocumentEntitySchema()); const documentEntity = newEntity(new DocumentEntitySchema()); expect(documentRepo).toEqual({ createdAt: { name: "created_at", type: "string", }, id: { name: "id", type: "number", }, name: { name: "name", type: "string", }, key: { name: "key", type: "string", }, }); expect(documentEntity).toEqual({ createdAt: undefined, id: undefined, name: undefined, key: undefined, }); // below will fail // documentEntity.name = 1; // documentEntity.id = "1"; // type possibleName = "card" | "poker"; // interface AnotherDocumentEntity { // readonly createdAt: string; // id: number; // name: possibleName; // key: string; // } // const anotherDocumentEntity = newOverloadEntity(new DocumentEntitySchema()); // // now both will complain // anotherDocumentEntity.name = "a"; // anotherDocumentEntity.createdAt = 1; done(); }); });