This commit is contained in:
Benjamin Toby
2025-08-13 11:16:28 +01:00
parent a1e56bb1b0
commit 700a704abd
24 changed files with 400 additions and 260 deletions
@@ -1,35 +1,15 @@
import fs from "fs";
import grabDirNames from "../../utils/backend/names/grab-dir-names";
import {
DSQL_DatabaseSchemaType,
DSQL_FieldSchemaType,
DSQL_TableSchemaType,
} from "../../types";
import { DSQL_DatabaseSchemaType, DSQL_TableSchemaType } from "../../types";
import _ from "lodash";
import EJSON from "../../utils/ejson";
import generateTypeDefinition from "./generate-type-definitions";
import { AppNames } from "../../dict/app-names";
import defaultFields from "../../data/defaultFields.json";
type Params = {
dbSchema?: DSQL_DatabaseSchemaType;
};
export default function dbSchemaToType(params?: Params): string[] | undefined {
let datasquirelSchema;
const { mainShemaJSONFilePath, defaultTableFieldsJSONFilePath } =
grabDirNames();
if (params?.dbSchema) {
datasquirelSchema = params.dbSchema;
} else {
const mainSchema = EJSON.parse(
fs.readFileSync(mainShemaJSONFilePath, "utf-8")
) as DSQL_DatabaseSchemaType[];
datasquirelSchema = mainSchema.find(
(sch) => sch.dbFullName == "datasquirel"
);
}
let datasquirelSchema = params?.dbSchema;
if (!datasquirelSchema) return;
@@ -37,10 +17,6 @@ export default function dbSchemaToType(params?: Params): string[] | undefined {
.map((tbl) => ` "${tbl.tableName}",`)
.join("\n")}\n] as const`;
const defaultFields = EJSON.parse(
fs.readFileSync(defaultTableFieldsJSONFilePath, "utf-8")
) as DSQL_FieldSchemaType[];
const dbTablesSchemas = datasquirelSchema.tables.map((tblSchm) => {
let newDefaultFields = _.cloneDeep(defaultFields);
return {