This commit is contained in:
Benjamin Toby
2025-07-07 09:14:37 +01:00
parent 6acf0f2cd6
commit ccb5605b58
30 changed files with 292 additions and 166 deletions
+1 -1
View File
@@ -2,4 +2,4 @@ import { APILoginFunctionReturn, LoginUserParam } from "../../types";
/**
* # Login A user
*/
export default function loginUser({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, }: LoginUserParam): Promise<APILoginFunctionReturn>;
export default function loginUser({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, useLocal, }: LoginUserParam): Promise<APILoginFunctionReturn>;
+2 -15
View File
@@ -13,8 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = loginUser;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
@@ -26,7 +24,7 @@ const grab_cookie_expirt_date_1 = __importDefault(require("../../utils/grab-cook
* # Login A user
*/
function loginUser(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, }) {
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, apiUserID, skipWriteAuthFile, dbUserId, debug, cleanupTokens, secureCookie, request, useLocal, }) {
var _b, _c, _d;
const grabedHostNames = (0, grab_host_names_1.default)({ userId: user_id || apiUserID });
const { host, port, scheme } = grabedHostNames;
@@ -82,18 +80,7 @@ function loginUser(_a) {
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
if (useLocal) {
httpResponse = yield (0, api_login_1.default)({
database: database || process.env.DSQL_DB_NAME || "",
email: payload.email,
+2 -1
View File
@@ -2,7 +2,7 @@ import http from "http";
import { SendOneTimeCodeEmailResponse } from "../../types";
type Param = {
key?: string;
database?: string;
database: string;
email: string;
temp_code_field_name?: string;
response?: http.ServerResponse & {
@@ -15,6 +15,7 @@ type Param = {
sender?: string;
user_id?: boolean;
extraCookies?: import("../../types").CookieObject[];
useLocal?: boolean;
};
/**
* # Send Email Code to a User
+4 -22
View File
@@ -13,8 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = sendEmailCode;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_send_email_code_1 = __importDefault(require("../../functions/api/users/api-send-email-code"));
/**
@@ -22,7 +20,7 @@ const api_send_email_code_1 = __importDefault(require("../../functions/api/users
*/
function sendEmailCode(params) {
return __awaiter(this, void 0, void 0, function* () {
const { key, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, user_id, response, extraCookies, } = params;
const { key, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, user_id, response, extraCookies, useLocal, } = params;
const grabedHostNames = (0, grab_host_names_1.default)();
const { host, port, scheme } = grabedHostNames;
const defaultTempLoginFieldName = "temp_login_code";
@@ -30,26 +28,10 @@ function sendEmailCode(params) {
? temp_code_field_name
: defaultTempLoginFieldName;
const emailHtml = `<p>Please use this code to login</p>\n<h2>{{code}}</h2>\n<p>Please note that this code expires after 15 minutes</p>`;
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs_1.default.readFileSync(localDbSchemaPath, "utf8"));
}
catch (error) { }
console.log("useLocal", useLocal);
if (useLocal) {
return yield (0, api_send_email_code_1.default)({
database: DSQL_DB_NAME,
database,
email,
email_login_field: emailLoginTempCodeFieldName,
html: emailHtml,
+5 -1
View File
@@ -15,9 +15,13 @@ type Param = {
debug?: boolean;
secureCookie?: boolean;
loginOnly?: boolean;
/**
* Login without calling external API
*/
forceLocal?: boolean;
};
/**
* # SERVER FUNCTION: Login with google Function
*/
export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, }: Param): Promise<APILoginFunctionReturn>;
export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, forceLocal, }: Param): Promise<APILoginFunctionReturn>;
export {};
+3 -12
View File
@@ -23,7 +23,7 @@ const grab_cookie_expirt_date_1 = __importDefault(require("../../../utils/grab-c
* # SERVER FUNCTION: Login with google Function
*/
function googleAuth(_a) {
return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, }) {
return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, debug, secureCookie, loginOnly, forceLocal, }) {
var _b;
const grabedHostNames = (0, grab_host_names_1.default)({
userId: apiUserID || process.env.DSQL_API_USER_ID,
@@ -66,17 +66,7 @@ function googleAuth(_a) {
let httpResponse = {
success: false,
};
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_DB_HOST, DSQL_DB_USERNAME, DSQL_DB_PASSWORD, DSQL_DB_NAME } = process.env;
if ((DSQL_DB_HOST === null || DSQL_DB_HOST === void 0 ? void 0 : DSQL_DB_HOST.match(/./)) &&
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
if (forceLocal) {
if (debug) {
console.log(`Google login with Local Paradigm ...`);
}
@@ -85,6 +75,7 @@ function googleAuth(_a) {
additionalFields,
additionalData,
debug,
loginOnly,
});
}
else {
+7 -5
View File
@@ -710,7 +710,7 @@ export interface ImageObjectType {
export interface FileObjectType {
fileName?: string;
private?: boolean;
fileType?: string;
fileType?: (typeof FileMimeTypes)[number];
fileSize?: number;
fileBase64?: string;
fileBase64Full?: string;
@@ -1420,12 +1420,12 @@ export type DatasquirelWindowEventPayloadType = {
* # Docker Compose Types
*/
export type DockerCompose = {
services: DockerComposeServices;
services: DockerComposeServicesType;
networks: DockerComposeNetworks;
name: string;
};
export declare const DockerComposeServices: readonly ["setup", "cron", "reverse-proxy", "webapp", "websocket", "static", "db", "maxscale", "post-db-setup", "web-app-post-db-setup", "post-replica-db-setup", "db-replica-1", "db-replica-2", "db-cron", "web-app-post-db-setup"];
export type DockerComposeServices = {
export type DockerComposeServicesType = {
[key in (typeof DockerComposeServices)[number]]: DockerComposeServiceWithBuildObject;
};
export type DockerComposeNetworks = {
@@ -1448,6 +1448,7 @@ export type DockerComposeServiceWithBuildObject = {
hostname: string;
volumes: string[];
environment: string[];
ports?: string[];
networks?: DockerComposeServiceNetworkObject;
restart?: string;
depends_on?: {
@@ -1501,7 +1502,7 @@ export type MediaUploadDataType = ImageObjectType & FileObjectType & {
overwrite?: boolean;
};
export declare const ImageMimeTypes: (keyof sharp.FormatEnum)[];
export declare const FileMimeTypes: readonly ["pdf", "csv", "json", "sql", "xlsx", "txt", "zip", "xz", "yaml", "yml"];
export declare const FileMimeTypes: readonly ["pdf", "csv", "json", "sql", "xlsx", "txt", "zip", "xz", "tar.xz", "yaml", "yml"];
export declare const VideoMimeTypes: readonly ["mp4", "wav"];
export declare const CurrentlyEditedFieldActions: readonly ["edit-field", "edit-index", "delete-field", "delete-index", "new-field", "new-index", "move-up", "move-down", "complete"];
export type CurrentlyEditedTableSchemaType = {
@@ -1576,6 +1577,7 @@ export type LoginUserParam = {
dbUserId?: string | number;
cleanupTokens?: boolean;
secureCookie?: boolean;
useLocal?: boolean;
};
export declare const UserSelectFields: readonly [{
readonly field: "first_name";
@@ -1611,7 +1613,7 @@ export declare const InvitedUserSelectFields: readonly [{
readonly alias: "invited_user_last_name";
}, {
readonly field: "email";
readonly alias: "invited_user_email";
readonly alias: "invited_user_email_addr";
}, {
readonly field: "image_thumbnail";
readonly alias: "invited_user_image_thumbnail";
+2 -1
View File
@@ -144,6 +144,7 @@ exports.FileMimeTypes = [
"txt",
"zip",
"xz",
"tar.xz",
"yaml",
"yml",
];
@@ -221,7 +222,7 @@ exports.InvitedUserSelectFields = [
},
{
field: "email",
alias: "invited_user_email",
alias: "invited_user_email_addr",
},
{
field: "image_thumbnail",
+23 -3
View File
@@ -29,13 +29,14 @@ export default function grabDirNames(param?: Param): {
dbNginxLoadBalancerConfigFile: string;
dockerComposeFile: string;
dockerComposeFileAlt: string;
testDockerComposeFile: string;
testDockerComposeFileAlt: string;
dsqlDockerComposeFile: string;
dsqlDockerComposeFileAlt: string;
extraDockerComposeFile: string;
extraDockerComposeFileAlt: string;
siteSetupFile: string;
envFile: string;
testEnvFile: string;
dsqlEnvFileName: string;
dsqlEnvFile: string;
userPublicMediaDir: string | undefined;
userTempSQLFilePath: string | undefined;
STATIC_ROOT: string;
@@ -69,5 +70,24 @@ export default function grabDirNames(param?: Param): {
mainDBSSLDir: string;
replica1DBSSLDir: string;
replica2DBSSLDir: string;
staticConfigDir: string;
staticNGINXConfigFile: string;
mainReverseProxyConfigDir: string;
mainReverseProxyConfigFile: string;
mainReverseProxyTemplatesDir: string;
mainReverseProxyTemplatesDefaultFile: string;
dsqlDockerComposeFileName: string;
dsqlDockerComposeFileNameAlt: string;
distroDirName: "distro";
distroAppDirName: "dsql-app";
distroDataDirName: "dsql-data";
distroCommunityName: "dsql-community";
distroCommunityExportTarName: "dsql-community.tar.xz";
distroProName: "dsql-pro";
distroProExportTarName: "dsql-pro.tar.xz";
distroEnterpriseName: "dsql-enterprise";
distroEnterpriseExportTarName: "dsql-enterprise.tar.xz";
communityDistroTempDir: string;
communityDistroDir: string;
};
export {};
+49 -6
View File
@@ -15,6 +15,12 @@ function grabDirNames(param) {
if (!DATA_DIR)
throw new Error("Please provide the `DATA_DIR` env variable.");
const STATIC_ROOT = path_1.default.join(DATA_DIR, "static");
const staticConfigDir = path_1.default.join(DATA_DIR, "static-config");
const staticNGINXConfigFile = path_1.default.join(staticConfigDir, "default.conf");
const mainReverseProxyConfigDir = path_1.default.join(DATA_DIR, "reverse-proxy");
const mainReverseProxyConfigFile = path_1.default.join(mainReverseProxyConfigDir, "default.conf");
const mainReverseProxyTemplatesDir = path_1.default.join(mainReverseProxyConfigDir, "templates");
const mainReverseProxyTemplatesDefaultFile = path_1.default.join(mainReverseProxyTemplatesDir, "default.conf.template");
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");
@@ -100,15 +106,18 @@ function grabDirNames(param) {
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 dsqlDockerComposeFileName = "dsql.docker-compose.yml";
const dsqlDockerComposeFileNameAlt = "dsql.docker-compose.yaml";
const dsqlDockerComposeFile = path_1.default.join(appDir, dsqlDockerComposeFileName);
const dsqlDockerComposeFileAlt = path_1.default.join(appDir, dsqlDockerComposeFileNameAlt);
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");
const dsqlEnvFileName = "dsql.env";
const dsqlEnvFile = path_1.default.join(appDir, dsqlEnvFileName);
/**
* # Backup Dir names
* @description
@@ -119,6 +128,20 @@ function grabDirNames(param) {
: undefined;
const sqlBackupDirName = `sql`;
const schemasBackupDirName = `schema`;
/**
* # Distribution Names
*/
const distroDirName = "distro";
const distroAppDirName = "dsql-app";
const distroDataDirName = "dsql-data";
const distroCommunityName = "dsql-community";
const distroCommunityExportTarName = `${distroCommunityName}.tar.xz`;
const distroProName = "dsql-pro";
const distroProExportTarName = `${distroProName}.tar.xz`;
const distroEnterpriseName = "dsql-enterprise";
const distroEnterpriseExportTarName = `${distroEnterpriseName}.tar.xz`;
const communityDistroTempDir = path_1.default.resolve(appDir, "build", "community", ".tmp");
const communityDistroDir = path_1.default.resolve(communityDistroTempDir, distroDirName);
return {
appDir,
privateDataDir,
@@ -143,13 +166,14 @@ function grabDirNames(param) {
dbNginxLoadBalancerConfigFile,
dockerComposeFile,
dockerComposeFileAlt,
testDockerComposeFile,
testDockerComposeFileAlt,
dsqlDockerComposeFile,
dsqlDockerComposeFileAlt,
extraDockerComposeFile,
extraDockerComposeFileAlt,
siteSetupFile,
envFile,
testEnvFile,
dsqlEnvFileName,
dsqlEnvFile,
userPublicMediaDir,
userTempSQLFilePath,
STATIC_ROOT,
@@ -183,5 +207,24 @@ function grabDirNames(param) {
mainDBSSLDir,
replica1DBSSLDir,
replica2DBSSLDir,
staticConfigDir,
staticNGINXConfigFile,
mainReverseProxyConfigDir,
mainReverseProxyConfigFile,
mainReverseProxyTemplatesDir,
mainReverseProxyTemplatesDefaultFile,
dsqlDockerComposeFileName,
dsqlDockerComposeFileNameAlt,
distroDirName,
distroAppDirName,
distroDataDirName,
distroCommunityName,
distroCommunityExportTarName,
distroProName,
distroProExportTarName,
distroEnterpriseName,
distroEnterpriseExportTarName,
communityDistroTempDir,
communityDistroDir,
};
}
@@ -4,9 +4,13 @@ export default function grabDockerStackServicesNames(): {
dbServiceName: string;
dbCronServiceName: string;
postDbSetupServiceName: string;
setupServiceName: string;
webAppServiceName: string;
webAppCronServiceName: string;
webAppPostDbSetupServiceName: string;
dbReplica1ServiceName: string;
dbReplica2ServiceName: string;
reverseProxyServiceName: string;
staticServiceName: string;
websocketServiceName: string;
cronServiceName: string;
};
@@ -6,22 +6,30 @@ function grabDockerStackServicesNames() {
const maxScaleServiceName = `${deploymentName}-dsql-maxscale`;
const dbServiceName = `${deploymentName}-dsql-db`;
const dbCronServiceName = `${deploymentName}-dsql-db-cron`;
const cronServiceName = `${deploymentName}-dsql-cron`;
const postDbSetupServiceName = `${deploymentName}-dsql-post-db-setup`;
const setupServiceName = `${deploymentName}-dsql-setup`;
const webAppServiceName = `${deploymentName}-dsql-web-app`;
const webAppCronServiceName = `${deploymentName}-dsql-web-app-cron`;
const webAppPostDbSetupServiceName = `${deploymentName}-dsql-web-app-post-db-setup`;
const dbReplica1ServiceName = `${deploymentName}-dsql-db-replica-1`;
const dbReplica2ServiceName = `${deploymentName}-dsql-db-replica-2`;
const reverseProxyServiceName = `${deploymentName}-dsql-reverse-proxy`;
const staticServiceName = `${deploymentName}-dsql-static`;
const websocketServiceName = `${deploymentName}-dsql-websocket`;
return {
deploymentName,
maxScaleServiceName,
dbServiceName,
dbCronServiceName,
postDbSetupServiceName,
setupServiceName,
webAppServiceName,
webAppCronServiceName,
webAppPostDbSetupServiceName,
dbReplica1ServiceName,
dbReplica2ServiceName,
reverseProxyServiceName,
staticServiceName,
websocketServiceName,
cronServiceName,
};
}
@@ -5,4 +5,5 @@ export default function grabIPAddresses(): {
mainDBIP: string;
localHostIP: string;
globalIPPrefix: string;
webSocketIP: string;
};
@@ -7,11 +7,12 @@ 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 } = (0, grab_docker_resource_ip_numbers_1.default)();
const { cron, db, maxscale, postDbSetup, web, db_cron, reverse_proxy, web_app_post_db_setup, websocket, } = (0, grab_docker_resource_ip_numbers_1.default)();
const webAppIP = `${globalIPPrefix}.${web}`;
const appCronIP = `${globalIPPrefix}.${cron}`;
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
const mainDBIP = `${globalIPPrefix}.${db}`;
const webSocketIP = `${globalIPPrefix}.${websocket}`;
const localHostIP = `${globalIPPrefix}.1`;
return {
webAppIP,
@@ -20,5 +21,6 @@ function grabIPAddresses() {
mainDBIP,
localHostIP,
globalIPPrefix,
webSocketIP,
};
}
+1 -2
View File
@@ -24,7 +24,6 @@ function default_1(_a) {
genObject: query,
dbFullName,
});
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,
@@ -53,7 +52,7 @@ function default_1(_a) {
},
];
}
const res = yield (0, conn_db_handler_1.default)(DB_CONN, connQueries);
const res = yield (0, conn_db_handler_1.default)(undefined, connQueries);
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
return {
success: isSuccess,
+6 -4
View File
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = connDbHandler;
const debug_log_1 = __importDefault(require("../logging/debug-log"));
const grab_dsql_connection_1 = __importDefault(require("../grab-dsql-connection"));
/**
* # Run Query From MySQL Connection
* @description Run a query from a pre-existing MySQL/Mariadb Connection
@@ -34,14 +35,15 @@ query,
values, debug) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const finalConnection = conn || (yield (0, grab_dsql_connection_1.default)());
try {
if (!conn)
if (!finalConnection)
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);
const res = yield finalConnection.query(trimQuery(query), values);
if (debug) {
(0, debug_log_1.default)({
log: res,
@@ -62,7 +64,7 @@ values, debug) {
const queryObj = query[i];
currentQueryError.sql = queryObj.query;
currentQueryError.sqlValues = queryObj.values;
const queryObjRes = yield conn.query(trimQuery(queryObj.query), queryObj.values);
const queryObjRes = yield finalConnection.query(trimQuery(queryObj.query), queryObj.values);
if (debug) {
(0, debug_log_1.default)({
log: queryObjRes,
@@ -118,7 +120,7 @@ values, debug) {
};
}
finally {
yield (conn === null || conn === void 0 ? void 0 : conn.end());
yield (finalConnection === null || finalConnection === void 0 ? void 0 : finalConnection.end());
}
});
}
+14
View File
@@ -20,6 +20,20 @@ const grabDbSSL_1 = __importDefault(require("./backend/grabDbSSL"));
*/
function grabDSQLConnection(param) {
return __awaiter(this, void 0, void 0, function* () {
return yield mariadb_1.default.createConnection({
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
database: (param === null || param === void 0 ? void 0 : param.noDb) ? undefined : process.env.DSQL_DB_NAME,
port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
ssl: (0, grabDbSSL_1.default)(),
supportBigNumbers: true,
bigNumberStrings: false,
dateStrings: true,
});
if (global.DSQL_USE_LOCAL || (param === null || param === void 0 ? void 0 : param.local)) {
return (global.DSQL_DB_CONN ||
(yield mariadb_1.default.createConnection({
+5 -1
View File
@@ -26,8 +26,12 @@ function numberfy(num, decimals) {
return 0;
if (isNaN(numberfiedNum))
return 0;
if (decimals)
if (decimals == 0) {
return Math.round(Number(numberfiedNum));
}
else if (decimals) {
return Number(numberfiedNum.toFixed(decimals));
}
if (existingDecimals)
return Number(numberfiedNum.toFixed(existingDecimals));
return Math.round(numberfiedNum);