Roll Back compile version

This commit is contained in:
Benjamin Toby
2025-07-05 16:14:11 +01:00
parent 4f4eb44a98
commit 728183b827
251 changed files with 10169 additions and 7458 deletions
@@ -1,7 +1,43 @@
import dataTypeParser, { DataTypesWithNumbers } from "./data-type-parser";
export default function dataTypeConstructor(dataType, limit, decimal) {
let finalType = dataTypeParser(dataType).type;
if (!DataTypesWithNumbers.includes(finalType)) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = dataTypeConstructor;
const data_type_parser_1 = __importStar(require("./data-type-parser"));
function dataTypeConstructor(dataType, limit, decimal) {
let finalType = (0, data_type_parser_1.default)(dataType).type;
if (!data_type_parser_1.DataTypesWithNumbers.includes(finalType)) {
return finalType;
}
if (finalType == "VARCHAR") {
+15 -8
View File
@@ -1,16 +1,23 @@
import numberfy from "../../numberfy";
export const DataTypesWithNumbers = [
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataTypesWithTwoNumbers = exports.DataTypesWithNumbers = void 0;
exports.default = dataTypeParser;
const numberfy_1 = __importDefault(require("../../numberfy"));
exports.DataTypesWithNumbers = [
"DECIMAL",
"DOUBLE",
"FLOAT",
"VARCHAR",
];
export const DataTypesWithTwoNumbers = [
exports.DataTypesWithTwoNumbers = [
"DECIMAL",
"DOUBLE",
"FLOAT",
];
export default function dataTypeParser(dataType) {
function dataTypeParser(dataType) {
if (!dataType) {
return {
type: "VARCHAR",
@@ -20,7 +27,7 @@ export default function dataTypeParser(dataType) {
const dataTypeArray = dataType.split("(");
const type = dataTypeArray[0];
const number = dataTypeArray[1];
if (!DataTypesWithNumbers.includes(type)) {
if (!exports.DataTypesWithNumbers.includes(type)) {
return {
type,
};
@@ -29,12 +36,12 @@ export default function dataTypeParser(dataType) {
const numberArr = number.split(",");
return {
type,
limit: numberfy(numberArr[0]),
decimal: numberArr[1] ? numberfy(numberArr[1]) : undefined,
limit: (0, numberfy_1.default)(numberArr[0]),
decimal: numberArr[1] ? (0, numberfy_1.default)(numberArr[1]) : undefined,
};
}
return {
type,
limit: number ? numberfy(number) : undefined,
limit: number ? (0, numberfy_1.default)(number) : undefined,
};
}
@@ -1,4 +1,7 @@
export default function grabTargetDatabaseSchemaIndex({ dbs, dbFullName, dbSlug, dbSchema, childDbSchema, childTableSchema, }) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabTargetDatabaseSchemaIndex;
function grabTargetDatabaseSchemaIndex({ dbs, dbFullName, dbSlug, dbSchema, childDbSchema, childTableSchema, }) {
if (!dbs)
return undefined;
const targetDbIndex = dbs.findIndex((db) => (dbSlug && dbSlug == db.dbSlug) ||
@@ -1,4 +1,7 @@
export default function grabTargetTableSchemaIndex({ tables, tableName, tableSchema, childTableSchema, }) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabTargetTableSchemaIndex;
function grabTargetTableSchemaIndex({ tables, tableName, tableSchema, childTableSchema, }) {
if (!tables)
return undefined;
const targetTableIndex = tables.findIndex((tbl) => (tableName && tableName == tbl.tableName) ||
@@ -1,4 +1,7 @@
export default function grabTargetTableSchema({ tables, tableName, }) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabTargetTableSchema;
function grabTargetTableSchema({ tables, tableName, }) {
const targetTable = tables.find((tbl) => tableName && tableName == tbl.tableName);
return targetTable;
}
@@ -1,4 +1,7 @@
export default function grabTextFieldType(field, nullReturn) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabTextFieldType;
function grabTextFieldType(field, nullReturn) {
if (field.richText)
return "richText";
if (field.json)
@@ -1,9 +1,15 @@
import { grabPrimaryRequiredDbSchema, writeUpdatedDbSchema, } from "../../../shell/createDbFromSchema/grab-required-database-schemas";
import _ from "lodash";
import uniqueByKey from "../../unique-by-key";
export default function ({ currentDbSchema, userId }) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const grab_required_database_schemas_1 = require("../../../shell/createDbFromSchema/grab-required-database-schemas");
const lodash_1 = __importDefault(require("lodash"));
const unique_by_key_1 = __importDefault(require("../../unique-by-key"));
function default_1({ currentDbSchema, userId }) {
var _a, _b, _c;
const newCurrentDbSchema = _.cloneDeep(currentDbSchema);
const newCurrentDbSchema = lodash_1.default.cloneDeep(currentDbSchema);
if (newCurrentDbSchema.childrenDatabases) {
for (let ch = 0; ch < newCurrentDbSchema.childrenDatabases.length; ch++) {
const dbChildDb = newCurrentDbSchema.childrenDatabases[ch];
@@ -11,7 +17,7 @@ export default function ({ currentDbSchema, userId }) {
newCurrentDbSchema.childrenDatabases.splice(ch, 1, {});
continue;
}
const targetChildDatabase = grabPrimaryRequiredDbSchema({
const targetChildDatabase = (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({
dbId: dbChildDb.dbId,
userId,
});
@@ -21,7 +27,7 @@ export default function ({ currentDbSchema, userId }) {
*/
if ((targetChildDatabase === null || targetChildDatabase === void 0 ? void 0 : targetChildDatabase.id) && targetChildDatabase.childDatabase) {
targetChildDatabase.tables = [...newCurrentDbSchema.tables];
writeUpdatedDbSchema({
(0, grab_required_database_schemas_1.writeUpdatedDbSchema)({
dbSchema: targetChildDatabase,
userId,
});
@@ -31,13 +37,13 @@ export default function ({ currentDbSchema, userId }) {
}
}
newCurrentDbSchema.childrenDatabases =
uniqueByKey(newCurrentDbSchema.childrenDatabases.filter((db) => Boolean(db.dbId)), "dbId");
(0, unique_by_key_1.default)(newCurrentDbSchema.childrenDatabases.filter((db) => Boolean(db.dbId)), "dbId");
}
/**
* Handle scenario where this database is a child of another
*/
if (currentDbSchema.childDatabase && currentDbSchema.childDatabaseDbId) {
const targetParentDatabase = grabPrimaryRequiredDbSchema({
const targetParentDatabase = (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({
dbId: currentDbSchema.childDatabaseDbId,
userId,
});
@@ -74,14 +80,14 @@ export default function ({ currentDbSchema, userId }) {
if (!(existingChildDb === null || existingChildDb === void 0 ? void 0 : existingChildDb.dbId)) {
targetParentDatabase.childrenDatabases.push(newChildDatabaseObject);
}
targetParentDatabase.childrenDatabases = uniqueByKey(targetParentDatabase.childrenDatabases, "dbId");
targetParentDatabase.childrenDatabases = (0, unique_by_key_1.default)(targetParentDatabase.childrenDatabases, "dbId");
}
/**
* Update tables for child database, which is the current database
*/
if (targetParentDatabase === null || targetParentDatabase === void 0 ? void 0 : targetParentDatabase.id) {
newCurrentDbSchema.tables = targetParentDatabase.tables;
writeUpdatedDbSchema({ dbSchema: targetParentDatabase, userId });
(0, grab_required_database_schemas_1.writeUpdatedDbSchema)({ dbSchema: targetParentDatabase, userId });
}
}
return newCurrentDbSchema;
@@ -1,12 +1,18 @@
import { grabPrimaryRequiredDbSchema, writeUpdatedDbSchema, } from "../../../shell/createDbFromSchema/grab-required-database-schemas";
import _ from "lodash";
import uniqueByKey from "../../unique-by-key";
export default function ({ currentDbSchema, currentTableSchema, currentTableSchemaIndex, userId, }) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const grab_required_database_schemas_1 = require("../../../shell/createDbFromSchema/grab-required-database-schemas");
const lodash_1 = __importDefault(require("lodash"));
const unique_by_key_1 = __importDefault(require("../../unique-by-key"));
function default_1({ currentDbSchema, currentTableSchema, currentTableSchemaIndex, userId, }) {
var _a, _b, _c, _d, _e, _f, _g;
if (!currentDbSchema.dbFullName) {
throw new Error(`Resolve Children tables ERROR => currentDbSchema.dbFullName not found!`);
}
const newCurrentDbSchema = _.cloneDeep(currentDbSchema);
const newCurrentDbSchema = lodash_1.default.cloneDeep(currentDbSchema);
if (newCurrentDbSchema.tables[currentTableSchemaIndex].childrenTables) {
for (let ch = 0; ch <
newCurrentDbSchema.tables[currentTableSchemaIndex].childrenTables
@@ -17,7 +23,7 @@ export default function ({ currentDbSchema, currentTableSchema, currentTableSche
(_a = newCurrentDbSchema.tables[currentTableSchemaIndex].childrenTables) === null || _a === void 0 ? void 0 : _a.splice(ch, 1, {});
continue;
}
const targetChildTableParentDatabase = grabPrimaryRequiredDbSchema({
const targetChildTableParentDatabase = (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({
dbId: childTable.dbId,
userId,
});
@@ -39,7 +45,7 @@ export default function ({ currentDbSchema, currentTableSchema, currentTableSche
if (targetChildTableParentDatabaseTable === null || targetChildTableParentDatabaseTable === void 0 ? void 0 : targetChildTableParentDatabaseTable.childTable) {
targetChildTableParentDatabase.tables[targetChildTableParentDatabaseTableIndex].fields = [...currentTableSchema.fields];
targetChildTableParentDatabase.tables[targetChildTableParentDatabaseTableIndex].indexes = [...(currentTableSchema.indexes || [])];
writeUpdatedDbSchema({
(0, grab_required_database_schemas_1.writeUpdatedDbSchema)({
dbSchema: targetChildTableParentDatabase,
userId,
});
@@ -52,7 +58,7 @@ export default function ({ currentDbSchema, currentTableSchema, currentTableSche
if ((_d = newCurrentDbSchema.tables[currentTableSchemaIndex]
.childrenTables) === null || _d === void 0 ? void 0 : _d[0]) {
newCurrentDbSchema.tables[currentTableSchemaIndex].childrenTables =
uniqueByKey(newCurrentDbSchema.tables[currentTableSchemaIndex].childrenTables.filter((tbl) => Boolean(tbl.dbId) && Boolean(tbl.tableId)), "dbId");
(0, unique_by_key_1.default)(newCurrentDbSchema.tables[currentTableSchemaIndex].childrenTables.filter((tbl) => Boolean(tbl.dbId) && Boolean(tbl.tableId)), "dbId");
}
else {
delete newCurrentDbSchema.tables[currentTableSchemaIndex]
@@ -65,7 +71,7 @@ export default function ({ currentDbSchema, currentTableSchema, currentTableSche
if (currentTableSchema.childTable &&
currentTableSchema.childTableDbId &&
currentTableSchema.childTableDbId) {
const targetParentDatabase = grabPrimaryRequiredDbSchema({
const targetParentDatabase = (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({
dbId: currentTableSchema.childTableDbId,
userId,
});
@@ -114,7 +120,7 @@ export default function ({ currentDbSchema, currentTableSchema, currentTableSche
if (!(existingChildDbTable === null || existingChildDbTable === void 0 ? void 0 : existingChildDbTable.tableId)) {
(_g = targetParentDatabase.tables[targetParentDatabaseTableIndex].childrenTables) === null || _g === void 0 ? void 0 : _g.push(newChildDatabaseTableObject);
}
targetParentDatabase.tables[targetParentDatabaseTableIndex].childrenTables = uniqueByKey(targetParentDatabase.tables[targetParentDatabaseTableIndex]
targetParentDatabase.tables[targetParentDatabaseTableIndex].childrenTables = (0, unique_by_key_1.default)(targetParentDatabase.tables[targetParentDatabaseTableIndex]
.childrenTables || [], ["dbId", "tableId"]);
}
/**
@@ -126,7 +132,7 @@ export default function ({ currentDbSchema, currentTableSchema, currentTableSche
targetParentDatabaseTable.fields;
newCurrentDbSchema.tables[currentTableSchemaIndex].indexes =
targetParentDatabaseTable.indexes;
writeUpdatedDbSchema({ dbSchema: targetParentDatabase, userId });
(0, grab_required_database_schemas_1.writeUpdatedDbSchema)({ dbSchema: targetParentDatabase, userId });
}
}
return newCurrentDbSchema;
@@ -1,15 +1,21 @@
import _ from "lodash";
import resolveSchemaChildrenHandleChildrenDatabases from "./resolve-schema-children-handle-children-databases";
import resolveSchemaChildrenHandleChildrenTables from "./resolve-schema-children-handle-children-tables";
export default function resolveSchemaChildren({ dbSchema, userId }) {
let newDbSchema = _.cloneDeep(dbSchema);
newDbSchema = resolveSchemaChildrenHandleChildrenDatabases({
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = resolveSchemaChildren;
const lodash_1 = __importDefault(require("lodash"));
const resolve_schema_children_handle_children_databases_1 = __importDefault(require("./resolve-schema-children-handle-children-databases"));
const resolve_schema_children_handle_children_tables_1 = __importDefault(require("./resolve-schema-children-handle-children-tables"));
function resolveSchemaChildren({ dbSchema, userId }) {
let newDbSchema = lodash_1.default.cloneDeep(dbSchema);
newDbSchema = (0, resolve_schema_children_handle_children_databases_1.default)({
currentDbSchema: newDbSchema,
userId,
});
for (let t = 0; t < newDbSchema.tables.length; t++) {
const tableSchema = newDbSchema.tables[t];
newDbSchema = resolveSchemaChildrenHandleChildrenTables({
newDbSchema = (0, resolve_schema_children_handle_children_tables_1.default)({
currentDbSchema: newDbSchema,
currentTableSchema: tableSchema,
currentTableSchemaIndex: t,
@@ -1,7 +1,13 @@
import _ from "lodash";
export default function resolveSchemaForeignKeys({ dbSchema, userId }) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = resolveSchemaForeignKeys;
const lodash_1 = __importDefault(require("lodash"));
function resolveSchemaForeignKeys({ dbSchema, userId }) {
var _a;
let newDbSchema = _.cloneDeep(dbSchema);
let newDbSchema = lodash_1.default.cloneDeep(dbSchema);
for (let t = 0; t < newDbSchema.tables.length; t++) {
const tableSchema = newDbSchema.tables[t];
for (let f = 0; f < tableSchema.fields.length; f++) {
@@ -1,37 +1,44 @@
import fs from "fs";
import grabDirNames from "../../backend/names/grab-dir-names";
import _n from "../../numberfy";
import path from "path";
import _ from "lodash";
import EJSON from "../../ejson";
import { writeUpdatedDbSchema } from "../../../shell/createDbFromSchema/grab-required-database-schemas";
export default function resolveUsersSchemaIDs({ userId, dbId }) {
const { targetUserPrivateDir, tempDirName } = grabDirNames({ userId });
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = resolveUsersSchemaIDs;
exports.resolveUserDatabaseSchemaIDs = resolveUserDatabaseSchemaIDs;
const fs_1 = __importDefault(require("fs"));
const grab_dir_names_1 = __importDefault(require("../../backend/names/grab-dir-names"));
const numberfy_1 = __importDefault(require("../../numberfy"));
const path_1 = __importDefault(require("path"));
const lodash_1 = __importDefault(require("lodash"));
const ejson_1 = __importDefault(require("../../ejson"));
const grab_required_database_schemas_1 = require("../../../shell/createDbFromSchema/grab-required-database-schemas");
function resolveUsersSchemaIDs({ userId, dbId }) {
const { targetUserPrivateDir, tempDirName } = (0, grab_dir_names_1.default)({ userId });
if (!targetUserPrivateDir)
return false;
const schemaDirFilesFolders = fs.readdirSync(targetUserPrivateDir);
const schemaDirFilesFolders = fs_1.default.readdirSync(targetUserPrivateDir);
for (let i = 0; i < schemaDirFilesFolders.length; i++) {
const fileOrFolderName = schemaDirFilesFolders[i];
if (!fileOrFolderName.match(/^\d+.json/))
continue;
const fileDbId = _n(fileOrFolderName.split(".").shift());
const fileDbId = (0, numberfy_1.default)(fileOrFolderName.split(".").shift());
if (!fileDbId)
continue;
if (dbId && _n(dbId) !== fileDbId) {
if (dbId && (0, numberfy_1.default)(dbId) !== fileDbId) {
continue;
}
const schemaFullPath = path.join(targetUserPrivateDir, fileOrFolderName);
if (!fs.existsSync(schemaFullPath))
const schemaFullPath = path_1.default.join(targetUserPrivateDir, fileOrFolderName);
if (!fs_1.default.existsSync(schemaFullPath))
continue;
const dbSchema = EJSON.parse(fs.readFileSync(schemaFullPath, "utf-8"));
const dbSchema = ejson_1.default.parse(fs_1.default.readFileSync(schemaFullPath, "utf-8"));
if (!dbSchema)
continue;
let newDbSchema = resolveUserDatabaseSchemaIDs({ dbSchema });
writeUpdatedDbSchema({ dbSchema: newDbSchema, userId });
(0, grab_required_database_schemas_1.writeUpdatedDbSchema)({ dbSchema: newDbSchema, userId });
}
}
export function resolveUserDatabaseSchemaIDs({ dbSchema, }) {
let newDbSchema = _.cloneDeep(dbSchema);
function resolveUserDatabaseSchemaIDs({ dbSchema, }) {
let newDbSchema = lodash_1.default.cloneDeep(dbSchema);
if (!newDbSchema.id)
newDbSchema.id = dbSchema.id;
newDbSchema.tables.forEach((tbl, index) => {
+9 -3
View File
@@ -1,6 +1,12 @@
import _ from "lodash";
export default function setTextFieldType(field, type) {
const newField = _.cloneDeep(field);
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = setTextFieldType;
const lodash_1 = __importDefault(require("lodash"));
function setTextFieldType(field, type) {
const newField = lodash_1.default.cloneDeep(field);
delete newField.css;
delete newField.richText;
delete newField.json;