This commit is contained in:
Benjamin Toby
2025-07-05 14:59:30 +01:00
parent 6e334c2525
commit 7e8bb37c09
526 changed files with 17560 additions and 11386 deletions
@@ -0,0 +1,10 @@
import { SiteConfig } from "../../../types";
type Params = {
userId?: string | number;
};
type Return = {
appConfig: SiteConfig;
userConfig: SiteConfig | null;
};
export default function grabConfig(params?: Params): Return;
export {};
+24
View File
@@ -0,0 +1,24 @@
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({
userId: params === null || params === void 0 ? void 0 : params.userId,
});
const appConfigJSON = envsub(fs.readFileSync(appConfigJSONFile, "utf-8"));
const appConfig = EJSON.parse(appConfigJSON);
if (!userConfigJSONFilePath) {
return { appConfig, userConfig: null };
}
if (!fs.existsSync(userConfigJSONFilePath)) {
fs.writeFileSync(userConfigJSONFilePath, JSON.stringify({
main: {},
}), "utf-8");
}
const userConfigJSON = envsub(fs.readFileSync(userConfigJSONFilePath, "utf-8"));
const userConfig = (EJSON.parse(userConfigJSON) || {
main: {},
});
return { appConfig, userConfig };
}
@@ -0,0 +1,10 @@
import { SiteConfigMain } from "../../../types";
type Params = {
userId?: string | number;
};
type Return = {
appMainConfig: SiteConfigMain;
userMainConfig?: SiteConfigMain;
};
export default function grabMainConfig(params?: Params): Return;
export {};
@@ -0,0 +1,6 @@
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 });
return { appMainConfig: appConfig.main, userMainConfig: userConfig === null || userConfig === void 0 ? void 0 : userConfig.main };
}
@@ -0,0 +1,11 @@
import { SiteConfig } from "../../../types";
type Params = {
userId?: string | number;
newConfig?: SiteConfig;
};
type Return = {
success?: boolean;
msg?: string;
};
export default function updateUserConfig({ newConfig, userId, }: Params): Return;
export {};
@@ -0,0 +1,25 @@
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, }) {
if (!userId || !newConfig) {
return {
success: false,
msg: `UserID or newConfig not provided`,
};
}
const { userConfigJSONFilePath } = grabDirNames({
userId,
});
if (!userConfigJSONFilePath || !fs.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");
return { success: true };
}
@@ -1,13 +1,7 @@
"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)
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)
? "'" +
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
"'"
@@ -19,6 +13,6 @@ function exportMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariad
let execSyncOptions = {
encoding: "utf-8",
};
const dumpDb = (0, child_process_1.execSync)(cmd, execSyncOptions);
const dumpDb = execSync(cmd, execSyncOptions);
return dumpDb;
}
+20 -37
View File
@@ -1,42 +1,25 @@
"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"));
import grabDSQLConnection from "../../grab-dsql-connection";
/**
* # DSQL user read-only DB handler
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
*/
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());
}
});
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());
}
}
@@ -1,38 +1,21 @@
"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"));
import connDbHandler from "../../db/conn-db-handler";
import grabDSQLConnection from "../../grab-dsql-connection";
/**
* # DSQL user read-only DB handler
*/
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();
}
});
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();
}
}
@@ -1,39 +1,22 @@
"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"));
import grabDSQLConnection from "../../grab-dsql-connection";
/**
* # DSQL user read-only DB handler
*/
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());
}
});
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());
}
}
@@ -1,16 +1,10 @@
"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"));
import grabDSQLConnection from "../../grab-dsql-connection";
/**
* # DSQL user read-only DB handler
*/
function NO_DB_HANDLER(...args) {
export default function NO_DB_HANDLER(...args) {
var _a;
const CONNECTION = (0, grab_dsql_connection_1.default)();
const CONNECTION = grabDSQLConnection();
try {
return new Promise((resolve, reject) => {
CONNECTION.query(...args)
@@ -1,16 +1,10 @@
"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"));
import grabDSQLConnection from "../../grab-dsql-connection";
/**
* # Root DB handler
*/
function ROOT_DB_HANDLER(...args) {
export default function ROOT_DB_HANDLER(...args) {
var _a;
const CONNECTION = (0, grab_dsql_connection_1.default)();
const CONNECTION = grabDSQLConnection();
try {
return new Promise((resolve, reject) => {
CONNECTION.query(...args)
+4 -10
View File
@@ -1,25 +1,19 @@
"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"));
import fs from "fs";
/**
* # Grall SSL
*/
function grabDbSSL() {
export default 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_1.default.existsSync(caFilePath)) {
if (!fs.existsSync(caFilePath)) {
console.log(`${caFilePath} does not exist`);
return undefined;
}
return {
ca: fs_1.default.readFileSync(`${SSL_DIR}/ca-cert.pem`),
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
// key: fs.readFileSync(`${SSL_DIR}/client-key.pem`),
// cert: fs.readFileSync(`${SSL_DIR}/client-cert.pem`),
rejectUnauthorized: false,
+19 -36
View File
@@ -1,37 +1,20 @@
"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;
});
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;
}
@@ -1,8 +0,0 @@
import { DATASQUIREL_LoggedInUser, UserType } from "../../../types";
type Param = {
user?: DATASQUIREL_LoggedInUser | UserType;
userId?: string | number | null;
dbSlug?: string;
};
export default function grabUserDbFullName({ dbSlug, user, userId }: Param): string;
export {};
@@ -1,12 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabUserDbFullName;
function grabUserDbFullName({ dbSlug, user, userId }) {
const finalUserId = (user === null || user === void 0 ? void 0 : user.id) || userId;
if (!finalUserId || !dbSlug)
throw new Error(`Couldn't grab full DB name. Missing parameters finalUserId || dbSlug`);
if (dbSlug.match(/[^a-zA-Z0-9-_]/)) {
throw new Error(`Invalid Database slug`);
}
return `datasquirel_user_${finalUserId}_${dbSlug}`;
}
+32 -3
View File
@@ -3,17 +3,19 @@ type Param = {
user?: DATASQUIREL_LoggedInUser | UserType;
userId?: string | number | null;
appDir?: string;
dataDir?: string;
};
export default function grabDirNames(param?: Param): {
appDir: string;
schemasDir: string;
userDirPath: string | undefined;
privateDataDir: string;
oldSchemasDir: string;
userConfigJSONFilePath: string | undefined;
mainShemaJSONFilePath: string;
mainDbTypeDefFile: string;
tempDirName: string;
defaultTableFieldsJSONFilePath: string;
usersSchemaDir: string;
targetUserSchemaDir: string | undefined;
targetUserPrivateDir: string | undefined;
userSchemaMainJSONFilePath: string | undefined;
userPrivateMediaDir: string | undefined;
userPrivateExportsDir: string | undefined;
@@ -36,5 +38,32 @@ export default function grabDirNames(param?: Param): {
testEnvFile: string;
userPublicMediaDir: string | undefined;
userTempSQLFilePath: string | undefined;
STATIC_ROOT: string;
appConfigJSONFile: string;
appConfigDir: string;
mariadbMainConfigDir: string;
mariadbMainConfigFile: string;
maxscaleConfigDir: string;
mariadbReplicaConfigDir: string;
DATA_DIR: string;
publicDir: string;
publicSSLDir: string;
appSSLDir: string;
maxscaleConfigFile: string;
mariadbReplicaConfigFile: string;
mainSSLDir: string;
mainDbDataDir: string;
replica1DbDataDir: string;
galeraConfigFile: string;
galeraReplicaConfigFile: string;
dbDockerComposeFile: string;
dbDockerComposeFileAlt: string;
mainDbGrastateDatFile: string;
appSchemaJSONFile: string;
mainBackupDir: string;
userBackupDir: string | undefined;
sqlBackupDirName: string;
schemasBackupDirName: string;
userMainShemaJSONFilePath: string | undefined;
};
export {};
+115 -49
View File
@@ -1,86 +1,125 @@
"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) {
import path from "path";
export default function grabDirNames(param) {
var _a;
const appDir = (param === null || param === void 0 ? void 0 : param.appDir) || process.env.DSQL_APP_DIR;
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR || "/static";
const DATA_DIR = (param === null || param === void 0 ? void 0 : param.dataDir) || process.env.DSQL_DATA_DIR || "/data";
const finalUserId = ((_a = param === null || param === void 0 ? void 0 : param.user) === null || _a === void 0 ? void 0 : _a.id) || (param === null || param === void 0 ? void 0 : param.userId);
const publicImagesDir = path_1.default.join(STATIC_ROOT, `images`);
if (!appDir)
throw new Error("Please provide the `DSQL_APP_DIR` env variable.");
const schemasDir = process.env.DSQL_DB_SCHEMA_DIR ||
path_1.default.join(appDir, "jsonData", "dbSchemas");
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");
/**
* # 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");
/**
* # Schema Dir names
* @description
*/
const oldSchemasDir = path.join(appDir, "jsonData", "dbSchemas");
const appSchemaJSONFile = path.join(oldSchemasDir, "1.json");
const tempDirName = ".tmp";
if (!schemasDir)
const appConfigDir = path.join(appDir, "jsonData", "config");
const appConfigJSONFile = path.join(appConfigDir, "app-config.json");
if (!privateDataDir)
throw new Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");
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(schemasDir, `main.json`);
const defaultTableFieldsJSONFilePath = path_1.default.join(pakageSharedDir, `data/defaultFields.json`);
const usersSchemaDir = path_1.default.join(schemasDir, `users`);
const targetUserSchemaDir = finalUserId
? path_1.default.join(usersSchemaDir, `user-${finalUserId}`)
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 targetUserPrivateDir = finalUserId
? path.join(usersSchemaDir, `user-${finalUserId}`)
: undefined;
const userTempSQLFilePath = targetUserSchemaDir
? path_1.default.join(targetUserSchemaDir, `tmp.sql`)
const userTempSQLFilePath = targetUserPrivateDir
? path.join(targetUserPrivateDir, `tmp.sql`)
: undefined;
const userDirPath = finalUserId
? path_1.default.join(usersSchemaDir, `user-${finalUserId}`)
const userMainShemaJSONFilePath = targetUserPrivateDir
? path.join(targetUserPrivateDir, `main.json`)
: undefined;
const userSchemaMainJSONFilePath = userDirPath
? path_1.default.join(userDirPath, `main.json`)
const userConfigJSONFilePath = targetUserPrivateDir
? path.join(targetUserPrivateDir, `config.json`)
: undefined;
const userPrivateMediaDir = userDirPath
? path_1.default.join(userDirPath, `media`)
const userSchemaMainJSONFilePath = targetUserPrivateDir
? path.join(targetUserPrivateDir, `main.json`)
: undefined;
const userPrivateExportsDir = userDirPath
? path_1.default.join(userDirPath, `export`)
const userPrivateMediaDir = targetUserPrivateDir
? path.join(targetUserPrivateDir, `media`)
: undefined;
const userPrivateExportsDir = targetUserPrivateDir
? path.join(targetUserPrivateDir, `export`)
: undefined;
const userPrivateSQLExportsDir = userPrivateExportsDir
? path_1.default.join(userPrivateExportsDir, `sql`)
? path.join(userPrivateExportsDir, `sql`)
: undefined;
const userPrivateTempSQLExportsDir = userPrivateSQLExportsDir
? path_1.default.join(userPrivateSQLExportsDir, tempDirName)
? path.join(userPrivateSQLExportsDir, tempDirName)
: undefined;
const userPrivateTempJSONSchemaFilePath = userPrivateTempSQLExportsDir
? path_1.default.join(userPrivateTempSQLExportsDir, `schema.json`)
? path.join(userPrivateTempSQLExportsDir, `schema.json`)
: undefined;
const userPrivateDbExportZipFileName = `db-export.zip`;
const userPrivateDbExportZipFilePath = userPrivateSQLExportsDir
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
? path.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
: undefined;
const userPublicMediaDir = finalUserId
? path_1.default.join(publicImagesDir, `user-images/user-${finalUserId}`)
? path.join(publicImagesDir, `user-images/user-${finalUserId}`)
: undefined;
const userPrivateDbImportZipFileName = `db-export.zip`;
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
? path.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
: undefined;
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 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");
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");
/**
* # Backup Dir names
* @description
*/
const mainBackupDir = path.join(DATA_DIR, "backups");
const userBackupDir = targetUserPrivateDir
? path.join(targetUserPrivateDir, `backups`)
: undefined;
const sqlBackupDirName = `sql`;
const schemasBackupDirName = `schema`;
return {
appDir,
schemasDir,
userDirPath,
privateDataDir,
oldSchemasDir,
userConfigJSONFilePath,
mainShemaJSONFilePath,
mainDbTypeDefFile,
tempDirName,
defaultTableFieldsJSONFilePath,
usersSchemaDir,
targetUserSchemaDir,
targetUserPrivateDir,
userSchemaMainJSONFilePath,
userPrivateMediaDir,
userPrivateExportsDir,
@@ -103,5 +142,32 @@ function grabDirNames(param) {
testEnvFile,
userPublicMediaDir,
userTempSQLFilePath,
STATIC_ROOT,
appConfigJSONFile,
appConfigDir,
mariadbMainConfigDir,
mariadbMainConfigFile,
maxscaleConfigDir,
mariadbReplicaConfigDir,
DATA_DIR,
publicDir,
publicSSLDir,
appSSLDir,
maxscaleConfigFile,
mariadbReplicaConfigFile,
mainSSLDir,
mainDbDataDir,
replica1DbDataDir,
galeraConfigFile,
galeraReplicaConfigFile,
dbDockerComposeFile,
dbDockerComposeFileAlt,
mainDbGrastateDatFile,
appSchemaJSONFile,
mainBackupDir,
userBackupDir,
sqlBackupDirName,
schemasBackupDirName,
userMainShemaJSONFilePath,
};
}
@@ -0,0 +1,6 @@
export default function grabIPAddresses(): {
webAppIP: string;
appCronIP: string;
maxScaleIP: string;
globalIPPrefix: string;
};
@@ -0,0 +1,9 @@
import grabDockerResourceIPNumbers from "../../grab-docker-resource-ip-numbers";
export default function grabIPAddresses() {
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
const { cron, db, maxscale, postDbSetup, web } = grabDockerResourceIPNumbers();
const webAppIP = `${globalIPPrefix}.${web}`;
const appCronIP = `${globalIPPrefix}.${cron}`;
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
return { webAppIP, appCronIP, maxScaleIP, globalIPPrefix };
}
@@ -1,7 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = replaceDatasquirelDbName;
function replaceDatasquirelDbName({ str, userId, }) {
export default function replaceDatasquirelDbName({ str, userId, }) {
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
const userNameRegex = new RegExp(`${dbNamePrefix}\\d+_`, "g");
const newPrefix = `${dbNamePrefix}${userId}_`;
+1 -4
View File
@@ -1,6 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = parseCookies;
/**
* Parse request cookies
* ===================================================
@@ -8,7 +5,7 @@ exports.default = parseCookies;
* @description This function takes in a request object and
* returns the cookies as a JS object
*/
function parseCookies({ request, cookieString, }) {
export default function parseCookies({ request, cookieString, }) {
var _a;
try {
/** @type {string | undefined} */