Updates
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user