Roll Back compile version
This commit is contained in:
+18
-12
@@ -1,23 +1,29 @@
|
||||
import fs from "fs";
|
||||
import grabDirNames from "../names/grab-dir-names";
|
||||
import EJSON from "../../ejson";
|
||||
import envsub from "../../envsub";
|
||||
export default function grabConfig(params) {
|
||||
const { appConfigJSONFile, userConfigJSONFilePath } = grabDirNames({
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabConfig;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const grab_dir_names_1 = __importDefault(require("../names/grab-dir-names"));
|
||||
const ejson_1 = __importDefault(require("../../ejson"));
|
||||
const envsub_1 = __importDefault(require("../../envsub"));
|
||||
function grabConfig(params) {
|
||||
const { appConfigJSONFile, userConfigJSONFilePath } = (0, grab_dir_names_1.default)({
|
||||
userId: params === null || params === void 0 ? void 0 : params.userId,
|
||||
});
|
||||
const appConfigJSON = envsub(fs.readFileSync(appConfigJSONFile, "utf-8"));
|
||||
const appConfig = EJSON.parse(appConfigJSON);
|
||||
const appConfigJSON = (0, envsub_1.default)(fs_1.default.readFileSync(appConfigJSONFile, "utf-8"));
|
||||
const appConfig = ejson_1.default.parse(appConfigJSON);
|
||||
if (!userConfigJSONFilePath) {
|
||||
return { appConfig, userConfig: null };
|
||||
}
|
||||
if (!fs.existsSync(userConfigJSONFilePath)) {
|
||||
fs.writeFileSync(userConfigJSONFilePath, JSON.stringify({
|
||||
if (!fs_1.default.existsSync(userConfigJSONFilePath)) {
|
||||
fs_1.default.writeFileSync(userConfigJSONFilePath, JSON.stringify({
|
||||
main: {},
|
||||
}), "utf-8");
|
||||
}
|
||||
const userConfigJSON = envsub(fs.readFileSync(userConfigJSONFilePath, "utf-8"));
|
||||
const userConfig = (EJSON.parse(userConfigJSON) || {
|
||||
const userConfigJSON = (0, envsub_1.default)(fs_1.default.readFileSync(userConfigJSONFilePath, "utf-8"));
|
||||
const userConfig = (ejson_1.default.parse(userConfigJSON) || {
|
||||
main: {},
|
||||
});
|
||||
return { appConfig, userConfig };
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import grabConfig from "./grab-config";
|
||||
export default function grabMainConfig(params) {
|
||||
const { appConfig } = grabConfig();
|
||||
const { userConfig } = grabConfig({ userId: params === null || params === void 0 ? void 0 : params.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 = grabMainConfig;
|
||||
const grab_config_1 = __importDefault(require("./grab-config"));
|
||||
function grabMainConfig(params) {
|
||||
const { appConfig } = (0, grab_config_1.default)();
|
||||
const { userConfig } = (0, grab_config_1.default)({ userId: params === null || params === void 0 ? void 0 : params.userId });
|
||||
return { appMainConfig: appConfig.main, userMainConfig: userConfig === null || userConfig === void 0 ? void 0 : userConfig.main };
|
||||
}
|
||||
|
||||
+16
-10
@@ -1,25 +1,31 @@
|
||||
import fs from "fs";
|
||||
import grabDirNames from "../names/grab-dir-names";
|
||||
import grabConfig from "./grab-config";
|
||||
import _ from "lodash";
|
||||
export default function updateUserConfig({ newConfig, 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 = updateUserConfig;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const grab_dir_names_1 = __importDefault(require("../names/grab-dir-names"));
|
||||
const grab_config_1 = __importDefault(require("./grab-config"));
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
function updateUserConfig({ newConfig, userId, }) {
|
||||
if (!userId || !newConfig) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `UserID or newConfig not provided`,
|
||||
};
|
||||
}
|
||||
const { userConfigJSONFilePath } = grabDirNames({
|
||||
const { userConfigJSONFilePath } = (0, grab_dir_names_1.default)({
|
||||
userId,
|
||||
});
|
||||
if (!userConfigJSONFilePath || !fs.existsSync(userConfigJSONFilePath)) {
|
||||
if (!userConfigJSONFilePath || !fs_1.default.existsSync(userConfigJSONFilePath)) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `userConfigJSONFilePath not found!`,
|
||||
};
|
||||
}
|
||||
const { userConfig: existingUserConfig } = grabConfig({ userId });
|
||||
const updateConfig = _.merge(existingUserConfig, newConfig);
|
||||
fs.writeFileSync(userConfigJSONFilePath, JSON.stringify(updateConfig), "utf-8");
|
||||
const { userConfig: existingUserConfig } = (0, grab_config_1.default)({ userId });
|
||||
const updateConfig = lodash_1.default.merge(existingUserConfig, newConfig);
|
||||
fs_1.default.writeFileSync(userConfigJSONFilePath, JSON.stringify(updateConfig), "utf-8");
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { execSync } from "child_process";
|
||||
import os from "os";
|
||||
export default function exportMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }) {
|
||||
const mysqlDumpPath = os.platform().match(/win/i)
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = exportMariadbDatabase;
|
||||
const child_process_1 = require("child_process");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
function exportMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }) {
|
||||
const mysqlDumpPath = os_1.default.platform().match(/win/i)
|
||||
? "'" +
|
||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
||||
"'"
|
||||
@@ -13,6 +19,6 @@ export default function exportMariadbDatabase({ dbFullName, targetFilePath, mari
|
||||
let execSyncOptions = {
|
||||
encoding: "utf-8",
|
||||
};
|
||||
const dumpDb = execSync(cmd, execSyncOptions);
|
||||
const dumpDb = (0, child_process_1.execSync)(cmd, execSyncOptions);
|
||||
return dumpDb;
|
||||
}
|
||||
|
||||
+37
-20
@@ -1,25 +1,42 @@
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
"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 = DB_HANDLER;
|
||||
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||
*/
|
||||
export default async function DB_HANDLER(...args) {
|
||||
var _a;
|
||||
const CONNECTION = grabDSQLConnection();
|
||||
try {
|
||||
if (!CONNECTION)
|
||||
throw new Error("No Connection provided to DB_HANDLER function!");
|
||||
const results = await CONNECTION.query(...args);
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `DB_HANDLER Error`, error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
await (CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end());
|
||||
}
|
||||
function DB_HANDLER(...args) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
const CONNECTION = (0, grab_dsql_connection_1.default)();
|
||||
try {
|
||||
if (!CONNECTION)
|
||||
throw new Error("No Connection provided to DB_HANDLER function!");
|
||||
const results = yield CONNECTION.query(...args);
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `DB_HANDLER Error`, error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
yield (CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,21 +1,38 @@
|
||||
import connDbHandler from "../../db/conn-db-handler";
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
"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 = DSQL_USER_DB_HANDLER;
|
||||
const conn_db_handler_1 = __importDefault(require("../../db/conn-db-handler"));
|
||||
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default async function DSQL_USER_DB_HANDLER({ paradigm, queryString, queryValues, }) {
|
||||
var _a;
|
||||
const CONNECTION = paradigm == "Read Only"
|
||||
? grabDSQLConnection({ ro: true })
|
||||
: grabDSQLConnection({ fa: true });
|
||||
try {
|
||||
return await connDbHandler(CONNECTION, queryString, queryValues);
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `DSQL_USER_DB_HANDLER Error`, error);
|
||||
return null;
|
||||
}
|
||||
finally {
|
||||
CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end();
|
||||
}
|
||||
function DSQL_USER_DB_HANDLER(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ paradigm, queryString, queryValues, }) {
|
||||
var _b;
|
||||
const CONNECTION = paradigm == "Read Only"
|
||||
? (0, grab_dsql_connection_1.default)({ ro: true })
|
||||
: (0, grab_dsql_connection_1.default)({ fa: true });
|
||||
try {
|
||||
return yield (0, conn_db_handler_1.default)(CONNECTION, queryString, queryValues);
|
||||
}
|
||||
catch (error) {
|
||||
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `DSQL_USER_DB_HANDLER Error`, error);
|
||||
return null;
|
||||
}
|
||||
finally {
|
||||
CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+35
-18
@@ -1,22 +1,39 @@
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
"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 = LOCAL_DB_HANDLER;
|
||||
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default async function LOCAL_DB_HANDLER(...args) {
|
||||
var _a;
|
||||
const MASTER = grabDSQLConnection();
|
||||
try {
|
||||
const results = await MASTER.query(...args);
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `LOCAL_DB_HANDLER Error`, error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
await (MASTER === null || MASTER === void 0 ? void 0 : MASTER.end());
|
||||
}
|
||||
function LOCAL_DB_HANDLER(...args) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
const MASTER = (0, grab_dsql_connection_1.default)();
|
||||
try {
|
||||
const results = yield MASTER.query(...args);
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `LOCAL_DB_HANDLER Error`, error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
yield (MASTER === null || MASTER === void 0 ? void 0 : MASTER.end());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = NO_DB_HANDLER;
|
||||
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default function NO_DB_HANDLER(...args) {
|
||||
function NO_DB_HANDLER(...args) {
|
||||
var _a;
|
||||
const CONNECTION = grabDSQLConnection();
|
||||
const CONNECTION = (0, grab_dsql_connection_1.default)();
|
||||
try {
|
||||
return new Promise((resolve, reject) => {
|
||||
CONNECTION.query(...args)
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = ROOT_DB_HANDLER;
|
||||
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
|
||||
/**
|
||||
* # Root DB handler
|
||||
*/
|
||||
export default function ROOT_DB_HANDLER(...args) {
|
||||
function ROOT_DB_HANDLER(...args) {
|
||||
var _a;
|
||||
const CONNECTION = grabDSQLConnection();
|
||||
const CONNECTION = (0, grab_dsql_connection_1.default)();
|
||||
try {
|
||||
return new Promise((resolve, reject) => {
|
||||
CONNECTION.query(...args)
|
||||
|
||||
+10
-4
@@ -1,19 +1,25 @@
|
||||
import fs from "fs";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDbSSL;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
/**
|
||||
* # Grall SSL
|
||||
*/
|
||||
export default function grabDbSSL() {
|
||||
function grabDbSSL() {
|
||||
const SSL_DIR = process.env.DSQL_SSL_DIR;
|
||||
if (!(SSL_DIR === null || SSL_DIR === void 0 ? void 0 : SSL_DIR.match(/./))) {
|
||||
return undefined;
|
||||
}
|
||||
const caFilePath = `${SSL_DIR}/ca-cert.pem`;
|
||||
if (!fs.existsSync(caFilePath)) {
|
||||
if (!fs_1.default.existsSync(caFilePath)) {
|
||||
console.log(`${caFilePath} does not exist`);
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
|
||||
ca: fs_1.default.readFileSync(`${SSL_DIR}/ca-cert.pem`),
|
||||
// key: fs.readFileSync(`${SSL_DIR}/client-key.pem`),
|
||||
// cert: fs.readFileSync(`${SSL_DIR}/client-cert.pem`),
|
||||
rejectUnauthorized: false,
|
||||
|
||||
+36
-19
@@ -1,20 +1,37 @@
|
||||
import { execSync } from "child_process";
|
||||
import os from "os";
|
||||
import connDbHandler from "../db/conn-db-handler";
|
||||
export default async function importMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }) {
|
||||
const mysqlPath = os.platform().match(/win/i)
|
||||
? "'" +
|
||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe" +
|
||||
"'"
|
||||
: "mysql";
|
||||
const finalMariadbUser = mariadbUser || process.env.DSQL_DB_USERNAME;
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
await connDbHandler(global.DSQL_DB_CONN, `CREATE DATABASE IF NOT EXISTS ${dbFullName}`);
|
||||
const cmd = `${mysqlPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p"${finalMariadbPass}" ${dbFullName} < ${targetFilePath}`;
|
||||
let execSyncOptions = {
|
||||
encoding: "utf-8",
|
||||
};
|
||||
const importDb = execSync(cmd, execSyncOptions);
|
||||
return importDb;
|
||||
"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 = importMariadbDatabase;
|
||||
const child_process_1 = require("child_process");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||
function importMariadbDatabase(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }) {
|
||||
const mysqlPath = os_1.default.platform().match(/win/i)
|
||||
? "'" +
|
||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe" +
|
||||
"'"
|
||||
: "mysql";
|
||||
const finalMariadbUser = mariadbUser || process.env.DSQL_DB_USERNAME;
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
yield (0, conn_db_handler_1.default)(global.DSQL_DB_CONN, `CREATE DATABASE IF NOT EXISTS ${dbFullName}`);
|
||||
const cmd = `${mysqlPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p"${finalMariadbPass}" ${dbFullName} < ${targetFilePath}`;
|
||||
let execSyncOptions = {
|
||||
encoding: "utf-8",
|
||||
};
|
||||
const importDb = (0, child_process_1.execSync)(cmd, execSyncOptions);
|
||||
return importDb;
|
||||
});
|
||||
}
|
||||
|
||||
+62
-56
@@ -1,5 +1,11 @@
|
||||
import path from "path";
|
||||
export default function grabDirNames(param) {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDirNames;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
function grabDirNames(param) {
|
||||
var _a;
|
||||
const appDir = (param === null || param === void 0 ? void 0 : param.appDir) || process.env.DSQL_APP_DIR;
|
||||
const DATA_DIR = (param === null || param === void 0 ? void 0 : param.dataDir) || process.env.DSQL_DATA_DIR || "/data";
|
||||
@@ -8,104 +14,104 @@ export default function grabDirNames(param) {
|
||||
throw new Error("Please provide the `DSQL_APP_DIR` env variable.");
|
||||
if (!DATA_DIR)
|
||||
throw new Error("Please provide the `DATA_DIR` env variable.");
|
||||
const STATIC_ROOT = path.join(DATA_DIR, "static");
|
||||
const publicImagesDir = path.join(STATIC_ROOT, `images`);
|
||||
const publicDir = path.join(appDir, "public");
|
||||
const publicSSLDir = path.join(publicDir, "documents", "ssl");
|
||||
const appSSLDir = path.join(appDir, "ssl");
|
||||
const mainSSLDir = path.join(DATA_DIR, "ssl");
|
||||
const privateDataDir = path.join(DATA_DIR, "private");
|
||||
const STATIC_ROOT = path_1.default.join(DATA_DIR, "static");
|
||||
const publicImagesDir = path_1.default.join(STATIC_ROOT, `images`);
|
||||
const publicDir = path_1.default.join(appDir, "public");
|
||||
const publicSSLDir = path_1.default.join(publicDir, "documents", "ssl");
|
||||
const appSSLDir = path_1.default.join(appDir, "ssl");
|
||||
const mainSSLDir = path_1.default.join(DATA_DIR, "ssl");
|
||||
const privateDataDir = path_1.default.join(DATA_DIR, "private");
|
||||
/**
|
||||
* # DB Dir names
|
||||
* @description Database related Directories
|
||||
*/
|
||||
const mainDbDataDir = path.join(DATA_DIR, "db");
|
||||
const mainDbGrastateDatFile = path.join(mainDbDataDir, "grastate.dat");
|
||||
const replica1DbDataDir = path.join(DATA_DIR, "replica-1");
|
||||
const mariadbMainConfigDir = path.join(DATA_DIR, "db-config", "main");
|
||||
const mariadbReplicaConfigDir = path.join(DATA_DIR, "db-config", "replica");
|
||||
const maxscaleConfigDir = path.join(DATA_DIR, "db-config", "maxscale");
|
||||
const mariadbMainConfigFile = path.join(mariadbMainConfigDir, "default.cnf");
|
||||
const mariadbReplicaConfigFile = path.join(mariadbReplicaConfigDir, "default.cnf");
|
||||
const galeraConfigFile = path.join(mariadbMainConfigDir, "galera.cnf");
|
||||
const galeraReplicaConfigFile = path.join(mariadbReplicaConfigDir, "galera.cnf");
|
||||
const maxscaleConfigFile = path.join(maxscaleConfigDir, "maxscale.cnf");
|
||||
const mainDbDataDir = path_1.default.join(DATA_DIR, "db");
|
||||
const mainDbGrastateDatFile = path_1.default.join(mainDbDataDir, "grastate.dat");
|
||||
const replica1DbDataDir = path_1.default.join(DATA_DIR, "replica-1");
|
||||
const mariadbMainConfigDir = path_1.default.join(DATA_DIR, "db-config", "main");
|
||||
const mariadbReplicaConfigDir = path_1.default.join(DATA_DIR, "db-config", "replica");
|
||||
const maxscaleConfigDir = path_1.default.join(DATA_DIR, "db-config", "maxscale");
|
||||
const mariadbMainConfigFile = path_1.default.join(mariadbMainConfigDir, "default.cnf");
|
||||
const mariadbReplicaConfigFile = path_1.default.join(mariadbReplicaConfigDir, "default.cnf");
|
||||
const galeraConfigFile = path_1.default.join(mariadbMainConfigDir, "galera.cnf");
|
||||
const galeraReplicaConfigFile = path_1.default.join(mariadbReplicaConfigDir, "galera.cnf");
|
||||
const maxscaleConfigFile = path_1.default.join(maxscaleConfigDir, "maxscale.cnf");
|
||||
/**
|
||||
* # Schema Dir names
|
||||
* @description
|
||||
*/
|
||||
const oldSchemasDir = path.join(appDir, "jsonData", "dbSchemas");
|
||||
const appSchemaJSONFile = path.join(oldSchemasDir, "1.json");
|
||||
const oldSchemasDir = path_1.default.join(appDir, "jsonData", "dbSchemas");
|
||||
const appSchemaJSONFile = path_1.default.join(oldSchemasDir, "1.json");
|
||||
const tempDirName = ".tmp";
|
||||
const appConfigDir = path.join(appDir, "jsonData", "config");
|
||||
const appConfigJSONFile = path.join(appConfigDir, "app-config.json");
|
||||
const appConfigDir = path_1.default.join(appDir, "jsonData", "config");
|
||||
const appConfigJSONFile = path_1.default.join(appConfigDir, "app-config.json");
|
||||
if (!privateDataDir)
|
||||
throw new Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");
|
||||
const pakageSharedDir = path.join(appDir, `package-shared`);
|
||||
const mainDbTypeDefFile = path.join(pakageSharedDir, `types/dsql.ts`);
|
||||
const mainShemaJSONFilePath = path.join(oldSchemasDir, `main.json`);
|
||||
const defaultTableFieldsJSONFilePath = path.join(pakageSharedDir, `data/defaultFields.json`);
|
||||
const usersSchemaDir = path.join(privateDataDir, `users`);
|
||||
const pakageSharedDir = path_1.default.join(appDir, `package-shared`);
|
||||
const mainDbTypeDefFile = path_1.default.join(pakageSharedDir, `types/dsql.ts`);
|
||||
const mainShemaJSONFilePath = path_1.default.join(oldSchemasDir, `main.json`);
|
||||
const defaultTableFieldsJSONFilePath = path_1.default.join(pakageSharedDir, `data/defaultFields.json`);
|
||||
const usersSchemaDir = path_1.default.join(privateDataDir, `users`);
|
||||
const targetUserPrivateDir = finalUserId
|
||||
? path.join(usersSchemaDir, `user-${finalUserId}`)
|
||||
? path_1.default.join(usersSchemaDir, `user-${finalUserId}`)
|
||||
: undefined;
|
||||
const userTempSQLFilePath = targetUserPrivateDir
|
||||
? path.join(targetUserPrivateDir, `tmp.sql`)
|
||||
? path_1.default.join(targetUserPrivateDir, `tmp.sql`)
|
||||
: undefined;
|
||||
const userMainShemaJSONFilePath = targetUserPrivateDir
|
||||
? path.join(targetUserPrivateDir, `main.json`)
|
||||
? path_1.default.join(targetUserPrivateDir, `main.json`)
|
||||
: undefined;
|
||||
const userConfigJSONFilePath = targetUserPrivateDir
|
||||
? path.join(targetUserPrivateDir, `config.json`)
|
||||
? path_1.default.join(targetUserPrivateDir, `config.json`)
|
||||
: undefined;
|
||||
const userSchemaMainJSONFilePath = targetUserPrivateDir
|
||||
? path.join(targetUserPrivateDir, `main.json`)
|
||||
? path_1.default.join(targetUserPrivateDir, `main.json`)
|
||||
: undefined;
|
||||
const userPrivateMediaDir = targetUserPrivateDir
|
||||
? path.join(targetUserPrivateDir, `media`)
|
||||
? path_1.default.join(targetUserPrivateDir, `media`)
|
||||
: undefined;
|
||||
const userPrivateExportsDir = targetUserPrivateDir
|
||||
? path.join(targetUserPrivateDir, `export`)
|
||||
? path_1.default.join(targetUserPrivateDir, `export`)
|
||||
: undefined;
|
||||
const userPrivateSQLExportsDir = userPrivateExportsDir
|
||||
? path.join(userPrivateExportsDir, `sql`)
|
||||
? path_1.default.join(userPrivateExportsDir, `sql`)
|
||||
: undefined;
|
||||
const userPrivateTempSQLExportsDir = userPrivateSQLExportsDir
|
||||
? path.join(userPrivateSQLExportsDir, tempDirName)
|
||||
? path_1.default.join(userPrivateSQLExportsDir, tempDirName)
|
||||
: undefined;
|
||||
const userPrivateTempJSONSchemaFilePath = userPrivateTempSQLExportsDir
|
||||
? path.join(userPrivateTempSQLExportsDir, `schema.json`)
|
||||
? path_1.default.join(userPrivateTempSQLExportsDir, `schema.json`)
|
||||
: undefined;
|
||||
const userPrivateDbExportZipFileName = `db-export.zip`;
|
||||
const userPrivateDbExportZipFilePath = userPrivateSQLExportsDir
|
||||
? path.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
||||
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
||||
: undefined;
|
||||
const userPublicMediaDir = finalUserId
|
||||
? path.join(publicImagesDir, `user-images/user-${finalUserId}`)
|
||||
? path_1.default.join(publicImagesDir, `user-images/user-${finalUserId}`)
|
||||
: undefined;
|
||||
const userPrivateDbImportZipFileName = `db-export.zip`;
|
||||
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
|
||||
? path.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
||||
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
||||
: undefined;
|
||||
const dbNginxLoadBalancerConfigFile = path.join(appDir, "docker/services/mariadb/load-balancer/config/template/nginx.conf");
|
||||
let dockerComposeFile = path.join(appDir, "docker-compose.yml");
|
||||
let dockerComposeFileAlt = path.join(appDir, "docker-compose.yaml");
|
||||
const testDockerComposeFile = path.join(appDir, "test.docker-compose.yml");
|
||||
const testDockerComposeFileAlt = path.join(appDir, "test.docker-compose.yaml");
|
||||
const dbDockerComposeFile = path.join(appDir, "db.docker-compose.yml");
|
||||
const dbDockerComposeFileAlt = path.join(appDir, "db.docker-compose.yaml");
|
||||
const extraDockerComposeFile = path.join(appDir, "extra.docker-compose.yml");
|
||||
const extraDockerComposeFileAlt = path.join(appDir, "extra.docker-compose.yaml");
|
||||
const siteSetupFile = path.join(appDir, "site-setup.json");
|
||||
const envFile = path.join(appDir, ".env");
|
||||
const testEnvFile = path.join(appDir, "test.env");
|
||||
const dbNginxLoadBalancerConfigFile = path_1.default.join(appDir, "docker/services/mariadb/load-balancer/config/template/nginx.conf");
|
||||
let dockerComposeFile = path_1.default.join(appDir, "docker-compose.yml");
|
||||
let dockerComposeFileAlt = path_1.default.join(appDir, "docker-compose.yaml");
|
||||
const testDockerComposeFile = path_1.default.join(appDir, "test.docker-compose.yml");
|
||||
const testDockerComposeFileAlt = path_1.default.join(appDir, "test.docker-compose.yaml");
|
||||
const dbDockerComposeFile = path_1.default.join(appDir, "db.docker-compose.yml");
|
||||
const dbDockerComposeFileAlt = path_1.default.join(appDir, "db.docker-compose.yaml");
|
||||
const extraDockerComposeFile = path_1.default.join(appDir, "extra.docker-compose.yml");
|
||||
const extraDockerComposeFileAlt = path_1.default.join(appDir, "extra.docker-compose.yaml");
|
||||
const siteSetupFile = path_1.default.join(appDir, "site-setup.json");
|
||||
const envFile = path_1.default.join(appDir, ".env");
|
||||
const testEnvFile = path_1.default.join(appDir, "test.env");
|
||||
/**
|
||||
* # Backup Dir names
|
||||
* @description
|
||||
*/
|
||||
const mainBackupDir = path.join(DATA_DIR, "backups");
|
||||
const mainBackupDir = path_1.default.join(DATA_DIR, "backups");
|
||||
const userBackupDir = targetUserPrivateDir
|
||||
? path.join(targetUserPrivateDir, `backups`)
|
||||
? path_1.default.join(targetUserPrivateDir, `backups`)
|
||||
: undefined;
|
||||
const sqlBackupDirName = `sql`;
|
||||
const schemasBackupDirName = `schema`;
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import grabDockerResourceIPNumbers from "../../grab-docker-resource-ip-numbers";
|
||||
export default function grabIPAddresses() {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabIPAddresses;
|
||||
const grab_docker_resource_ip_numbers_1 = __importDefault(require("../../grab-docker-resource-ip-numbers"));
|
||||
function grabIPAddresses() {
|
||||
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
|
||||
const { cron, db, maxscale, postDbSetup, web } = grabDockerResourceIPNumbers();
|
||||
const { cron, db, maxscale, postDbSetup, web } = (0, grab_docker_resource_ip_numbers_1.default)();
|
||||
const webAppIP = `${globalIPPrefix}.${web}`;
|
||||
const appCronIP = `${globalIPPrefix}.${cron}`;
|
||||
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
export default function replaceDatasquirelDbName({ str, userId, }) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = replaceDatasquirelDbName;
|
||||
function replaceDatasquirelDbName({ str, userId, }) {
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const userNameRegex = new RegExp(`${dbNamePrefix}\\d+_`, "g");
|
||||
const newPrefix = `${dbNamePrefix}${userId}_`;
|
||||
|
||||
+4
-1
@@ -1,3 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = parseCookies;
|
||||
/**
|
||||
* Parse request cookies
|
||||
* ===================================================
|
||||
@@ -5,7 +8,7 @@
|
||||
* @description This function takes in a request object and
|
||||
* returns the cookies as a JS object
|
||||
*/
|
||||
export default function parseCookies({ request, cookieString, }) {
|
||||
function parseCookies({ request, cookieString, }) {
|
||||
var _a;
|
||||
try {
|
||||
/** @type {string | undefined} */
|
||||
|
||||
+4
-1
@@ -1,10 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = camelJoinedtoCamelSpace;
|
||||
/**
|
||||
* Convert Camel Joined Text to Camel Spaced Text
|
||||
* ==============================================================================
|
||||
* @description this function takes a camel cased text without spaces, and returns
|
||||
* a camel-case-spaced text
|
||||
*/
|
||||
export default function camelJoinedtoCamelSpace(text) {
|
||||
function camelJoinedtoCamelSpace(text) {
|
||||
if (!(text === null || text === void 0 ? void 0 : text.match(/./))) {
|
||||
return "";
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
export default function checkIfIsMaster({ dbContext, dbFullName }) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = checkIfIsMaster;
|
||||
function checkIfIsMaster({ dbContext, dbFullName }) {
|
||||
return (dbContext === null || dbContext === void 0 ? void 0 : dbContext.match(/dsql.user/i))
|
||||
? false
|
||||
: global.DSQL_USE_LOCAL
|
||||
|
||||
+5
-2
@@ -1,3 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ccol = void 0;
|
||||
const consoleColors = {
|
||||
Reset: "\x1b[0m",
|
||||
Bright: "\x1b[1m",
|
||||
@@ -25,5 +28,5 @@ const consoleColors = {
|
||||
BgWhite: "\x1b[47m",
|
||||
BgGray: "\x1b[100m",
|
||||
};
|
||||
export default consoleColors;
|
||||
export const ccol = consoleColors;
|
||||
exports.default = consoleColors;
|
||||
exports.ccol = consoleColors;
|
||||
|
||||
+10
-4
@@ -1,4 +1,10 @@
|
||||
export function setCookie(res, name, value, options = {}) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.setCookie = setCookie;
|
||||
exports.getCookie = getCookie;
|
||||
exports.updateCookie = updateCookie;
|
||||
exports.deleteCookie = deleteCookie;
|
||||
function setCookie(res, name, value, options = {}) {
|
||||
const cookieParts = [
|
||||
`${encodeURIComponent(name)}=${encodeURIComponent(value)}`,
|
||||
];
|
||||
@@ -22,7 +28,7 @@ export function setCookie(res, name, value, options = {}) {
|
||||
}
|
||||
res.setHeader("Set-Cookie", cookieParts.join("; "));
|
||||
}
|
||||
export function getCookie(req, name) {
|
||||
function getCookie(req, name) {
|
||||
const cookieHeader = req.headers.cookie;
|
||||
if (!cookieHeader)
|
||||
return null;
|
||||
@@ -35,9 +41,9 @@ export function getCookie(req, name) {
|
||||
}, {});
|
||||
return cookies[name] || null;
|
||||
}
|
||||
export function updateCookie(res, name, value, options = {}) {
|
||||
function updateCookie(res, name, value, options = {}) {
|
||||
setCookie(res, name, value, options);
|
||||
}
|
||||
export function deleteCookie(res, name, options = {}) {
|
||||
function deleteCookie(res, name, options = {}) {
|
||||
setCookie(res, name, "", Object.assign(Object.assign({}, options), { expires: new Date(0), maxAge: 0 }));
|
||||
}
|
||||
|
||||
+55
-38
@@ -1,41 +1,58 @@
|
||||
import { generate } from "generate-password";
|
||||
import dbHandler from "../functions/backend/dbHandler";
|
||||
import dsqlCrud from "./data-fetching/crud";
|
||||
import encrypt from "../functions/dsql/encrypt";
|
||||
import grabUserMainSqlUserName from "./grab-user-main-sql-user-name";
|
||||
import grabDbNames from "./grab-db-names";
|
||||
import { createNewSQLUser } from "../functions/web-app/mariadb-user/handle-mariadb-user-creation";
|
||||
export default async function createUserSQLUser(user) {
|
||||
const { fullName, host, username: mariaDBUsername, webHost, } = grabUserMainSqlUserName({ user });
|
||||
const { userDbPrefix } = grabDbNames({ user });
|
||||
await dbHandler({
|
||||
query: `DROP USER IF EXISTS '${mariaDBUsername}'@'${webHost}'`,
|
||||
noErrorLogs: true,
|
||||
"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());
|
||||
});
|
||||
const newPassword = generate({ length: 32 });
|
||||
await createNewSQLUser({
|
||||
host: webHost,
|
||||
password: newPassword,
|
||||
username: mariaDBUsername,
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = createUserSQLUser;
|
||||
const generate_password_1 = require("generate-password");
|
||||
const dbHandler_1 = __importDefault(require("../functions/backend/dbHandler"));
|
||||
const crud_1 = __importDefault(require("./data-fetching/crud"));
|
||||
const encrypt_1 = __importDefault(require("../functions/dsql/encrypt"));
|
||||
const grab_user_main_sql_user_name_1 = __importDefault(require("./grab-user-main-sql-user-name"));
|
||||
const grab_db_names_1 = __importDefault(require("./grab-db-names"));
|
||||
const handle_mariadb_user_creation_1 = require("../functions/web-app/mariadb-user/handle-mariadb-user-creation");
|
||||
function createUserSQLUser(user) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { fullName, host, username: mariaDBUsername, webHost, } = (0, grab_user_main_sql_user_name_1.default)({ user });
|
||||
const { userDbPrefix } = (0, grab_db_names_1.default)({ user });
|
||||
yield (0, dbHandler_1.default)({
|
||||
query: `DROP USER IF EXISTS '${mariaDBUsername}'@'${webHost}'`,
|
||||
noErrorLogs: true,
|
||||
});
|
||||
const newPassword = (0, generate_password_1.generate)({ length: 32 });
|
||||
yield (0, handle_mariadb_user_creation_1.createNewSQLUser)({
|
||||
host: webHost,
|
||||
password: newPassword,
|
||||
username: mariaDBUsername,
|
||||
});
|
||||
const updateWebHostGrants = (yield (0, dbHandler_1.default)({
|
||||
query: `GRANT ALL PRIVILEGES ON \`${userDbPrefix.replace(/\_/g, "\\_")}%\`.* TO '${mariaDBUsername}'@'${webHost}'`,
|
||||
}));
|
||||
const updateUser = yield (0, crud_1.default)({
|
||||
action: "update",
|
||||
table: "users",
|
||||
targetField: "id",
|
||||
targetValue: user.id,
|
||||
data: {
|
||||
mariadb_host: webHost,
|
||||
mariadb_pass: (0, encrypt_1.default)({ data: newPassword }) || undefined,
|
||||
mariadb_user: mariaDBUsername,
|
||||
},
|
||||
});
|
||||
return {
|
||||
fullName,
|
||||
host,
|
||||
username: mariaDBUsername,
|
||||
password: newPassword,
|
||||
};
|
||||
});
|
||||
const updateWebHostGrants = (await dbHandler({
|
||||
query: `GRANT ALL PRIVILEGES ON \`${userDbPrefix.replace(/\_/g, "\\_")}%\`.* TO '${mariaDBUsername}'@'${webHost}'`,
|
||||
}));
|
||||
const updateUser = await dsqlCrud({
|
||||
action: "update",
|
||||
table: "users",
|
||||
targetField: "id",
|
||||
targetValue: user.id,
|
||||
data: {
|
||||
mariadb_host: webHost,
|
||||
mariadb_pass: encrypt({ data: newPassword }) || undefined,
|
||||
mariadb_user: mariaDBUsername,
|
||||
},
|
||||
});
|
||||
return {
|
||||
fullName,
|
||||
host,
|
||||
username: mariaDBUsername,
|
||||
password: newPassword,
|
||||
};
|
||||
}
|
||||
|
||||
+68
-51
@@ -1,60 +1,77 @@
|
||||
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||
import connDbHandler from "../db/conn-db-handler";
|
||||
export default async function ({ table, query, count, countOnly, dbFullName, }) {
|
||||
var _a, _b, _c, _d;
|
||||
let queryObject;
|
||||
queryObject = sqlGenerator({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
dbFullName,
|
||||
"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());
|
||||
});
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
let connQueries = [
|
||||
{
|
||||
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
values: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
||||
},
|
||||
];
|
||||
const countQueryObject = count || countOnly
|
||||
? sqlGenerator({
|
||||
};
|
||||
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 sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||
function default_1(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, dbFullName, }) {
|
||||
var _b, _c, _d, _e;
|
||||
let queryObject;
|
||||
queryObject = (0, sql_generator_1.default)({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
count: true,
|
||||
dbFullName,
|
||||
})
|
||||
: undefined;
|
||||
if (count && countQueryObject) {
|
||||
connQueries.push({
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
});
|
||||
}
|
||||
else if (countOnly && countQueryObject) {
|
||||
connQueries = [
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
let connQueries = [
|
||||
{
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
values: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
||||
},
|
||||
];
|
||||
}
|
||||
const res = await connDbHandler(DB_CONN, connQueries);
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
batchPayload: isSuccess ? (countOnly ? null : res) : null,
|
||||
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
||||
errors: res === null || res === void 0 ? void 0 : res.errors,
|
||||
queryObject: {
|
||||
sql: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
params: queryObject === null || queryObject === void 0 ? void 0 : queryObject.values,
|
||||
},
|
||||
count: isSuccess
|
||||
? ((_b = (_a = res[1]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b["COUNT(*)"])
|
||||
? res[1][0]["COUNT(*)"]
|
||||
: ((_d = (_c = res[0]) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d["COUNT(*)"])
|
||||
? res[0][0]["COUNT(*)"]
|
||||
: undefined
|
||||
: undefined,
|
||||
};
|
||||
const countQueryObject = count || countOnly
|
||||
? (0, sql_generator_1.default)({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
count: true,
|
||||
dbFullName,
|
||||
})
|
||||
: undefined;
|
||||
if (count && countQueryObject) {
|
||||
connQueries.push({
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
});
|
||||
}
|
||||
else if (countOnly && countQueryObject) {
|
||||
connQueries = [
|
||||
{
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
},
|
||||
];
|
||||
}
|
||||
const res = yield (0, conn_db_handler_1.default)(DB_CONN, connQueries);
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
batchPayload: isSuccess ? (countOnly ? null : res) : null,
|
||||
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
||||
errors: res === null || res === void 0 ? void 0 : res.errors,
|
||||
queryObject: {
|
||||
sql: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
params: queryObject === null || queryObject === void 0 ? void 0 : queryObject.values,
|
||||
},
|
||||
count: isSuccess
|
||||
? ((_c = (_b = res[1]) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c["COUNT(*)"])
|
||||
? res[1][0]["COUNT(*)"]
|
||||
: ((_e = (_d = res[0]) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e["COUNT(*)"])
|
||||
? res[0][0]["COUNT(*)"]
|
||||
: undefined
|
||||
: undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
+77
-60
@@ -1,61 +1,78 @@
|
||||
import sqlDeleteGenerator from "../../functions/dsql/sql/sql-delete-generator";
|
||||
import dsqlCrudGet from "./crud-get";
|
||||
import connDbHandler from "../db/conn-db-handler";
|
||||
import addDbEntry from "../../functions/backend/db/addDbEntry";
|
||||
import updateDbEntry from "../../functions/backend/db/updateDbEntry";
|
||||
export default async function dsqlCrud(params) {
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, dbFullName, deleteData, batchData, deleteKeyValues, } = params;
|
||||
const finalData = (sanitize ? sanitize({ data }) : data);
|
||||
const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData);
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
switch (action) {
|
||||
case "get":
|
||||
return await dsqlCrudGet(params);
|
||||
// case "batch-get":
|
||||
// return await dsqlCrudBatchGet(params);
|
||||
case "insert":
|
||||
const INSERT_RESULT = await addDbEntry({
|
||||
data: finalData,
|
||||
batchData: finalBatchData,
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
});
|
||||
return INSERT_RESULT;
|
||||
case "update":
|
||||
data === null || data === void 0 ? true : delete data.id;
|
||||
const UPDATE_RESULT = await updateDbEntry({
|
||||
data: finalData,
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
identifierColumnName: (targetField || "id"),
|
||||
identifierValue: String(targetValue || targetId),
|
||||
});
|
||||
return UPDATE_RESULT;
|
||||
case "delete":
|
||||
const deleteQuery = sqlDeleteGenerator({
|
||||
data: targetId
|
||||
? { id: targetId }
|
||||
: targetField && targetValue
|
||||
? { [targetField]: targetValue }
|
||||
: deleteData,
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
deleteKeyValues,
|
||||
});
|
||||
const res = (await connDbHandler(DB_CONN, deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.query, deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.values));
|
||||
return {
|
||||
success: Boolean(res.affectedRows),
|
||||
payload: res,
|
||||
queryObject: {
|
||||
sql: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.query) || "",
|
||||
params: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.values) || [],
|
||||
},
|
||||
};
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
msg: "Invalid action",
|
||||
};
|
||||
}
|
||||
"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 = dsqlCrud;
|
||||
const sql_delete_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-delete-generator"));
|
||||
const crud_get_1 = __importDefault(require("./crud-get"));
|
||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||
const addDbEntry_1 = __importDefault(require("../../functions/backend/db/addDbEntry"));
|
||||
const updateDbEntry_1 = __importDefault(require("../../functions/backend/db/updateDbEntry"));
|
||||
function dsqlCrud(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, dbFullName, deleteData, batchData, deleteKeyValues, } = params;
|
||||
const finalData = (sanitize ? sanitize({ data }) : data);
|
||||
const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData);
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
switch (action) {
|
||||
case "get":
|
||||
return yield (0, crud_get_1.default)(params);
|
||||
// case "batch-get":
|
||||
// return await dsqlCrudBatchGet(params);
|
||||
case "insert":
|
||||
const INSERT_RESULT = yield (0, addDbEntry_1.default)({
|
||||
data: finalData,
|
||||
batchData: finalBatchData,
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
});
|
||||
return INSERT_RESULT;
|
||||
case "update":
|
||||
data === null || data === void 0 ? true : delete data.id;
|
||||
const UPDATE_RESULT = yield (0, updateDbEntry_1.default)({
|
||||
data: finalData,
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
identifierColumnName: (targetField || "id"),
|
||||
identifierValue: String(targetValue || targetId),
|
||||
});
|
||||
return UPDATE_RESULT;
|
||||
case "delete":
|
||||
const deleteQuery = (0, sql_delete_generator_1.default)({
|
||||
data: targetId
|
||||
? { id: targetId }
|
||||
: targetField && targetValue
|
||||
? { [targetField]: targetValue }
|
||||
: deleteData,
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
deleteKeyValues,
|
||||
});
|
||||
const res = (yield (0, conn_db_handler_1.default)(DB_CONN, deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.query, deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.values));
|
||||
return {
|
||||
success: Boolean(res.affectedRows),
|
||||
payload: res,
|
||||
queryObject: {
|
||||
sql: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.query) || "",
|
||||
params: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.values) || [],
|
||||
},
|
||||
};
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
msg: "Invalid action",
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+162
-145
@@ -1,150 +1,167 @@
|
||||
import _ from "lodash";
|
||||
import deserializeQuery from "../deserialize-query";
|
||||
import EJSON from "../ejson";
|
||||
import numberfy from "../numberfy";
|
||||
import dsqlCrud from "./crud";
|
||||
export default async function dsqlMethodCrud({ method, tableName, addUser, user, extraData, transformData, existingData, body, query, targetId, sanitize, transformQuery, debug, }) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
let result = {
|
||||
success: false,
|
||||
};
|
||||
try {
|
||||
let finalBody = body;
|
||||
let finalQuery = deserializeQuery(query);
|
||||
let LIMIT = 10;
|
||||
let PAGE = 1;
|
||||
let OFFSET = (PAGE - 1) * LIMIT;
|
||||
if (method == "GET") {
|
||||
const newFinalQuery = _.cloneDeep(finalQuery || {});
|
||||
Object.keys(newFinalQuery).forEach((key) => {
|
||||
const value = newFinalQuery[key];
|
||||
if (typeof value == "string" && value.match(/^\{|^\[/)) {
|
||||
newFinalQuery[key] = EJSON.stringify(value);
|
||||
}
|
||||
if (value == "true") {
|
||||
newFinalQuery[key] = true;
|
||||
}
|
||||
if (value == "false") {
|
||||
newFinalQuery[key] = false;
|
||||
}
|
||||
});
|
||||
if (newFinalQuery.limit)
|
||||
LIMIT = numberfy(newFinalQuery.limit);
|
||||
if (newFinalQuery.page)
|
||||
PAGE = numberfy(newFinalQuery.page);
|
||||
OFFSET = (PAGE - 1) * LIMIT;
|
||||
finalQuery = newFinalQuery;
|
||||
}
|
||||
let finalData = finalBody
|
||||
? Object.assign(Object.assign({}, finalBody), extraData)
|
||||
: {};
|
||||
if ((user === null || user === void 0 ? void 0 : user.id) && addUser) {
|
||||
finalData = Object.assign(Object.assign({}, finalData), { [addUser.field]: String(user.id) });
|
||||
}
|
||||
if (transformData) {
|
||||
if (debug) {
|
||||
console.log("DEBUG:::transforming Data ...");
|
||||
"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 = dsqlMethodCrud;
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
const deserialize_query_1 = __importDefault(require("../deserialize-query"));
|
||||
const ejson_1 = __importDefault(require("../ejson"));
|
||||
const numberfy_1 = __importDefault(require("../numberfy"));
|
||||
const crud_1 = __importDefault(require("./crud"));
|
||||
function dsqlMethodCrud(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ method, tableName, addUser, user, extraData, transformData, existingData, body, query, targetId, sanitize, transformQuery, debug, }) {
|
||||
var _b, _c, _d, _e, _f;
|
||||
let result = {
|
||||
success: false,
|
||||
};
|
||||
try {
|
||||
let finalBody = body;
|
||||
let finalQuery = (0, deserialize_query_1.default)(query);
|
||||
let LIMIT = 10;
|
||||
let PAGE = 1;
|
||||
let OFFSET = (PAGE - 1) * LIMIT;
|
||||
if (method == "GET") {
|
||||
const newFinalQuery = lodash_1.default.cloneDeep(finalQuery || {});
|
||||
Object.keys(newFinalQuery).forEach((key) => {
|
||||
const value = newFinalQuery[key];
|
||||
if (typeof value == "string" && value.match(/^\{|^\[/)) {
|
||||
newFinalQuery[key] = ejson_1.default.stringify(value);
|
||||
}
|
||||
if (value == "true") {
|
||||
newFinalQuery[key] = true;
|
||||
}
|
||||
if (value == "false") {
|
||||
newFinalQuery[key] = false;
|
||||
}
|
||||
});
|
||||
if (newFinalQuery.limit)
|
||||
LIMIT = (0, numberfy_1.default)(newFinalQuery.limit);
|
||||
if (newFinalQuery.page)
|
||||
PAGE = (0, numberfy_1.default)(newFinalQuery.page);
|
||||
OFFSET = (PAGE - 1) * LIMIT;
|
||||
finalQuery = newFinalQuery;
|
||||
}
|
||||
finalData = (await transformData({
|
||||
data: finalData,
|
||||
existingData: existingData,
|
||||
user,
|
||||
reqMethod: method,
|
||||
}));
|
||||
}
|
||||
if (transformQuery) {
|
||||
if (debug) {
|
||||
console.log("DEBUG:::transforming Query ...");
|
||||
let finalData = finalBody
|
||||
? Object.assign(Object.assign({}, finalBody), extraData)
|
||||
: {};
|
||||
if ((user === null || user === void 0 ? void 0 : user.id) && addUser) {
|
||||
finalData = Object.assign(Object.assign({}, finalData), { [addUser.field]: String(user.id) });
|
||||
}
|
||||
finalQuery = await transformQuery({
|
||||
query: finalQuery || {},
|
||||
user,
|
||||
reqMethod: method,
|
||||
});
|
||||
if (transformData) {
|
||||
if (debug) {
|
||||
console.log("DEBUG:::transforming Data ...");
|
||||
}
|
||||
finalData = (yield transformData({
|
||||
data: finalData,
|
||||
existingData: existingData,
|
||||
user,
|
||||
reqMethod: method,
|
||||
}));
|
||||
}
|
||||
if (transformQuery) {
|
||||
if (debug) {
|
||||
console.log("DEBUG:::transforming Query ...");
|
||||
}
|
||||
finalQuery = yield transformQuery({
|
||||
query: finalQuery || {},
|
||||
user,
|
||||
reqMethod: method,
|
||||
});
|
||||
}
|
||||
if (debug) {
|
||||
console.log("DEBUG:::finalQuery", finalQuery);
|
||||
console.log("DEBUG:::finalData", finalData);
|
||||
}
|
||||
switch (method) {
|
||||
case "GET":
|
||||
const GET_RESULT = yield (0, crud_1.default)({
|
||||
action: "get",
|
||||
table: tableName,
|
||||
query: Object.assign(Object.assign({}, finalQuery), { query: Object.assign(Object.assign({}, finalQuery === null || finalQuery === void 0 ? void 0 : finalQuery.query), ((user === null || user === void 0 ? void 0 : user.id) && addUser
|
||||
? {
|
||||
[addUser.field]: {
|
||||
value: String(user.id),
|
||||
},
|
||||
}
|
||||
: undefined)), limit: LIMIT, offset: OFFSET }),
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.success),
|
||||
payload: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.payload,
|
||||
msg: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.msg,
|
||||
error: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.error,
|
||||
queryObject: {
|
||||
string: ((_b = GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.queryObject) === null || _b === void 0 ? void 0 : _b.sql) || "",
|
||||
values: ((_c = GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.queryObject) === null || _c === void 0 ? void 0 : _c.params) || [],
|
||||
},
|
||||
};
|
||||
break;
|
||||
case "POST":
|
||||
const POST_RESULT = yield (0, crud_1.default)({
|
||||
action: "insert",
|
||||
table: tableName,
|
||||
data: finalData && ((_d = Object.keys(finalData)) === null || _d === void 0 ? void 0 : _d[0])
|
||||
? finalData
|
||||
: undefined,
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.success),
|
||||
payload: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.payload,
|
||||
msg: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.msg,
|
||||
error: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.error,
|
||||
};
|
||||
break;
|
||||
case "PUT":
|
||||
const PUT_RESULT = yield (0, crud_1.default)({
|
||||
action: "update",
|
||||
table: tableName,
|
||||
data: finalData && ((_e = Object.keys(finalData)) === null || _e === void 0 ? void 0 : _e[0])
|
||||
? finalData
|
||||
: undefined,
|
||||
targetId,
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.success),
|
||||
payload: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.payload,
|
||||
msg: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.msg,
|
||||
error: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.error,
|
||||
};
|
||||
break;
|
||||
case "DELETE":
|
||||
const DELETE_RESULT = yield (0, crud_1.default)({
|
||||
action: "delete",
|
||||
table: tableName,
|
||||
targetId,
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.success),
|
||||
payload: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.payload,
|
||||
msg: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.msg,
|
||||
error: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.error,
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (debug) {
|
||||
console.log("DEBUG:::finalQuery", finalQuery);
|
||||
console.log("DEBUG:::finalData", finalData);
|
||||
catch (error) {
|
||||
(_f = global.ERROR_CALLBACK) === null || _f === void 0 ? void 0 : _f.call(global, `Method Crud Error`, error);
|
||||
return result;
|
||||
}
|
||||
switch (method) {
|
||||
case "GET":
|
||||
const GET_RESULT = await dsqlCrud({
|
||||
action: "get",
|
||||
table: tableName,
|
||||
query: Object.assign(Object.assign({}, finalQuery), { query: Object.assign(Object.assign({}, finalQuery === null || finalQuery === void 0 ? void 0 : finalQuery.query), ((user === null || user === void 0 ? void 0 : user.id) && addUser
|
||||
? {
|
||||
[addUser.field]: {
|
||||
value: String(user.id),
|
||||
},
|
||||
}
|
||||
: undefined)), limit: LIMIT, offset: OFFSET }),
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.success),
|
||||
payload: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.payload,
|
||||
msg: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.msg,
|
||||
error: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.error,
|
||||
queryObject: {
|
||||
string: ((_a = GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.queryObject) === null || _a === void 0 ? void 0 : _a.sql) || "",
|
||||
values: ((_b = GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.queryObject) === null || _b === void 0 ? void 0 : _b.params) || [],
|
||||
},
|
||||
};
|
||||
break;
|
||||
case "POST":
|
||||
const POST_RESULT = await dsqlCrud({
|
||||
action: "insert",
|
||||
table: tableName,
|
||||
data: finalData && ((_c = Object.keys(finalData)) === null || _c === void 0 ? void 0 : _c[0])
|
||||
? finalData
|
||||
: undefined,
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.success),
|
||||
payload: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.payload,
|
||||
msg: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.msg,
|
||||
error: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.error,
|
||||
};
|
||||
break;
|
||||
case "PUT":
|
||||
const PUT_RESULT = await dsqlCrud({
|
||||
action: "update",
|
||||
table: tableName,
|
||||
data: finalData && ((_d = Object.keys(finalData)) === null || _d === void 0 ? void 0 : _d[0])
|
||||
? finalData
|
||||
: undefined,
|
||||
targetId,
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.success),
|
||||
payload: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.payload,
|
||||
msg: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.msg,
|
||||
error: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.error,
|
||||
};
|
||||
break;
|
||||
case "DELETE":
|
||||
const DELETE_RESULT = await dsqlCrud({
|
||||
action: "delete",
|
||||
table: tableName,
|
||||
targetId,
|
||||
sanitize,
|
||||
});
|
||||
result = {
|
||||
success: Boolean(DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.success),
|
||||
payload: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.payload,
|
||||
msg: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.msg,
|
||||
error: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.error,
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (error) {
|
||||
(_e = global.ERROR_CALLBACK) === null || _e === void 0 ? void 0 : _e.call(global, `Method Crud Error`, error);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+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;
|
||||
|
||||
+9
-3
@@ -1,9 +1,15 @@
|
||||
import _ from "lodash";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = deleteByKey;
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
/**
|
||||
* # Delete all matches in an Array
|
||||
*/
|
||||
export default function deleteByKey(arr, key) {
|
||||
let newArray = _.cloneDeep(arr);
|
||||
function deleteByKey(arr, key) {
|
||||
let newArray = lodash_1.default.cloneDeep(arr);
|
||||
for (let i = 0; i < newArray.length; i++) {
|
||||
const item = newArray[i];
|
||||
if (Array.isArray(key)) {
|
||||
|
||||
+10
-4
@@ -1,16 +1,22 @@
|
||||
import EJSON from "./ejson";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = deserializeQuery;
|
||||
const ejson_1 = __importDefault(require("./ejson"));
|
||||
/**
|
||||
* # Convert Serialized Query back to object
|
||||
*/
|
||||
export default function deserializeQuery(query) {
|
||||
let queryObject = typeof query == "object" ? query : Object(EJSON.parse(query));
|
||||
function deserializeQuery(query) {
|
||||
let queryObject = typeof query == "object" ? query : Object(ejson_1.default.parse(query));
|
||||
const keys = Object.keys(queryObject);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
const value = queryObject[key];
|
||||
if (typeof value == "string") {
|
||||
if (value.match(/^\{|^\[/)) {
|
||||
queryObject[key] = EJSON.parse(value);
|
||||
queryObject[key] = ejson_1.default.parse(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
-1
@@ -1,3 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* # EJSON parse string
|
||||
*/
|
||||
@@ -30,4 +32,4 @@ const EJSON = {
|
||||
parse,
|
||||
stringify,
|
||||
};
|
||||
export default EJSON;
|
||||
exports.default = EJSON;
|
||||
|
||||
+13
-7
@@ -1,17 +1,23 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
export default function emptyDirectory(dir) {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = emptyDirectory;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
function emptyDirectory(dir) {
|
||||
try {
|
||||
const dirContent = fs.readdirSync(dir);
|
||||
const dirContent = fs_1.default.readdirSync(dir);
|
||||
for (let i = 0; i < dirContent.length; i++) {
|
||||
const fileFolder = dirContent[i];
|
||||
const fullFileFolderPath = path.join(dir, fileFolder);
|
||||
const stat = fs.statSync(fullFileFolderPath);
|
||||
const fullFileFolderPath = path_1.default.join(dir, fileFolder);
|
||||
const stat = fs_1.default.statSync(fullFileFolderPath);
|
||||
if (stat.isDirectory()) {
|
||||
emptyDirectory(fullFileFolderPath);
|
||||
continue;
|
||||
}
|
||||
fs.unlinkSync(fullFileFolderPath);
|
||||
fs_1.default.unlinkSync(fullFileFolderPath);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* # End MYSQL Connection
|
||||
*/
|
||||
@@ -8,4 +10,4 @@ function endConnection(connection) {
|
||||
});
|
||||
}
|
||||
}
|
||||
export default endConnection;
|
||||
exports.default = endConnection;
|
||||
|
||||
Vendored
+4
-1
@@ -1,4 +1,7 @@
|
||||
export default function envsub(str) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = envsub;
|
||||
function envsub(str) {
|
||||
return str.replace(/\$([A-Z_]+)|\${([A-Z_]+)}/g, (match, var1, var2) => {
|
||||
const varName = var1 || var2;
|
||||
return process.env[varName] || match;
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
"use strict";
|
||||
// @ts-check
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = generateColumnDescription;
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -8,7 +11,7 @@
|
||||
/**
|
||||
* # Generate SQL text for Field
|
||||
*/
|
||||
export default function generateColumnDescription({ columnData, primaryKeySet, }) {
|
||||
function generateColumnDescription({ columnData, primaryKeySet, }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
|
||||
+4
-1
@@ -1,5 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabAPIBasePath;
|
||||
const APIParadigms = ["crud", "media", "schema"];
|
||||
export default function grabAPIBasePath({ version, paradigm }) {
|
||||
function grabAPIBasePath({ version, paradigm }) {
|
||||
let basePath = `/api/v${version || "1"}`;
|
||||
if (paradigm) {
|
||||
basePath += `/${paradigm}`;
|
||||
|
||||
+13
-7
@@ -1,11 +1,17 @@
|
||||
import fs from "fs";
|
||||
import grabDirNames from "./backend/names/grab-dir-names";
|
||||
import EJSON from "./ejson";
|
||||
export default function grabAppMainDbSchema() {
|
||||
const { appSchemaJSONFile } = grabDirNames();
|
||||
if (!fs.existsSync(appSchemaJSONFile)) {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabAppMainDbSchema;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const grab_dir_names_1 = __importDefault(require("./backend/names/grab-dir-names"));
|
||||
const ejson_1 = __importDefault(require("./ejson"));
|
||||
function grabAppMainDbSchema() {
|
||||
const { appSchemaJSONFile } = (0, grab_dir_names_1.default)();
|
||||
if (!fs_1.default.existsSync(appSchemaJSONFile)) {
|
||||
return undefined;
|
||||
}
|
||||
const parsedAppSchema = EJSON.parse(fs.readFileSync(appSchemaJSONFile, "utf-8"));
|
||||
const parsedAppSchema = ejson_1.default.parse(fs_1.default.readFileSync(appSchemaJSONFile, "utf-8"));
|
||||
return parsedAppSchema;
|
||||
}
|
||||
|
||||
+6
-3
@@ -1,9 +1,12 @@
|
||||
import { AppVersions } from "../types";
|
||||
export default function grabAppVersion() {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabAppVersion;
|
||||
const types_1 = require("../types");
|
||||
function grabAppVersion() {
|
||||
const appVersionEnv = process.env.NEXT_PUBLIC_VERSION;
|
||||
const finalAppVersion = (appVersionEnv ||
|
||||
"community");
|
||||
const targetAppVersion = AppVersions.find((version) => version.value === finalAppVersion);
|
||||
const targetAppVersion = types_1.AppVersions.find((version) => version.value === finalAppVersion);
|
||||
if (!targetAppVersion) {
|
||||
throw new Error(`Invalid App Version: ${finalAppVersion}`);
|
||||
}
|
||||
|
||||
+9
-3
@@ -1,9 +1,15 @@
|
||||
import numberfy from "./numberfy";
|
||||
export default function grabCookieExpiryDate() {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabCookieExpiryDate;
|
||||
const numberfy_1 = __importDefault(require("./numberfy"));
|
||||
function grabCookieExpiryDate() {
|
||||
const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
|
||||
const ONE_WEEK_IN_SECONDS = ONE_DAY_IN_SECONDS * 7;
|
||||
const COOKIE_EXPIRY_TIME_IN_SECONDS = process.env.DSQL_SESSION_EXPIRY_TIME
|
||||
? numberfy(process.env.DSQL_SESSION_EXPIRY_TIME)
|
||||
? (0, numberfy_1.default)(process.env.DSQL_SESSION_EXPIRY_TIME)
|
||||
: ONE_WEEK_IN_SECONDS;
|
||||
const COOKIE_EXPIRY_IN_MILLISECONDS = COOKIE_EXPIRY_TIME_IN_SECONDS * 1000;
|
||||
const COOKIE_EXPIRY_DATE = new Date(Date.now() + COOKIE_EXPIRY_IN_MILLISECONDS).toUTCString();
|
||||
|
||||
+10
-4
@@ -1,11 +1,17 @@
|
||||
import slugify from "./slugify";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDbFullName;
|
||||
const slugify_1 = __importDefault(require("./slugify"));
|
||||
/**
|
||||
* # Grab full database name
|
||||
* @description Grab full database name from slug or full name
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
export default function grabDbFullName({ dbName, userId, user, }) {
|
||||
function grabDbFullName({ dbName, userId, user, }) {
|
||||
const finalUserId = (user === null || user === void 0 ? void 0 : user.id) || userId;
|
||||
if (!finalUserId) {
|
||||
return dbName;
|
||||
@@ -14,7 +20,7 @@ export default function grabDbFullName({ dbName, userId, user, }) {
|
||||
return;
|
||||
}
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const parsedDbName = slugify(dbName, "_");
|
||||
const parsedDbName = (0, slugify_1.default)(dbName, "_");
|
||||
const dbSlug = parsedDbName.replace(new RegExp(`${dbNamePrefix}_?\\d+_`), "");
|
||||
return slugify(`${dbNamePrefix}_${finalUserId}_${dbSlug}`, "_");
|
||||
return (0, slugify_1.default)(`${dbNamePrefix}_${finalUserId}_${dbSlug}`, "_");
|
||||
}
|
||||
|
||||
+9
-3
@@ -1,14 +1,20 @@
|
||||
import grabDbFullName from "./grab-db-full-name";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDbNames;
|
||||
const grab_db_full_name_1 = __importDefault(require("./grab-db-full-name"));
|
||||
/**
|
||||
* # Grab full database name
|
||||
* @description Grab full database name from slug or full name
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
export default function grabDbNames({ dbName, userId, user }) {
|
||||
function grabDbNames({ dbName, userId, user }) {
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const finalUserId = (user === null || user === void 0 ? void 0 : user.id) || userId;
|
||||
const userDbPrefix = `${dbNamePrefix}${finalUserId}_`;
|
||||
const dbFullName = grabDbFullName({ dbName, user, userId });
|
||||
const dbFullName = (0, grab_db_full_name_1.default)({ dbName, user, userId });
|
||||
return { userDbPrefix, dbFullName, dbNamePrefix };
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
export default function grabDockerResourceIPNumbers() {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDockerResourceIPNumbers;
|
||||
function grabDockerResourceIPNumbers() {
|
||||
return {
|
||||
db: 32,
|
||||
maxscale: 24,
|
||||
|
||||
+12
-6
@@ -1,11 +1,17 @@
|
||||
import mysql from "serverless-mysql";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDSQLConnection;
|
||||
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
|
||||
/**
|
||||
* # Grab General CONNECTION for DSQL
|
||||
*/
|
||||
export default function grabDSQLConnection(param) {
|
||||
function grabDSQLConnection(param) {
|
||||
if (global.DSQL_USE_LOCAL || (param === null || param === void 0 ? void 0 : param.local)) {
|
||||
return (global.DSQL_DB_CONN ||
|
||||
mysql({
|
||||
(0, serverless_mysql_1.default)({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
@@ -22,7 +28,7 @@ export default function grabDSQLConnection(param) {
|
||||
}
|
||||
if (param === null || param === void 0 ? void 0 : param.ro) {
|
||||
return (global.DSQL_READ_ONLY_DB_CONN ||
|
||||
mysql({
|
||||
(0, serverless_mysql_1.default)({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_READ_ONLY_USERNAME,
|
||||
@@ -36,7 +42,7 @@ export default function grabDSQLConnection(param) {
|
||||
}
|
||||
if (param === null || param === void 0 ? void 0 : param.fa) {
|
||||
return (global.DSQL_FULL_ACCESS_DB_CONN ||
|
||||
mysql({
|
||||
(0, serverless_mysql_1.default)({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_FULL_ACCESS_USERNAME,
|
||||
@@ -49,7 +55,7 @@ export default function grabDSQLConnection(param) {
|
||||
}));
|
||||
}
|
||||
return (global.DSQL_DB_CONN ||
|
||||
mysql({
|
||||
(0, serverless_mysql_1.default)({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
|
||||
+10
-4
@@ -1,10 +1,16 @@
|
||||
"use strict";
|
||||
// @ts-check
|
||||
import https from "https";
|
||||
import http from "http";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabHostNames;
|
||||
const https_1 = __importDefault(require("https"));
|
||||
const http_1 = __importDefault(require("http"));
|
||||
/**
|
||||
* # Grab Names For Query
|
||||
*/
|
||||
export default function grabHostNames(param) {
|
||||
function grabHostNames(param) {
|
||||
var _a, _b;
|
||||
const finalEnv = (param === null || param === void 0 ? void 0 : param.env)
|
||||
? Object.assign(Object.assign({}, process.env), param.env) : process.env;
|
||||
@@ -24,7 +30,7 @@ export default function grabHostNames(param) {
|
||||
return {
|
||||
host: remoteHost || localHost || "datasquirel.com",
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
scheme: (scheme === null || scheme === void 0 ? void 0 : scheme.match(/^http$/i)) ? http : https,
|
||||
scheme: (scheme === null || scheme === void 0 ? void 0 : scheme.match(/^http$/i)) ? http_1.default : https_1.default,
|
||||
user_id: (param === null || param === void 0 ? void 0 : param.userId) || String(finalEnv["DSQL_API_USER_ID"] || 0),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
export default function grabInstanceGlobalNetWorkName() {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabInstanceGlobalNetWorkName;
|
||||
function grabInstanceGlobalNetWorkName() {
|
||||
const deploymentName = process.env.DSQL_DEPLOYMENT_NAME || "dsql";
|
||||
return `${deploymentName}_dsql_global_network`;
|
||||
}
|
||||
|
||||
+9
-3
@@ -1,9 +1,15 @@
|
||||
import numberfy from "./numberfy";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabKeys;
|
||||
const numberfy_1 = __importDefault(require("./numberfy"));
|
||||
/**
|
||||
* # Grab Encryption Keys
|
||||
* @description Grab Required Encryption Keys
|
||||
*/
|
||||
export default function grabKeys(param) {
|
||||
function grabKeys(param) {
|
||||
return {
|
||||
key: (param === null || param === void 0 ? void 0 : param.encryptionKey) || process.env.DSQL_ENCRYPTION_PASSWORD,
|
||||
keyLen: process.env.DSQL_ENCRYPTION_KEY_LENGTH
|
||||
@@ -16,7 +22,7 @@ export default function grabKeys(param) {
|
||||
"aes-192-cbc",
|
||||
bufferAllocSize: (param === null || param === void 0 ? void 0 : param.bufferAllocSize) ||
|
||||
(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE
|
||||
? numberfy(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE)
|
||||
? (0, numberfy_1.default)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE)
|
||||
: undefined) ||
|
||||
16,
|
||||
};
|
||||
|
||||
+9
-3
@@ -1,8 +1,14 @@
|
||||
import sqlGenerator from "../functions/dsql/sql/sql-generator";
|
||||
export default function apiGetGrabQueryAndValues({ query, values }) {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = apiGetGrabQueryAndValues;
|
||||
const sql_generator_1 = __importDefault(require("../functions/dsql/sql/sql-generator"));
|
||||
function apiGetGrabQueryAndValues({ query, values }) {
|
||||
const queryGenObject = typeof query == "string"
|
||||
? undefined
|
||||
: sqlGenerator({
|
||||
: (0, sql_generator_1.default)({
|
||||
tableName: query.table,
|
||||
genObject: query.query,
|
||||
dbFullName: query.dbFullName || "__db",
|
||||
|
||||
+4
-1
@@ -1,8 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabSQLKeyName;
|
||||
/**
|
||||
* # Grab Key Names
|
||||
* @description Grab key names for foreign keys and indexes
|
||||
*/
|
||||
export default function grabSQLKeyName({ type, userId, addDate }) {
|
||||
function grabSQLKeyName({ type, userId, addDate }) {
|
||||
let prefixParadigm = (() => {
|
||||
if (type == "foreign_key")
|
||||
return "fk";
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
export default function grabSQLUserNameForUser(userId) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabSQLUserNameForUser;
|
||||
function grabSQLUserNameForUser(userId) {
|
||||
return `dsql_user_${userId || 0}`;
|
||||
}
|
||||
|
||||
+9
-3
@@ -1,10 +1,16 @@
|
||||
import grabSQLUserNameForUser from "./grab-sql-user-name-for-user";
|
||||
export default function grabSQLUserName({ user, name: passedName, }) {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabSQLUserName;
|
||||
const grab_sql_user_name_for_user_1 = __importDefault(require("./grab-sql-user-name-for-user"));
|
||||
function grabSQLUserName({ user, name: passedName, }) {
|
||||
if (!user) {
|
||||
console.log("No User Found");
|
||||
return {};
|
||||
}
|
||||
const sqlUsername = grabSQLUserNameForUser(user.id);
|
||||
const sqlUsername = (0, grab_sql_user_name_for_user_1.default)(user.id);
|
||||
const parsedPassedName = passedName
|
||||
? passedName.replace(sqlUsername, "").replace(/^_+|_+$/, "")
|
||||
: undefined;
|
||||
|
||||
+11
-5
@@ -1,8 +1,14 @@
|
||||
import grabSQLUserNameForUser from "./grab-sql-user-name-for-user";
|
||||
import grabIPAddresses from "../utils/backend/names/grab-ip-addresses";
|
||||
export default function grabUserMainSqlUserName({ HOST, user, username, }) {
|
||||
const sqlUsername = grabSQLUserNameForUser(user === null || user === void 0 ? void 0 : user.id);
|
||||
const { webAppIP, maxScaleIP } = grabIPAddresses();
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabUserMainSqlUserName;
|
||||
const grab_sql_user_name_for_user_1 = __importDefault(require("./grab-sql-user-name-for-user"));
|
||||
const grab_ip_addresses_1 = __importDefault(require("../utils/backend/names/grab-ip-addresses"));
|
||||
function grabUserMainSqlUserName({ HOST, user, username, }) {
|
||||
const sqlUsername = (0, grab_sql_user_name_for_user_1.default)(user === null || user === void 0 ? void 0 : user.id);
|
||||
const { webAppIP, maxScaleIP } = (0, grab_ip_addresses_1.default)();
|
||||
const finalUsername = username || sqlUsername;
|
||||
const finalHost = HOST || maxScaleIP || "127.0.0.1";
|
||||
const fullName = `${finalUsername}@${webAppIP}`;
|
||||
|
||||
+12
-9
@@ -1,17 +1,20 @@
|
||||
import { ccol } from "../console-colors";
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = debugLog;
|
||||
const console_colors_1 = require("../console-colors");
|
||||
const LogTypes = ["error", "warning"];
|
||||
export default function debugLog({ log, label, title, type, addTime }) {
|
||||
function debugLog({ log, label, title, type, addTime }) {
|
||||
const logType = (() => {
|
||||
switch (type) {
|
||||
case "error":
|
||||
return ccol.FgRed;
|
||||
return console_colors_1.ccol.FgRed;
|
||||
case "warning":
|
||||
return ccol.FgYellow;
|
||||
return console_colors_1.ccol.FgYellow;
|
||||
default:
|
||||
return ccol.FgGreen;
|
||||
return console_colors_1.ccol.FgGreen;
|
||||
}
|
||||
})();
|
||||
let logTxt = `${logType}DEBUG${ccol.Reset}:::`;
|
||||
let logTxt = `${logType}DEBUG${console_colors_1.ccol.Reset}:::`;
|
||||
const date = new Date();
|
||||
const time = date.toLocaleTimeString("en-US", {
|
||||
hour: "numeric",
|
||||
@@ -21,10 +24,10 @@ export default function debugLog({ log, label, title, type, addTime }) {
|
||||
});
|
||||
const logTime = `${date.toLocaleDateString()}][${time}`;
|
||||
if (addTime)
|
||||
logTxt = `${ccol.BgWhite}[${logTime}]${ccol.Reset} ` + logTxt;
|
||||
logTxt = `${console_colors_1.ccol.BgWhite}[${logTime}]${console_colors_1.ccol.Reset} ` + logTxt;
|
||||
if (title)
|
||||
logTxt += `${ccol.FgBlue}${title}${ccol.Reset}::`;
|
||||
logTxt += `${console_colors_1.ccol.FgBlue}${title}${console_colors_1.ccol.Reset}::`;
|
||||
if (label)
|
||||
logTxt += `${ccol.FgWhite}${ccol.Bright}${label}${ccol.Reset} =>`;
|
||||
logTxt += `${console_colors_1.ccol.FgWhite}${console_colors_1.ccol.Bright}${label}${console_colors_1.ccol.Reset} =>`;
|
||||
console.log(logTxt, log);
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
export default function normalizeText(txt) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = normalizeText;
|
||||
function normalizeText(txt) {
|
||||
return txt
|
||||
.replace(/\n|\r|\n\r/g, " ")
|
||||
.replace(/ {2,}/g, " ")
|
||||
|
||||
+4
-1
@@ -1,3 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = numberfy;
|
||||
/**
|
||||
* # Get Number from any input
|
||||
* @example
|
||||
@@ -7,7 +10,7 @@
|
||||
* numberfy("123.456", 0) // 123
|
||||
* numberfy("123.456", 3) // 123.456
|
||||
*/
|
||||
export default function numberfy(num, decimals) {
|
||||
function numberfy(num, decimals) {
|
||||
var _a;
|
||||
try {
|
||||
const numberString = String(num)
|
||||
|
||||
+10
-4
@@ -1,9 +1,15 @@
|
||||
import fs from "fs";
|
||||
export default function parseEnv(
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = parseEnv;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
function parseEnv(
|
||||
/** The file path to the env. Eg. /app/.env */ envFile) {
|
||||
if (!fs.existsSync(envFile))
|
||||
if (!fs_1.default.existsSync(envFile))
|
||||
return undefined;
|
||||
const envTextContent = fs.readFileSync(envFile, "utf-8");
|
||||
const envTextContent = fs_1.default.readFileSync(envFile, "utf-8");
|
||||
const envLines = envTextContent
|
||||
.split("\n")
|
||||
.map((ln) => ln.trim())
|
||||
|
||||
+12
-6
@@ -1,13 +1,19 @@
|
||||
import _ from "lodash";
|
||||
import defaultFieldsRegexp from "../functions/dsql/default-fields-regexp";
|
||||
export default function purgeDefaultFields(entry) {
|
||||
const newEntry = _.cloneDeep(entry);
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = purgeDefaultFields;
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
const default_fields_regexp_1 = __importDefault(require("../functions/dsql/default-fields-regexp"));
|
||||
function purgeDefaultFields(entry) {
|
||||
const newEntry = lodash_1.default.cloneDeep(entry);
|
||||
if (Array.isArray(newEntry)) {
|
||||
const entryKeys = Object.keys(newEntry[0]);
|
||||
for (let i = 0; i < newEntry.length; i++) {
|
||||
for (let j = 0; j < entryKeys.length; j++) {
|
||||
const entryKey = entryKeys[j];
|
||||
if (defaultFieldsRegexp.test(entryKey)) {
|
||||
if (default_fields_regexp_1.default.test(entryKey)) {
|
||||
delete newEntry[i][entryKey];
|
||||
}
|
||||
}
|
||||
@@ -18,7 +24,7 @@ export default function purgeDefaultFields(entry) {
|
||||
const entryKeys = Object.keys(newEntry);
|
||||
for (let i = 0; i < entryKeys.length; i++) {
|
||||
const entryKey = entryKeys[i];
|
||||
if (defaultFieldsRegexp.test(entryKey)) {
|
||||
if (default_fields_regexp_1.default.test(entryKey)) {
|
||||
delete newEntry[entryKey];
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,9 +1,12 @@
|
||||
"use strict";
|
||||
// @ts-check
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = serializeCookies;
|
||||
/**
|
||||
* # Serialize Cookies
|
||||
* @description Convert cookie object to string array
|
||||
*/
|
||||
export default function serializeCookies({ cookies, }) {
|
||||
function serializeCookies({ cookies, }) {
|
||||
let cookiesStringsArray = [];
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookieObject = cookies[i];
|
||||
|
||||
+9
-3
@@ -1,8 +1,14 @@
|
||||
import EJSON from "./ejson";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = serializeQuery;
|
||||
const ejson_1 = __importDefault(require("./ejson"));
|
||||
/**
|
||||
* # Serialize Query
|
||||
*/
|
||||
export default function serializeQuery(query) {
|
||||
function serializeQuery(query) {
|
||||
let str = "?";
|
||||
if (typeof query !== "object") {
|
||||
console.log("Invalid Query type");
|
||||
@@ -23,7 +29,7 @@ export default function serializeQuery(query) {
|
||||
return;
|
||||
const value = query[key];
|
||||
if (typeof value === "object") {
|
||||
const jsonStr = EJSON.stringify(value);
|
||||
const jsonStr = ejson_1.default.stringify(value);
|
||||
queryArr.push(`${key}=${encodeURIComponent(String(jsonStr))}`);
|
||||
}
|
||||
else if (typeof value === "string" || typeof value === "number") {
|
||||
|
||||
+14
-8
@@ -1,11 +1,17 @@
|
||||
import { execSync } from "child_process";
|
||||
import grabInstanceGlobalNetWorkName from "./grab-instance-global-network-name";
|
||||
import grabIPAddresses from "./backend/names/grab-ip-addresses";
|
||||
export default function setupGlobalNetwork() {
|
||||
const globalNetworkName = grabInstanceGlobalNetWorkName();
|
||||
const { globalIPPrefix } = grabIPAddresses();
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = setupGlobalNetwork;
|
||||
const child_process_1 = require("child_process");
|
||||
const grab_instance_global_network_name_1 = __importDefault(require("./grab-instance-global-network-name"));
|
||||
const grab_ip_addresses_1 = __importDefault(require("./backend/names/grab-ip-addresses"));
|
||||
function setupGlobalNetwork() {
|
||||
const globalNetworkName = (0, grab_instance_global_network_name_1.default)();
|
||||
const { globalIPPrefix } = (0, grab_ip_addresses_1.default)();
|
||||
try {
|
||||
execSync(`docker network rm ${globalNetworkName}`, {});
|
||||
(0, child_process_1.execSync)(`docker network rm ${globalNetworkName}`, {});
|
||||
}
|
||||
catch (error) { }
|
||||
let newNtwkCmd = `docker network create`;
|
||||
@@ -13,5 +19,5 @@ export default function setupGlobalNetwork() {
|
||||
newNtwkCmd += ` --subnet ${globalIPPrefix}.0/24`;
|
||||
newNtwkCmd += ` --gateway ${globalIPPrefix}.1`;
|
||||
newNtwkCmd += ` ${globalNetworkName}`;
|
||||
execSync(newNtwkCmd);
|
||||
(0, child_process_1.execSync)(newNtwkCmd);
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
export default function slugToNormalText(str) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = slugToNormalText;
|
||||
function slugToNormalText(str) {
|
||||
if (!str)
|
||||
return "";
|
||||
return str
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = slugToCamelTitle;
|
||||
/**
|
||||
* # Slug to Camel case Title
|
||||
*/
|
||||
export default function slugToCamelTitle(text) {
|
||||
function slugToCamelTitle(text) {
|
||||
if (text) {
|
||||
let addArray = text.split("-").filter((item) => item !== "");
|
||||
let camelArray = addArray.map((item) => {
|
||||
|
||||
Vendored
+4
-1
@@ -1,3 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = slugify;
|
||||
/**
|
||||
* # Return the slug of a string
|
||||
*
|
||||
@@ -6,7 +9,7 @@
|
||||
* slugify("Yes!") // "yes"
|
||||
* slugify("Hello!!! World!") // "hello-world"
|
||||
*/
|
||||
export default function slugify(str, divider, allowTrailingDash) {
|
||||
function slugify(str, divider, allowTrailingDash) {
|
||||
const finalSlugDivider = divider || "-";
|
||||
try {
|
||||
if (!str)
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
export default function sqlEqualityParser(eq) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = sqlEqualityParser;
|
||||
function sqlEqualityParser(eq) {
|
||||
switch (eq) {
|
||||
case "EQUAL":
|
||||
return "=";
|
||||
|
||||
+4
-1
@@ -1,8 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = trimSql;
|
||||
/**
|
||||
* # Trim SQL
|
||||
* @description Remove Returns and miltiple spaces from SQL Query
|
||||
*/
|
||||
export default function trimSql(sql) {
|
||||
function trimSql(sql) {
|
||||
return sql
|
||||
.replace(/\n|\r|\n\r|\r\n/gm, " ")
|
||||
.replace(/ {2,}/g, " ")
|
||||
|
||||
+11
-5
@@ -1,5 +1,11 @@
|
||||
import slugify from "./slugify";
|
||||
export default function uniqueByKey(arr, key) {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = uniqueByKey;
|
||||
const slugify_1 = __importDefault(require("./slugify"));
|
||||
function uniqueByKey(arr, key) {
|
||||
let newArray = [];
|
||||
let uniqueValues = [];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
@@ -9,13 +15,13 @@ export default function uniqueByKey(arr, key) {
|
||||
const targetVals = [];
|
||||
for (let k = 0; k < key.length; k++) {
|
||||
const ky = key[k];
|
||||
const targetValuek = slugify(String(item[ky]));
|
||||
const targetValuek = (0, slugify_1.default)(String(item[ky]));
|
||||
targetVals.push(targetValuek);
|
||||
}
|
||||
targetValue = slugify(targetVals.join(","));
|
||||
targetValue = (0, slugify_1.default)(targetVals.join(","));
|
||||
}
|
||||
else {
|
||||
targetValue = slugify(String(item[key]));
|
||||
targetValue = (0, slugify_1.default)(String(item[key]));
|
||||
}
|
||||
if (!targetValue)
|
||||
continue;
|
||||
|
||||
+12
-6
@@ -1,8 +1,14 @@
|
||||
import fs from "fs";
|
||||
import grabDirNames from "./backend/names/grab-dir-names";
|
||||
export default function updateGrastateToLatest() {
|
||||
const { mainDbGrastateDatFile } = grabDirNames();
|
||||
const existingGrastateDatFile = fs.readFileSync(mainDbGrastateDatFile, "utf-8");
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = updateGrastateToLatest;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const grab_dir_names_1 = __importDefault(require("./backend/names/grab-dir-names"));
|
||||
function updateGrastateToLatest() {
|
||||
const { mainDbGrastateDatFile } = (0, grab_dir_names_1.default)();
|
||||
const existingGrastateDatFile = fs_1.default.readFileSync(mainDbGrastateDatFile, "utf-8");
|
||||
const newGrastateDatFile = existingGrastateDatFile.replace(/safe_to_bootstrap: .*/, `safe_to_bootstrap: 1`);
|
||||
fs.writeFileSync(mainDbGrastateDatFile, newGrastateDatFile, "utf-8");
|
||||
fs_1.default.writeFileSync(mainDbGrastateDatFile, newGrastateDatFile, "utf-8");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user