UNPKG

@lunora/cli

Version:

The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands

44 lines (41 loc) 1.11 kB
import { validatorKindToSqlType } from './diffSnapshots-BeDvvNiF.mjs'; const validatorToColumn = (validator) => { if (validator.kind === "optional" && validator.inner) { return { nullable: true, sqlType: validatorKindToSqlType(validator.inner.kind) }; } return { nullable: false, sqlType: validatorKindToSqlType(validator.kind) }; }; const isGlobal = (mode) => mode === "global"; const schemaIrToSnapshot = (ir) => { const tables = {}; for (const table of ir.tables) { if (!isGlobal(table.shardMode)) { continue; } const columns = {}; for (const [columnName, validator] of Object.entries(table.shape)) { columns[columnName] = validatorToColumn(validator); } const indexes = {}; for (const index of table.indexes) { indexes[index.name] = { fields: [...index.fields], name: index.name, unique: index.unique ?? false }; } tables[table.name] = { columns, indexes, name: table.name }; } return { tables, version: 1 }; }; export { schemaIrToSnapshot as default };