Roll Back compile version
This commit is contained in:
+85
-68
@@ -1,10 +1,25 @@
|
||||
import debugLog from "../logging/debug-log";
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = connDbHandler;
|
||||
const debug_log_1 = __importDefault(require("../logging/debug-log"));
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
* setup with `serverless-mysql` npm module
|
||||
*/
|
||||
export default async function connDbHandler(
|
||||
function connDbHandler(
|
||||
/**
|
||||
* ServerlessMySQL Connection Object
|
||||
*/
|
||||
@@ -17,83 +32,85 @@ query,
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values, debug) {
|
||||
var _a, _b;
|
||||
try {
|
||||
if (!conn)
|
||||
throw new Error("No Connection Found!");
|
||||
if (!query)
|
||||
throw new Error("Query String Required!");
|
||||
let queryErrorArray = [];
|
||||
if (typeof query == "string") {
|
||||
const res = await conn.query(trimQuery(query), values);
|
||||
if (debug) {
|
||||
debugLog({
|
||||
log: res,
|
||||
addTime: true,
|
||||
label: "res",
|
||||
});
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a, _b;
|
||||
try {
|
||||
if (!conn)
|
||||
throw new Error("No Connection Found!");
|
||||
if (!query)
|
||||
throw new Error("Query String Required!");
|
||||
let queryErrorArray = [];
|
||||
if (typeof query == "string") {
|
||||
const res = yield conn.query(trimQuery(query), values);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: res,
|
||||
addTime: true,
|
||||
label: "res",
|
||||
});
|
||||
}
|
||||
return JSON.parse(JSON.stringify(res));
|
||||
}
|
||||
return JSON.parse(JSON.stringify(res));
|
||||
}
|
||||
else if (typeof query == "object") {
|
||||
const resArray = [];
|
||||
for (let i = 0; i < query.length; i++) {
|
||||
let currentQueryError = {};
|
||||
try {
|
||||
const queryObj = query[i];
|
||||
currentQueryError.sql = queryObj.query;
|
||||
currentQueryError.sqlValues = queryObj.values;
|
||||
const queryObjRes = await conn.query(trimQuery(queryObj.query), queryObj.values);
|
||||
if (debug) {
|
||||
debugLog({
|
||||
log: queryObjRes,
|
||||
addTime: true,
|
||||
label: "queryObjRes",
|
||||
});
|
||||
else if (typeof query == "object") {
|
||||
const resArray = [];
|
||||
for (let i = 0; i < query.length; i++) {
|
||||
let currentQueryError = {};
|
||||
try {
|
||||
const queryObj = query[i];
|
||||
currentQueryError.sql = queryObj.query;
|
||||
currentQueryError.sqlValues = queryObj.values;
|
||||
const queryObjRes = yield conn.query(trimQuery(queryObj.query), queryObj.values);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: queryObjRes,
|
||||
addTime: true,
|
||||
label: "queryObjRes",
|
||||
});
|
||||
}
|
||||
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Connection DB Handler Query Error`, error);
|
||||
resArray.push(null);
|
||||
currentQueryError["error"] = error.message;
|
||||
queryErrorArray.push(currentQueryError);
|
||||
}
|
||||
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Connection DB Handler Query Error`, error);
|
||||
resArray.push(null);
|
||||
currentQueryError["error"] = error.message;
|
||||
queryErrorArray.push(currentQueryError);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: resArray,
|
||||
addTime: true,
|
||||
label: "resArray",
|
||||
});
|
||||
}
|
||||
if (queryErrorArray[0]) {
|
||||
return {
|
||||
errors: queryErrorArray,
|
||||
};
|
||||
}
|
||||
return resArray;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `Connection DB Handler Error`, error);
|
||||
if (debug) {
|
||||
debugLog({
|
||||
log: resArray,
|
||||
(0, debug_log_1.default)({
|
||||
log: `Connection DB Handler Error: ${error.message}`,
|
||||
addTime: true,
|
||||
label: "resArray",
|
||||
label: "Error",
|
||||
});
|
||||
}
|
||||
if (queryErrorArray[0]) {
|
||||
return {
|
||||
errors: queryErrorArray,
|
||||
};
|
||||
}
|
||||
return resArray;
|
||||
return {
|
||||
error: `Connection DB Handler Error: ${error.message}`,
|
||||
};
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
finally {
|
||||
conn === null || conn === void 0 ? void 0 : conn.end();
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `Connection DB Handler Error`, error);
|
||||
if (debug) {
|
||||
debugLog({
|
||||
log: `Connection DB Handler Error: ${error.message}`,
|
||||
addTime: true,
|
||||
label: "Error",
|
||||
});
|
||||
}
|
||||
return {
|
||||
error: `Connection DB Handler Error: ${error.message}`,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
conn === null || conn === void 0 ? void 0 : conn.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
function trimQuery(query) {
|
||||
return query.replace(/\n/gm, "").replace(/ {2,}/g, "").trim();
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
+17
-11
@@ -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;
|
||||
|
||||
+17
-11
@@ -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++) {
|
||||
|
||||
+25
-18
@@ -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) => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user