import { Schema } from "./Schema"; import { SchemaDecl } from "./SchemaDecl"; import { Table } from "../table/Table"; import { compileSchema } from "./compileSchema"; type DeclOrFunc = SchemaDecl | (() => SchemaDecl) export class LazySchema { decl: DeclOrFunc private compiled: Schema> constructor(decl: DeclOrFunc) { this.decl = decl; } get() { if (!this.compiled) { const actualDecl = (typeof this.decl === 'function' ? this.decl() : this.decl); this.compiled = compileSchema(actualDecl) as Schema>; delete this.decl; } return this.compiled; } createTable() { return this.get().createTable(); } } export function lazySchema(decl: DeclOrFunc) { return new LazySchema(decl); }