Updates
This commit is contained in:
parent
b578843c6d
commit
8b3553fcd5
@ -13,6 +13,7 @@ import numberfy from "../package-shared/utils/numberfy";
|
|||||||
import slugify from "../package-shared/utils/slugify";
|
import slugify from "../package-shared/utils/slugify";
|
||||||
import postLogin from "./auth/post-login";
|
import postLogin from "./auth/post-login";
|
||||||
import deserializeQuery from "../package-shared/utils/deserialize-query";
|
import deserializeQuery from "../package-shared/utils/deserialize-query";
|
||||||
|
import debugLog from "../package-shared/utils/logging/debug-log";
|
||||||
|
|
||||||
const media = {
|
const media = {
|
||||||
imageInputToBase64: imageInputToBase64,
|
imageInputToBase64: imageInputToBase64,
|
||||||
@ -41,6 +42,7 @@ const utils = {
|
|||||||
EJSON,
|
EJSON,
|
||||||
numberfy,
|
numberfy,
|
||||||
slugify,
|
slugify,
|
||||||
|
debugLog,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
2
dist/client/index.d.ts
vendored
2
dist/client/index.d.ts
vendored
@ -11,6 +11,7 @@ import numberfy from "../package-shared/utils/numberfy";
|
|||||||
import slugify from "../package-shared/utils/slugify";
|
import slugify from "../package-shared/utils/slugify";
|
||||||
import postLogin from "./auth/post-login";
|
import postLogin from "./auth/post-login";
|
||||||
import deserializeQuery from "../package-shared/utils/deserialize-query";
|
import deserializeQuery from "../package-shared/utils/deserialize-query";
|
||||||
|
import debugLog from "../package-shared/utils/logging/debug-log";
|
||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
@ -48,6 +49,7 @@ declare const datasquirelClient: {
|
|||||||
};
|
};
|
||||||
numberfy: typeof numberfy;
|
numberfy: typeof numberfy;
|
||||||
slugify: typeof slugify;
|
slugify: typeof slugify;
|
||||||
|
debugLog: typeof debugLog;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export default datasquirelClient;
|
export default datasquirelClient;
|
||||||
|
2
dist/client/index.js
vendored
2
dist/client/index.js
vendored
@ -18,6 +18,7 @@ const numberfy_1 = __importDefault(require("../package-shared/utils/numberfy"));
|
|||||||
const slugify_1 = __importDefault(require("../package-shared/utils/slugify"));
|
const slugify_1 = __importDefault(require("../package-shared/utils/slugify"));
|
||||||
const post_login_1 = __importDefault(require("./auth/post-login"));
|
const post_login_1 = __importDefault(require("./auth/post-login"));
|
||||||
const deserialize_query_1 = __importDefault(require("../package-shared/utils/deserialize-query"));
|
const deserialize_query_1 = __importDefault(require("../package-shared/utils/deserialize-query"));
|
||||||
|
const debug_log_1 = __importDefault(require("../package-shared/utils/logging/debug-log"));
|
||||||
const media = {
|
const media = {
|
||||||
imageInputToBase64: imageInputToBase64_1.default,
|
imageInputToBase64: imageInputToBase64_1.default,
|
||||||
imageInputFileToBase64: imageInputFileToBase64_1.default,
|
imageInputFileToBase64: imageInputFileToBase64_1.default,
|
||||||
@ -43,6 +44,7 @@ const utils = {
|
|||||||
EJSON: ejson_1.default,
|
EJSON: ejson_1.default,
|
||||||
numberfy: numberfy_1.default,
|
numberfy: numberfy_1.default,
|
||||||
slugify: slugify_1.default,
|
slugify: slugify_1.default,
|
||||||
|
debugLog: debug_log_1.default,
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Fetch
|
* Fetch
|
||||||
|
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -37,6 +37,7 @@ import validateTempEmailCode from "./package-shared/actions/users/validate-temp-
|
|||||||
import deleteUser from "./package-shared/actions/users/delete-user";
|
import deleteUser from "./package-shared/actions/users/delete-user";
|
||||||
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
|
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
|
||||||
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
|
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
|
||||||
|
import debugLog from "./package-shared/utils/logging/debug-log";
|
||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
@ -107,6 +108,7 @@ declare const datasquirel: {
|
|||||||
};
|
};
|
||||||
numberfy: typeof import("./package-shared/utils/numberfy").default;
|
numberfy: typeof import("./package-shared/utils/numberfy").default;
|
||||||
slugify: typeof import("./package-shared/utils/slugify").default;
|
slugify: typeof import("./package-shared/utils/slugify").default;
|
||||||
|
debugLog: typeof debugLog;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
sql: {
|
sql: {
|
||||||
@ -124,6 +126,7 @@ declare const datasquirel: {
|
|||||||
parseCookies: typeof parseCookies;
|
parseCookies: typeof parseCookies;
|
||||||
httpRequest: typeof httpRequest;
|
httpRequest: typeof httpRequest;
|
||||||
connDbHandler: typeof connDbHandler;
|
connDbHandler: typeof connDbHandler;
|
||||||
|
debugLog: typeof debugLog;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Run Crud actions `get`, `insert`, `update`, `delete`
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
@ -36,6 +36,7 @@ const validate_temp_email_code_1 = __importDefault(require("./package-shared/act
|
|||||||
const delete_user_1 = __importDefault(require("./package-shared/actions/users/delete-user"));
|
const delete_user_1 = __importDefault(require("./package-shared/actions/users/delete-user"));
|
||||||
const crud_1 = __importDefault(require("./package-shared/utils/data-fetching/crud"));
|
const crud_1 = __importDefault(require("./package-shared/utils/data-fetching/crud"));
|
||||||
const method_crud_1 = __importDefault(require("./package-shared/utils/data-fetching/method-crud"));
|
const method_crud_1 = __importDefault(require("./package-shared/utils/data-fetching/method-crud"));
|
||||||
|
const debug_log_1 = __importDefault(require("./package-shared/utils/logging/debug-log"));
|
||||||
/**
|
/**
|
||||||
* User Functions Object
|
* User Functions Object
|
||||||
*/
|
*/
|
||||||
@ -100,6 +101,7 @@ const datasquirel = {
|
|||||||
parseCookies: parseCookies_1.default,
|
parseCookies: parseCookies_1.default,
|
||||||
httpRequest: httpRequest_1.default,
|
httpRequest: httpRequest_1.default,
|
||||||
connDbHandler: conn_db_handler_1.default,
|
connDbHandler: conn_db_handler_1.default,
|
||||||
|
debugLog: debug_log_1.default,
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Run Crud actions `get`, `insert`, `update`, `delete`
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
12
dist/package-shared/actions/get.js
vendored
12
dist/package-shared/actions/get.js
vendored
@ -19,6 +19,7 @@ const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
|||||||
const get_1 = __importDefault(require("../functions/api/query/get"));
|
const get_1 = __importDefault(require("../functions/api/query/get"));
|
||||||
const serialize_query_1 = __importDefault(require("../utils/serialize-query"));
|
const serialize_query_1 = __importDefault(require("../utils/serialize-query"));
|
||||||
const grab_query_and_values_1 = __importDefault(require("../utils/grab-query-and-values"));
|
const grab_query_and_values_1 = __importDefault(require("../utils/grab-query-and-values"));
|
||||||
|
const debug_log_1 = __importDefault(require("../utils/logging/debug-log"));
|
||||||
/**
|
/**
|
||||||
* # Make a get request to Datasquirel API
|
* # Make a get request to Datasquirel API
|
||||||
*/
|
*/
|
||||||
@ -26,6 +27,9 @@ function get(_a) {
|
|||||||
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }) {
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
function debugFn(log, label) {
|
||||||
|
(0, debug_log_1.default)({ log, addTime: true, title: "apiGet", label });
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
*
|
*
|
||||||
@ -40,7 +44,7 @@ function get(_a) {
|
|||||||
}
|
}
|
||||||
catch (error) { }
|
catch (error) { }
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:Running Locally ...");
|
debugFn("Running Locally ...");
|
||||||
}
|
}
|
||||||
return yield (0, get_1.default)({
|
return yield (0, get_1.default)({
|
||||||
dbFullName: DSQL_DB_NAME,
|
dbFullName: DSQL_DB_NAME,
|
||||||
@ -70,15 +74,15 @@ function get(_a) {
|
|||||||
debug,
|
debug,
|
||||||
};
|
};
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:queryObject", queryObject);
|
debugFn(queryObject, "queryObject");
|
||||||
}
|
}
|
||||||
const queryString = (0, serialize_query_1.default)(Object.assign({}, queryObject));
|
const queryString = (0, serialize_query_1.default)(Object.assign({}, queryObject));
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:queryString", queryString);
|
debugFn(queryString, "queryString");
|
||||||
}
|
}
|
||||||
let path = `/api/query/${user_id || grabedHostNames.user_id}/get${queryString}`;
|
let path = `/api/query/${user_id || grabedHostNames.user_id}/get${queryString}`;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:path", path);
|
debugFn(path, "path");
|
||||||
}
|
}
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
14
dist/package-shared/actions/users/login-user.js
vendored
14
dist/package-shared/actions/users/login-user.js
vendored
@ -20,6 +20,7 @@ const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names")
|
|||||||
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
|
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
|
||||||
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||||
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||||
|
const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||||
/**
|
/**
|
||||||
* # Login A user
|
* # Login A user
|
||||||
*/
|
*/
|
||||||
@ -36,6 +37,9 @@ function loginUser(_a) {
|
|||||||
: undefined;
|
: undefined;
|
||||||
const finalEncryptionKey = encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
|
const finalEncryptionKey = encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
|
||||||
const finalEncryptionSalt = encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
const finalEncryptionSalt = encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
||||||
|
function debugFn(log, label) {
|
||||||
|
(0, debug_log_1.default)({ log, addTime: true, title: "loginUser", label });
|
||||||
|
}
|
||||||
if (!(finalEncryptionKey === null || finalEncryptionKey === void 0 ? void 0 : finalEncryptionKey.match(/.{8,}/))) {
|
if (!(finalEncryptionKey === null || finalEncryptionKey === void 0 ? void 0 : finalEncryptionKey.match(/.{8,}/))) {
|
||||||
console.log("Encryption key is invalid");
|
console.log("Encryption key is invalid");
|
||||||
return {
|
return {
|
||||||
@ -148,7 +152,7 @@ function loginUser(_a) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log(`loginUser:httpResponse:`, httpResponse);
|
debugFn(httpResponse, "httpResponse");
|
||||||
}
|
}
|
||||||
if (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) {
|
if (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) {
|
||||||
let encryptedPayload = (0, encrypt_1.default)({
|
let encryptedPayload = (0, encrypt_1.default)({
|
||||||
@ -173,16 +177,16 @@ function loginUser(_a) {
|
|||||||
const authKeyName = cookieNames.keyCookieName;
|
const authKeyName = cookieNames.keyCookieName;
|
||||||
const csrfName = cookieNames.csrfCookieName;
|
const csrfName = cookieNames.csrfCookieName;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log(`loginUser:authKeyName:`, authKeyName);
|
debugFn(authKeyName, "authKeyName");
|
||||||
console.log(`loginUser:csrfName:`, csrfName);
|
debugFn(csrfName, "csrfName");
|
||||||
console.log(`loginUser:encryptedPayload:`, encryptedPayload);
|
debugFn(encryptedPayload, "encryptedPayload");
|
||||||
}
|
}
|
||||||
response === null || response === void 0 ? void 0 : response.setHeader("Set-Cookie", [
|
response === null || response === void 0 ? void 0 : response.setHeader("Set-Cookie", [
|
||||||
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
|
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
|
||||||
`${csrfName}=${(_b = httpResponse.payload) === null || _b === void 0 ? void 0 : _b.csrf_k};samesite=strict;path=/;HttpOnly=true`,
|
`${csrfName}=${(_b = httpResponse.payload) === null || _b === void 0 ? void 0 : _b.csrf_k};samesite=strict;path=/;HttpOnly=true`,
|
||||||
]);
|
]);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log(`loginUser:Response Sent!`);
|
debugFn("Response Sent!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
|
@ -10,6 +10,7 @@ const ejson_1 = __importDefault(require("../../utils/ejson"));
|
|||||||
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||||
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
|
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
|
||||||
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||||
|
const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||||
/**
|
/**
|
||||||
* # Logout user
|
* # Logout user
|
||||||
*/
|
*/
|
||||||
@ -25,8 +26,11 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
|||||||
database,
|
database,
|
||||||
userId: user_id,
|
userId: user_id,
|
||||||
});
|
});
|
||||||
|
function debugFn(log, label) {
|
||||||
|
(0, debug_log_1.default)({ log, addTime: true, title: "logoutUser", label });
|
||||||
|
}
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("logoutUser:cookieNames", cookieNames);
|
debugFn(cookieNames, "cookieNames");
|
||||||
}
|
}
|
||||||
const authKeyName = cookieNames.keyCookieName;
|
const authKeyName = cookieNames.keyCookieName;
|
||||||
const csrfName = cookieNames.csrfCookieName;
|
const csrfName = cookieNames.csrfCookieName;
|
||||||
@ -57,7 +61,7 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("logoutUser:decryptedUserJSON", decryptedUserJSON);
|
debugFn(decryptedUserJSON, "decryptedUserJSON");
|
||||||
}
|
}
|
||||||
if (!decryptedUserJSON)
|
if (!decryptedUserJSON)
|
||||||
throw new Error("Invalid User");
|
throw new Error("Invalid User");
|
||||||
|
@ -8,9 +8,3 @@ type Param = {
|
|||||||
*/
|
*/
|
||||||
export default function setUserSchemaData({ userId, schemaData, }: Param): boolean;
|
export default function setUserSchemaData({ userId, schemaData, }: Param): boolean;
|
||||||
export {};
|
export {};
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
|
@ -24,9 +24,3 @@ function setUserSchemaData({ userId, schemaData, }) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
|
12
dist/package-shared/shell/createDbFromSchema/check-db-record.d.ts
vendored
Normal file
12
dist/package-shared/shell/createDbFromSchema/check-db-record.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { DSQL_DatabaseSchemaType } from "../../types";
|
||||||
|
import { DSQL_DATASQUIREL_USER_DATABASES } from "../../types/dsql";
|
||||||
|
type Param = {
|
||||||
|
userId?: number | string | null;
|
||||||
|
dbSchema: DSQL_DatabaseSchemaType;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* # Create database from Schema Function
|
||||||
|
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||||
|
*/
|
||||||
|
export default function checkDbRecordCreateDbSchema({ userId, dbSchema, }: Param): Promise<DSQL_DATASQUIREL_USER_DATABASES | undefined>;
|
||||||
|
export {};
|
64
dist/package-shared/shell/createDbFromSchema/check-db-record.js
vendored
Normal file
64
dist/package-shared/shell/createDbFromSchema/check-db-record.js
vendored
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
"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 = checkDbRecordCreateDbSchema;
|
||||||
|
const varDatabaseDbHandler_1 = __importDefault(require("../utils/varDatabaseDbHandler"));
|
||||||
|
const numberfy_1 = __importDefault(require("../../utils/numberfy"));
|
||||||
|
const addDbEntry_1 = __importDefault(require("../../functions/backend/db/addDbEntry"));
|
||||||
|
/**
|
||||||
|
* # Create database from Schema Function
|
||||||
|
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||||
|
*/
|
||||||
|
function checkDbRecordCreateDbSchema(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ userId, dbSchema, }) {
|
||||||
|
try {
|
||||||
|
const { dbFullName, dbName, dbSlug, dbDescription, dbImage, childDatabase, childDatabaseDbFullName, } = dbSchema;
|
||||||
|
let recordedDbEntryArray = userId
|
||||||
|
? yield (0, varDatabaseDbHandler_1.default)({
|
||||||
|
queryString: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
||||||
|
queryValuesArray: [dbFullName],
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
let recordedDbEntry = recordedDbEntryArray === null || recordedDbEntryArray === void 0 ? void 0 : recordedDbEntryArray[0];
|
||||||
|
if (!(recordedDbEntry === null || recordedDbEntry === void 0 ? void 0 : recordedDbEntry.id) && userId) {
|
||||||
|
const newDbEntryObj = {
|
||||||
|
user_id: (0, numberfy_1.default)(userId),
|
||||||
|
db_name: dbName,
|
||||||
|
db_slug: dbSlug,
|
||||||
|
db_full_name: dbFullName,
|
||||||
|
db_description: dbDescription,
|
||||||
|
db_image: dbImage,
|
||||||
|
active_clone: childDatabase ? 1 : undefined,
|
||||||
|
active_clone_parent_db: childDatabaseDbFullName,
|
||||||
|
};
|
||||||
|
const newDbEntry = (yield (0, addDbEntry_1.default)({
|
||||||
|
data: newDbEntryObj,
|
||||||
|
tableName: "user_databases",
|
||||||
|
forceLocal: true,
|
||||||
|
}));
|
||||||
|
if (newDbEntry.insertId) {
|
||||||
|
recordedDbEntryArray = yield (0, varDatabaseDbHandler_1.default)({
|
||||||
|
queryString: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
||||||
|
queryValuesArray: [dbFullName],
|
||||||
|
});
|
||||||
|
recordedDbEntry = recordedDbEntryArray === null || recordedDbEntryArray === void 0 ? void 0 : recordedDbEntryArray[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recordedDbEntry;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
15
dist/package-shared/shell/createDbFromSchema/check-table-record.d.ts
vendored
Normal file
15
dist/package-shared/shell/createDbFromSchema/check-table-record.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { DSQL_DatabaseSchemaType, DSQL_TableSchemaType } from "../../types";
|
||||||
|
import { DSQL_DATASQUIREL_USER_DATABASE_TABLES, DSQL_DATASQUIREL_USER_DATABASES } from "../../types/dsql";
|
||||||
|
type Param = {
|
||||||
|
userId?: number | string | null;
|
||||||
|
tableSchema?: DSQL_TableSchemaType;
|
||||||
|
dbSchema: DSQL_DatabaseSchemaType[];
|
||||||
|
dbRecord?: DSQL_DATASQUIREL_USER_DATABASES;
|
||||||
|
dbFullName: string;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* # Create database from Schema Function
|
||||||
|
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||||
|
*/
|
||||||
|
export default function checkTableRecordCreateDbSchema({ userId, tableSchema, dbSchema, dbRecord, dbFullName, }: Param): Promise<DSQL_DATASQUIREL_USER_DATABASE_TABLES | undefined>;
|
||||||
|
export {};
|
92
dist/package-shared/shell/createDbFromSchema/check-table-record.js
vendored
Normal file
92
dist/package-shared/shell/createDbFromSchema/check-table-record.js
vendored
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
"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 = checkTableRecordCreateDbSchema;
|
||||||
|
const varDatabaseDbHandler_1 = __importDefault(require("../utils/varDatabaseDbHandler"));
|
||||||
|
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||||
|
const numberfy_1 = __importDefault(require("../../utils/numberfy"));
|
||||||
|
const addDbEntry_1 = __importDefault(require("../../functions/backend/db/addDbEntry"));
|
||||||
|
/**
|
||||||
|
* # Create database from Schema Function
|
||||||
|
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||||
|
*/
|
||||||
|
function checkTableRecordCreateDbSchema(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ userId, tableSchema, dbSchema, dbRecord, dbFullName, }) {
|
||||||
|
if (!tableSchema)
|
||||||
|
return undefined;
|
||||||
|
try {
|
||||||
|
const queryObj = (0, sql_generator_1.default)({
|
||||||
|
tableName: "user_database_tables",
|
||||||
|
genObject: {
|
||||||
|
query: {
|
||||||
|
db_id: {
|
||||||
|
value: String(dbRecord === null || dbRecord === void 0 ? void 0 : dbRecord.id),
|
||||||
|
},
|
||||||
|
table_slug: {
|
||||||
|
value: tableSchema.tableName,
|
||||||
|
},
|
||||||
|
user_id: {
|
||||||
|
value: String(userId),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dbFullName: "datasquirel",
|
||||||
|
});
|
||||||
|
let recordedTableEntryArray = userId
|
||||||
|
? yield (0, varDatabaseDbHandler_1.default)({
|
||||||
|
queryString: (queryObj === null || queryObj === void 0 ? void 0 : queryObj.string) || "",
|
||||||
|
queryValuesArray: queryObj === null || queryObj === void 0 ? void 0 : queryObj.values,
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
let recordedTableEntry = recordedTableEntryArray === null || recordedTableEntryArray === void 0 ? void 0 : recordedTableEntryArray[0];
|
||||||
|
if (!(recordedTableEntry === null || recordedTableEntry === void 0 ? void 0 : recordedTableEntry.id) && userId) {
|
||||||
|
const newTableInsertObject = {
|
||||||
|
user_id: (0, numberfy_1.default)(userId),
|
||||||
|
db_id: dbRecord === null || dbRecord === void 0 ? void 0 : dbRecord.id,
|
||||||
|
db_slug: dbRecord === null || dbRecord === void 0 ? void 0 : dbRecord.db_slug,
|
||||||
|
table_name: tableSchema.tableFullName,
|
||||||
|
table_slug: tableSchema.tableName,
|
||||||
|
};
|
||||||
|
if ((tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.childTable) && tableSchema.childTableName) {
|
||||||
|
const parentDb = dbSchema.find((db) => db.dbFullName == tableSchema.childTableDbFullName);
|
||||||
|
const parentDbTable = parentDb === null || parentDb === void 0 ? void 0 : parentDb.tables.find((tbl) => tbl.tableName == tableSchema.childTableName);
|
||||||
|
if (parentDb && parentDbTable) {
|
||||||
|
newTableInsertObject["child_table"] = 1;
|
||||||
|
newTableInsertObject["child_table_parent_database"] =
|
||||||
|
parentDb.dbFullName;
|
||||||
|
newTableInsertObject["child_table_parent_table"] =
|
||||||
|
parentDbTable.tableName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const newTableRecordEntry = (yield (0, addDbEntry_1.default)({
|
||||||
|
data: newTableInsertObject,
|
||||||
|
tableName: "user_database_tables",
|
||||||
|
dbContext: "Master",
|
||||||
|
forceLocal: true,
|
||||||
|
}));
|
||||||
|
if (newTableRecordEntry.insertId) {
|
||||||
|
recordedTableEntryArray = yield (0, varDatabaseDbHandler_1.default)({
|
||||||
|
queryString: (queryObj === null || queryObj === void 0 ? void 0 : queryObj.string) || "",
|
||||||
|
queryValuesArray: queryObj === null || queryObj === void 0 ? void 0 : queryObj.values,
|
||||||
|
});
|
||||||
|
recordedTableEntry = recordedTableEntryArray === null || recordedTableEntryArray === void 0 ? void 0 : recordedTableEntryArray[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recordedTableEntry;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
14
dist/package-shared/shell/createDbFromSchema/handle-indexes.d.ts
vendored
Normal file
14
dist/package-shared/shell/createDbFromSchema/handle-indexes.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { DSQL_IndexSchemaType } from "../../types";
|
||||||
|
type Param = {
|
||||||
|
tableName: string;
|
||||||
|
dbFullName: string;
|
||||||
|
indexes: DSQL_IndexSchemaType[];
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Handle DATASQUIREL Table Indexes
|
||||||
|
* ===================================================
|
||||||
|
* @description Iterate through each datasquirel schema
|
||||||
|
* table index(if available), and perform operations
|
||||||
|
*/
|
||||||
|
export default function handleIndexescreateDbFromSchema({ dbFullName, tableName, indexes, }: Param): Promise<void>;
|
||||||
|
export {};
|
55
dist/package-shared/shell/createDbFromSchema/handle-indexes.js
vendored
Normal file
55
dist/package-shared/shell/createDbFromSchema/handle-indexes.js
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
"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 = handleIndexescreateDbFromSchema;
|
||||||
|
const varDatabaseDbHandler_1 = __importDefault(require("../utils/varDatabaseDbHandler"));
|
||||||
|
/**
|
||||||
|
* Handle DATASQUIREL Table Indexes
|
||||||
|
* ===================================================
|
||||||
|
* @description Iterate through each datasquirel schema
|
||||||
|
* table index(if available), and perform operations
|
||||||
|
*/
|
||||||
|
function handleIndexescreateDbFromSchema(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ dbFullName, tableName, indexes, }) {
|
||||||
|
for (let g = 0; g < indexes.length; g++) {
|
||||||
|
const { indexType, indexName, indexTableFields, alias } = indexes[g];
|
||||||
|
if (!(alias === null || alias === void 0 ? void 0 : alias.match(/./)))
|
||||||
|
continue;
|
||||||
|
/**
|
||||||
|
* @description Check for existing Index in MYSQL db
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* @type {import("../../types").DSQL_MYSQL_SHOW_INDEXES_Type[]}
|
||||||
|
* @description All indexes from MYSQL db
|
||||||
|
*/ // @ts-ignore
|
||||||
|
const allExistingIndexes = yield (0, varDatabaseDbHandler_1.default)({
|
||||||
|
queryString: `SHOW INDEXES FROM \`${dbFullName}\`.\`${tableName}\``,
|
||||||
|
});
|
||||||
|
const existingKeyInDb = allExistingIndexes.filter((indexObject) => indexObject.Key_name === alias);
|
||||||
|
if (!existingKeyInDb[0])
|
||||||
|
throw new Error("This Index Does not Exist");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
/**
|
||||||
|
* @description Create new index if determined that it
|
||||||
|
* doesn't exist in MYSQL db
|
||||||
|
*/
|
||||||
|
yield (0, varDatabaseDbHandler_1.default)({
|
||||||
|
queryString: `CREATE${(indexType === null || indexType === void 0 ? void 0 : indexType.match(/fullText/i)) ? " FULLTEXT" : ""} INDEX \`${alias}\` ON \`${dbFullName}\`.\`${tableName}\`(${indexTableFields === null || indexTableFields === void 0 ? void 0 : indexTableFields.map((nm) => nm.value).map((nm) => `\`${nm}\``).join(",")}) COMMENT 'schema_index'`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
type Param = {
|
type Param = {
|
||||||
userId?: number | string | null;
|
userId?: number | string | null;
|
||||||
targetDatabase?: string;
|
targetDatabase?: string;
|
||||||
dbSchemaData?: import("../types").DSQL_DatabaseSchemaType[];
|
dbSchemaData?: import("../../types").DSQL_DatabaseSchemaType[];
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Create database from Schema Function
|
* # Create database from Schema Function
|
@ -14,13 +14,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = createDbFromSchema;
|
exports.default = createDbFromSchema;
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const noDatabaseDbHandler_1 = __importDefault(require("./utils/noDatabaseDbHandler"));
|
const noDatabaseDbHandler_1 = __importDefault(require("../utils/noDatabaseDbHandler"));
|
||||||
const varDatabaseDbHandler_1 = __importDefault(require("./utils/varDatabaseDbHandler"));
|
const varDatabaseDbHandler_1 = __importDefault(require("../utils/varDatabaseDbHandler"));
|
||||||
const createTable_1 = __importDefault(require("./utils/createTable"));
|
const createTable_1 = __importDefault(require("../utils/createTable"));
|
||||||
const updateTable_1 = __importDefault(require("./utils/updateTable"));
|
const updateTable_1 = __importDefault(require("../utils/updateTable"));
|
||||||
const dbHandler_1 = __importDefault(require("./utils/dbHandler"));
|
const dbHandler_1 = __importDefault(require("../utils/dbHandler"));
|
||||||
const ejson_1 = __importDefault(require("../utils/ejson"));
|
const ejson_1 = __importDefault(require("../../utils/ejson"));
|
||||||
const grab_dir_names_1 = __importDefault(require("../utils/backend/names/grab-dir-names"));
|
const grab_dir_names_1 = __importDefault(require("../../utils/backend/names/grab-dir-names"));
|
||||||
|
const check_db_record_1 = __importDefault(require("./check-db-record"));
|
||||||
|
const check_table_record_1 = __importDefault(require("./check-table-record"));
|
||||||
|
const handle_indexes_1 = __importDefault(require("./handle-indexes"));
|
||||||
/**
|
/**
|
||||||
* # Create database from Schema Function
|
* # Create database from Schema Function
|
||||||
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||||
@ -38,25 +41,21 @@ function createDbFromSchema(_a) {
|
|||||||
console.log("Schema Not Found!");
|
console.log("Schema Not Found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// await createDatabasesFromSchema(dbSchema);
|
|
||||||
for (let i = 0; i < dbSchema.length; i++) {
|
for (let i = 0; i < dbSchema.length; i++) {
|
||||||
const database = dbSchema[i];
|
const database = dbSchema[i];
|
||||||
const { dbFullName, tables, dbName, dbSlug, childrenDatabases } = database;
|
const { dbFullName, tables, dbSlug, childrenDatabases } = database;
|
||||||
if (targetDatabase && dbFullName != targetDatabase) {
|
if (targetDatabase && dbFullName != targetDatabase) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/** @type {any} */
|
|
||||||
const dbCheck = yield (0, noDatabaseDbHandler_1.default)(`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbFullName}'`);
|
const dbCheck = yield (0, noDatabaseDbHandler_1.default)(`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbFullName}'`);
|
||||||
if (!((_b = dbCheck === null || dbCheck === void 0 ? void 0 : dbCheck[0]) === null || _b === void 0 ? void 0 : _b.dbFullName)) {
|
if (!((_b = dbCheck === null || dbCheck === void 0 ? void 0 : dbCheck[0]) === null || _b === void 0 ? void 0 : _b.dbFullName)) {
|
||||||
const newDatabase = yield (0, noDatabaseDbHandler_1.default)(`CREATE DATABASE IF NOT EXISTS \`${dbFullName}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);
|
const newDatabase = yield (0, noDatabaseDbHandler_1.default)(`CREATE DATABASE IF NOT EXISTS \`${dbFullName}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Select all tables
|
|
||||||
* @type {any}
|
|
||||||
* @description Select All tables in target database
|
|
||||||
*/
|
|
||||||
const allTables = yield (0, noDatabaseDbHandler_1.default)(`SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${dbFullName}'`);
|
const allTables = yield (0, noDatabaseDbHandler_1.default)(`SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${dbFullName}'`);
|
||||||
// let tableDropped;
|
let recordedDbEntry = yield (0, check_db_record_1.default)({
|
||||||
|
dbSchema: database,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
for (let tb = 0; tb < allTables.length; tb++) {
|
for (let tb = 0; tb < allTables.length; tb++) {
|
||||||
const { TABLE_NAME } = allTables[tb];
|
const { TABLE_NAME } = allTables[tb];
|
||||||
/**
|
/**
|
||||||
@ -89,13 +88,6 @@ function createDbFromSchema(_a) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const recordedDbEntryArray = userId
|
|
||||||
? yield (0, varDatabaseDbHandler_1.default)({
|
|
||||||
queryString: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
|
||||||
queryValuesArray: [dbFullName],
|
|
||||||
})
|
|
||||||
: undefined;
|
|
||||||
const recordedDbEntry = recordedDbEntryArray === null || recordedDbEntryArray === void 0 ? void 0 : recordedDbEntryArray[0];
|
|
||||||
/**
|
/**
|
||||||
* @description Iterate through each table and perform table actions
|
* @description Iterate through each table and perform table actions
|
||||||
*/
|
*/
|
||||||
@ -155,10 +147,8 @@ function createDbFromSchema(_a) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
////////////////////////////////////////
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
////////////////////////////////////////
|
|
||||||
/**
|
/**
|
||||||
* @description Create new Table if table doesnt exist
|
* @description Create new Table if table doesnt exist
|
||||||
*/
|
*/
|
||||||
@ -169,48 +159,27 @@ function createDbFromSchema(_a) {
|
|||||||
tableSchema: table,
|
tableSchema: table,
|
||||||
recordedDbEntry,
|
recordedDbEntry,
|
||||||
});
|
});
|
||||||
if (indexes && indexes[0]) {
|
/**
|
||||||
/**
|
* Handle DATASQUIREL Table Indexes
|
||||||
* Handle DATASQUIREL Table Indexes
|
* ===================================================
|
||||||
* ===================================================
|
* @description Iterate through each datasquirel schema
|
||||||
* @description Iterate through each datasquirel schema
|
* table index(if available), and perform operations
|
||||||
* table index(if available), and perform operations
|
*/
|
||||||
*/
|
if (indexes === null || indexes === void 0 ? void 0 : indexes[0]) {
|
||||||
if (indexes && indexes[0]) {
|
(0, handle_indexes_1.default)({
|
||||||
for (let g = 0; g < indexes.length; g++) {
|
dbFullName,
|
||||||
const { indexType, indexName, indexTableFields, alias, } = indexes[g];
|
indexes,
|
||||||
if (!(alias === null || alias === void 0 ? void 0 : alias.match(/./)))
|
tableName,
|
||||||
continue;
|
});
|
||||||
/**
|
|
||||||
* @description Check for existing Index in MYSQL db
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
/**
|
|
||||||
* @type {import("../types").DSQL_MYSQL_SHOW_INDEXES_Type[]}
|
|
||||||
* @description All indexes from MYSQL db
|
|
||||||
*/ // @ts-ignore
|
|
||||||
const allExistingIndexes = yield (0, varDatabaseDbHandler_1.default)({
|
|
||||||
queryString: `SHOW INDEXES FROM \`${dbFullName}\`.\`${tableName}\``,
|
|
||||||
});
|
|
||||||
const existingKeyInDb = allExistingIndexes.filter((indexObject) => indexObject.Key_name === alias);
|
|
||||||
if (!existingKeyInDb[0])
|
|
||||||
throw new Error("This Index Does not Exist");
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
/**
|
|
||||||
* @description Create new index if determined that it
|
|
||||||
* doesn't exist in MYSQL db
|
|
||||||
*/
|
|
||||||
yield (0, varDatabaseDbHandler_1.default)({
|
|
||||||
queryString: `CREATE${(indexType === null || indexType === void 0 ? void 0 : indexType.match(/fullText/i))
|
|
||||||
? " FULLTEXT"
|
|
||||||
: ""} INDEX \`${alias}\` ON \`${dbFullName}\`.\`${tableName}\`(${indexTableFields === null || indexTableFields === void 0 ? void 0 : indexTableFields.map((nm) => nm.value).map((nm) => `\`${nm}\``).join(",")}) COMMENT 'schema_index'`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const tableRecord = yield (0, check_table_record_1.default)({
|
||||||
|
dbFullName,
|
||||||
|
dbSchema,
|
||||||
|
tableSchema: table,
|
||||||
|
dbRecord: recordedDbEntry,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description Check all children databases
|
* @description Check all children databases
|
2
dist/package-shared/shell/utils/dbHandler.js
vendored
2
dist/package-shared/shell/utils/dbHandler.js
vendored
@ -32,7 +32,7 @@ function dbHandler(_a) {
|
|||||||
results = yield CONNECTION.query(query);
|
results = yield CONNECTION.query(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch (error) {
|
||||||
if (process.env.FIRST_RUN) {
|
if (process.env.FIRST_RUN) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
290
dist/package-shared/types/dsql.d.ts
vendored
Normal file
290
dist/package-shared/types/dsql.d.ts
vendored
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
export declare const DsqlTables: readonly ["users", "mariadb_users", "api_keys", "invitations", "user_users", "delegated_user_tables", "user_databases", "user_database_tables", "user_media", "delegated_users", "unsubscribes", "notifications", "docs_pages", "docs_page_extra_links", "deleted_api_keys", "servers"];
|
||||||
|
export type DSQL_DATASQUIREL_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
first_name?: string;
|
||||||
|
last_name?: string;
|
||||||
|
uid?: string;
|
||||||
|
email?: string;
|
||||||
|
user_type?: string;
|
||||||
|
user_priviledge?: number;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
image?: string;
|
||||||
|
image_thumbnail?: string;
|
||||||
|
social_login?: number;
|
||||||
|
social_platform?: string;
|
||||||
|
social_id?: string;
|
||||||
|
mariadb_user?: string;
|
||||||
|
mariadb_host?: string;
|
||||||
|
mariadb_pass?: string;
|
||||||
|
disk_usage_in_mb?: number;
|
||||||
|
verification_status?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_MARIADB_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
username?: string;
|
||||||
|
host?: string;
|
||||||
|
password?: string;
|
||||||
|
primary?: number;
|
||||||
|
grants?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_API_KEYS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
name?: string;
|
||||||
|
slug?: string;
|
||||||
|
key?: string;
|
||||||
|
scope?: string;
|
||||||
|
csrf?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_INVITATIONS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
inviting_user_id?: number;
|
||||||
|
invited_user_email?: string;
|
||||||
|
invitation_status?: string;
|
||||||
|
database_access?: string;
|
||||||
|
priviledge?: string;
|
||||||
|
db_tables_data?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_USER_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
invited_user_id?: number;
|
||||||
|
database?: string;
|
||||||
|
database_access?: string;
|
||||||
|
first_name?: string;
|
||||||
|
last_name?: string;
|
||||||
|
email?: string;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
phone?: string;
|
||||||
|
user_type?: string;
|
||||||
|
user_priviledge?: string;
|
||||||
|
image?: string;
|
||||||
|
image_thumbnail?: string;
|
||||||
|
city?: string;
|
||||||
|
state?: string;
|
||||||
|
country?: string;
|
||||||
|
zip_code?: string;
|
||||||
|
address?: string;
|
||||||
|
social_login?: number;
|
||||||
|
social_platform?: string;
|
||||||
|
social_id?: string;
|
||||||
|
verification_status?: number;
|
||||||
|
more_user_data?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_DELEGATED_USER_TABLES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
delegated_user_id?: number;
|
||||||
|
root_user_id?: number;
|
||||||
|
database?: string;
|
||||||
|
table?: string;
|
||||||
|
priviledge?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_USER_DATABASES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
db_name?: string;
|
||||||
|
db_slug?: string;
|
||||||
|
db_full_name?: string;
|
||||||
|
db_image?: string;
|
||||||
|
db_description?: string;
|
||||||
|
remote_connected?: number;
|
||||||
|
remote_connection_type?: string;
|
||||||
|
remote_db_full_name?: string;
|
||||||
|
remote_connection_host?: string;
|
||||||
|
remote_connection_key?: string;
|
||||||
|
active_clone?: number;
|
||||||
|
active_clone_parent_db?: string;
|
||||||
|
active_data?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_USER_DATABASE_TABLES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
db_id?: number;
|
||||||
|
db_slug?: string;
|
||||||
|
table_name?: string;
|
||||||
|
table_slug?: string;
|
||||||
|
table_description?: string;
|
||||||
|
child_table?: number;
|
||||||
|
child_table_parent_database?: string;
|
||||||
|
child_table_parent_table?: string;
|
||||||
|
active_data?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_USER_MEDIA = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
media_name?: string;
|
||||||
|
folder?: string;
|
||||||
|
media_url?: string;
|
||||||
|
media_thumbnail_url?: string;
|
||||||
|
media_path?: string;
|
||||||
|
media_thumbnail_path?: string;
|
||||||
|
media_type?: string;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
size?: number;
|
||||||
|
private?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_DELEGATED_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
delegated_user_id?: number;
|
||||||
|
permissions?: string;
|
||||||
|
permission_level_code?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_UNSUBSCRIBES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
email?: string;
|
||||||
|
type?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_NOTIFICATIONS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
title?: string;
|
||||||
|
message?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_DOCS_PAGES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
title?: string;
|
||||||
|
slug?: string;
|
||||||
|
description?: string;
|
||||||
|
content?: string;
|
||||||
|
text_content?: string;
|
||||||
|
level?: number;
|
||||||
|
page_order?: number;
|
||||||
|
parent_id?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_DOCS_PAGE_EXTRA_LINKS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
docs_page_id?: number;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
url?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_DELETED_API_KEYS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
key?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
||||||
|
export type DSQL_DATASQUIREL_SERVERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
server_id?: number;
|
||||||
|
ip?: string;
|
||||||
|
ssh_user?: string;
|
||||||
|
ssh_port?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
};
|
21
dist/package-shared/types/dsql.js
vendored
Normal file
21
dist/package-shared/types/dsql.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.DsqlTables = void 0;
|
||||||
|
exports.DsqlTables = [
|
||||||
|
"users",
|
||||||
|
"mariadb_users",
|
||||||
|
"api_keys",
|
||||||
|
"invitations",
|
||||||
|
"user_users",
|
||||||
|
"delegated_user_tables",
|
||||||
|
"user_databases",
|
||||||
|
"user_database_tables",
|
||||||
|
"user_media",
|
||||||
|
"delegated_users",
|
||||||
|
"unsubscribes",
|
||||||
|
"notifications",
|
||||||
|
"docs_pages",
|
||||||
|
"docs_page_extra_links",
|
||||||
|
"deleted_api_keys",
|
||||||
|
"servers",
|
||||||
|
];
|
8
dist/package-shared/utils/backend/import-mariadb-database.d.ts
vendored
Normal file
8
dist/package-shared/utils/backend/import-mariadb-database.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export type ExportMariaDBDatabaseParam = {
|
||||||
|
dbFullName: string;
|
||||||
|
targetFilePath: string;
|
||||||
|
mariadbUser?: string;
|
||||||
|
mariadbHost?: string;
|
||||||
|
mariadbPass?: string;
|
||||||
|
};
|
||||||
|
export default function importMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }: ExportMariaDBDatabaseParam): Promise<string | Buffer<ArrayBufferLike>>;
|
37
dist/package-shared/utils/backend/import-mariadb-database.js
vendored
Normal file
37
dist/package-shared/utils/backend/import-mariadb-database.js
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
"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;
|
||||||
|
});
|
||||||
|
}
|
@ -19,5 +19,7 @@ export default function grabDirNames(param?: Param): {
|
|||||||
userPrivateTempJSONSchemaFilePath: string | undefined;
|
userPrivateTempJSONSchemaFilePath: string | undefined;
|
||||||
userPrivateDbExportZipFileName: string;
|
userPrivateDbExportZipFileName: string;
|
||||||
userPrivateDbExportZipFilePath: string | undefined;
|
userPrivateDbExportZipFilePath: string | undefined;
|
||||||
|
userPrivateDbImportZipFileName: string;
|
||||||
|
userPrivateDbImportZipFilePath: string | undefined;
|
||||||
};
|
};
|
||||||
export {};
|
export {};
|
||||||
|
@ -15,7 +15,7 @@ function grabDirNames(param) {
|
|||||||
if (!schemasDir)
|
if (!schemasDir)
|
||||||
throw new Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");
|
throw new Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");
|
||||||
const pakageSharedDir = path_1.default.join(appDir, `package-shared`);
|
const pakageSharedDir = path_1.default.join(appDir, `package-shared`);
|
||||||
const mainDbTypeDefFile = path_1.default.join(appDir, `types/dsql.ts`);
|
const mainDbTypeDefFile = path_1.default.join(pakageSharedDir, `types/dsql.ts`);
|
||||||
const mainShemaJSONFilePath = path_1.default.join(schemasDir, `main.json`);
|
const mainShemaJSONFilePath = path_1.default.join(schemasDir, `main.json`);
|
||||||
const defaultTableFieldsJSONFilePath = path_1.default.join(pakageSharedDir, `data/defaultFields.json`);
|
const defaultTableFieldsJSONFilePath = path_1.default.join(pakageSharedDir, `data/defaultFields.json`);
|
||||||
const usersSchemaDir = path_1.default.join(schemasDir, `users`);
|
const usersSchemaDir = path_1.default.join(schemasDir, `users`);
|
||||||
@ -46,6 +46,10 @@ function grabDirNames(param) {
|
|||||||
const userPrivateDbExportZipFilePath = userPrivateSQLExportsDir
|
const userPrivateDbExportZipFilePath = userPrivateSQLExportsDir
|
||||||
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
const userPrivateDbImportZipFileName = `db-export.zip`;
|
||||||
|
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
|
||||||
|
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
||||||
|
: undefined;
|
||||||
return {
|
return {
|
||||||
schemasDir,
|
schemasDir,
|
||||||
userDirPath,
|
userDirPath,
|
||||||
@ -62,5 +66,7 @@ function grabDirNames(param) {
|
|||||||
userPrivateTempJSONSchemaFilePath,
|
userPrivateTempJSONSchemaFilePath,
|
||||||
userPrivateDbExportZipFileName,
|
userPrivateDbExportZipFileName,
|
||||||
userPrivateDbExportZipFilePath,
|
userPrivateDbExportZipFilePath,
|
||||||
|
userPrivateDbImportZipFileName,
|
||||||
|
userPrivateDbImportZipFilePath,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
6
dist/package-shared/utils/backend/names/replace-datasquirel-db-name.d.ts
vendored
Normal file
6
dist/package-shared/utils/backend/names/replace-datasquirel-db-name.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
type Param = {
|
||||||
|
str: string;
|
||||||
|
userId: string | number;
|
||||||
|
};
|
||||||
|
export default function replaceDatasquirelDbName({ str, userId, }: Param): string;
|
||||||
|
export {};
|
9
dist/package-shared/utils/backend/names/replace-datasquirel-db-name.js
vendored
Normal file
9
dist/package-shared/utils/backend/names/replace-datasquirel-db-name.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
"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}_`;
|
||||||
|
return str.replace(userNameRegex, newPrefix);
|
||||||
|
}
|
55
dist/package-shared/utils/console-colors.d.ts
vendored
Normal file
55
dist/package-shared/utils/console-colors.d.ts
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
declare const consoleColors: {
|
||||||
|
Reset: string;
|
||||||
|
Bright: string;
|
||||||
|
Dim: string;
|
||||||
|
Underscore: string;
|
||||||
|
Blink: string;
|
||||||
|
Reverse: string;
|
||||||
|
Hidden: string;
|
||||||
|
FgBlack: string;
|
||||||
|
FgRed: string;
|
||||||
|
FgGreen: string;
|
||||||
|
FgYellow: string;
|
||||||
|
FgBlue: string;
|
||||||
|
FgMagenta: string;
|
||||||
|
FgCyan: string;
|
||||||
|
FgWhite: string;
|
||||||
|
FgGray: string;
|
||||||
|
BgBlack: string;
|
||||||
|
BgRed: string;
|
||||||
|
BgGreen: string;
|
||||||
|
BgYellow: string;
|
||||||
|
BgBlue: string;
|
||||||
|
BgMagenta: string;
|
||||||
|
BgCyan: string;
|
||||||
|
BgWhite: string;
|
||||||
|
BgGray: string;
|
||||||
|
};
|
||||||
|
export default consoleColors;
|
||||||
|
export declare const ccol: {
|
||||||
|
Reset: string;
|
||||||
|
Bright: string;
|
||||||
|
Dim: string;
|
||||||
|
Underscore: string;
|
||||||
|
Blink: string;
|
||||||
|
Reverse: string;
|
||||||
|
Hidden: string;
|
||||||
|
FgBlack: string;
|
||||||
|
FgRed: string;
|
||||||
|
FgGreen: string;
|
||||||
|
FgYellow: string;
|
||||||
|
FgBlue: string;
|
||||||
|
FgMagenta: string;
|
||||||
|
FgCyan: string;
|
||||||
|
FgWhite: string;
|
||||||
|
FgGray: string;
|
||||||
|
BgBlack: string;
|
||||||
|
BgRed: string;
|
||||||
|
BgGreen: string;
|
||||||
|
BgYellow: string;
|
||||||
|
BgBlue: string;
|
||||||
|
BgMagenta: string;
|
||||||
|
BgCyan: string;
|
||||||
|
BgWhite: string;
|
||||||
|
BgGray: string;
|
||||||
|
};
|
32
dist/package-shared/utils/console-colors.js
vendored
Normal file
32
dist/package-shared/utils/console-colors.js
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.ccol = void 0;
|
||||||
|
const consoleColors = {
|
||||||
|
Reset: "\x1b[0m",
|
||||||
|
Bright: "\x1b[1m",
|
||||||
|
Dim: "\x1b[2m",
|
||||||
|
Underscore: "\x1b[4m",
|
||||||
|
Blink: "\x1b[5m",
|
||||||
|
Reverse: "\x1b[7m",
|
||||||
|
Hidden: "\x1b[8m",
|
||||||
|
FgBlack: "\x1b[30m",
|
||||||
|
FgRed: "\x1b[31m",
|
||||||
|
FgGreen: "\x1b[32m",
|
||||||
|
FgYellow: "\x1b[33m",
|
||||||
|
FgBlue: "\x1b[34m",
|
||||||
|
FgMagenta: "\x1b[35m",
|
||||||
|
FgCyan: "\x1b[36m",
|
||||||
|
FgWhite: "\x1b[37m",
|
||||||
|
FgGray: "\x1b[90m",
|
||||||
|
BgBlack: "\x1b[40m",
|
||||||
|
BgRed: "\x1b[41m",
|
||||||
|
BgGreen: "\x1b[42m",
|
||||||
|
BgYellow: "\x1b[43m",
|
||||||
|
BgBlue: "\x1b[44m",
|
||||||
|
BgMagenta: "\x1b[45m",
|
||||||
|
BgCyan: "\x1b[46m",
|
||||||
|
BgWhite: "\x1b[47m",
|
||||||
|
BgGray: "\x1b[100m",
|
||||||
|
};
|
||||||
|
exports.default = consoleColors;
|
||||||
|
exports.ccol = consoleColors;
|
25
dist/package-shared/utils/logging/debug-log.d.ts
vendored
Normal file
25
dist/package-shared/utils/logging/debug-log.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
declare const LogTypes: readonly ["error", "warning"];
|
||||||
|
type Param = {
|
||||||
|
/**
|
||||||
|
* data to be logged.
|
||||||
|
*/
|
||||||
|
log: any;
|
||||||
|
/**
|
||||||
|
* Log Title. Could be name of function or name of variable
|
||||||
|
*/
|
||||||
|
title?: string;
|
||||||
|
/**
|
||||||
|
* Label for the log
|
||||||
|
*/
|
||||||
|
label?: string;
|
||||||
|
/**
|
||||||
|
* Log type. `error` or `warning` or default
|
||||||
|
*/
|
||||||
|
type?: (typeof LogTypes)[number];
|
||||||
|
/**
|
||||||
|
* Whether to add a time stamp
|
||||||
|
*/
|
||||||
|
addTime?: boolean;
|
||||||
|
};
|
||||||
|
export default function debugLog({ log, label, title, type, addTime }: Param): void;
|
||||||
|
export {};
|
33
dist/package-shared/utils/logging/debug-log.js
vendored
Normal file
33
dist/package-shared/utils/logging/debug-log.js
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = debugLog;
|
||||||
|
const console_colors_1 = require("../console-colors");
|
||||||
|
const LogTypes = ["error", "warning"];
|
||||||
|
function debugLog({ log, label, title, type, addTime }) {
|
||||||
|
const logType = (() => {
|
||||||
|
switch (type) {
|
||||||
|
case "error":
|
||||||
|
return console_colors_1.ccol.FgRed;
|
||||||
|
case "warning":
|
||||||
|
return console_colors_1.ccol.FgYellow;
|
||||||
|
default:
|
||||||
|
return console_colors_1.ccol.FgGreen;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
let logTxt = `${logType}DEBUG${console_colors_1.ccol.Reset}:::`;
|
||||||
|
const date = new Date();
|
||||||
|
const time = date.toLocaleTimeString("en-US", {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric",
|
||||||
|
second: "numeric",
|
||||||
|
hour12: true,
|
||||||
|
});
|
||||||
|
const logTime = `${date.toLocaleDateString()}][${time}`;
|
||||||
|
if (addTime)
|
||||||
|
logTxt = `${console_colors_1.ccol.BgWhite}[${logTime}]${console_colors_1.ccol.Reset} ` + logTxt;
|
||||||
|
if (title)
|
||||||
|
logTxt += `${console_colors_1.ccol.FgBlue}${title}${console_colors_1.ccol.Reset}::`;
|
||||||
|
if (label)
|
||||||
|
logTxt += `${console_colors_1.ccol.FgWhite}${console_colors_1.ccol.Bright}${label}${console_colors_1.ccol.Reset} =>`;
|
||||||
|
console.log(logTxt, log);
|
||||||
|
}
|
2
index.ts
2
index.ts
@ -45,6 +45,7 @@ import validateTempEmailCode from "./package-shared/actions/users/validate-temp-
|
|||||||
import deleteUser from "./package-shared/actions/users/delete-user";
|
import deleteUser from "./package-shared/actions/users/delete-user";
|
||||||
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
|
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
|
||||||
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
|
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
|
||||||
|
import debugLog from "./package-shared/utils/logging/debug-log";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User Functions Object
|
* User Functions Object
|
||||||
@ -113,6 +114,7 @@ const datasquirel = {
|
|||||||
parseCookies,
|
parseCookies,
|
||||||
httpRequest,
|
httpRequest,
|
||||||
connDbHandler,
|
connDbHandler,
|
||||||
|
debugLog,
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Run Crud actions `get`, `insert`, `update`, `delete`
|
* Run Crud actions `get`, `insert`, `update`, `delete`
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
GetReturn,
|
GetReturn,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
import apiGetGrabQueryAndValues from "../utils/grab-query-and-values";
|
import apiGetGrabQueryAndValues from "../utils/grab-query-and-values";
|
||||||
|
import debugLog from "../utils/logging/debug-log";
|
||||||
|
|
||||||
type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
|
type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -43,6 +44,10 @@ export default async function get<
|
|||||||
const grabedHostNames = grabHostNames();
|
const grabedHostNames = grabHostNames();
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
|
function debugFn(log: any, label?: string) {
|
||||||
|
debugLog({ log, addTime: true, title: "apiGet", label });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for local DB settings
|
* Check for local DB settings
|
||||||
*
|
*
|
||||||
@ -62,7 +67,7 @@ export default async function get<
|
|||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:Running Locally ...");
|
debugFn("Running Locally ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
return await apiGet({
|
return await apiGet({
|
||||||
@ -96,13 +101,13 @@ export default async function get<
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:queryObject", queryObject);
|
debugFn(queryObject, "queryObject");
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryString = serializeQuery({ ...queryObject });
|
const queryString = serializeQuery({ ...queryObject });
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:queryString", queryString);
|
debugFn(queryString, "queryString");
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = `/api/query/${
|
let path = `/api/query/${
|
||||||
@ -110,7 +115,7 @@ export default async function get<
|
|||||||
}/get${queryString}`;
|
}/get${queryString}`;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("apiGet:path", path);
|
debugFn(path, "path");
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestObject: https.RequestOptions = {
|
const requestObject: https.RequestOptions = {
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
DSQL_DatabaseSchemaType,
|
DSQL_DatabaseSchemaType,
|
||||||
PackageUserLoginRequestBody,
|
PackageUserLoginRequestBody,
|
||||||
} from "../../types";
|
} from "../../types";
|
||||||
|
import debugLog from "../../utils/logging/debug-log";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
key?: string;
|
key?: string;
|
||||||
@ -73,6 +74,10 @@ export default async function loginUser({
|
|||||||
const finalEncryptionSalt =
|
const finalEncryptionSalt =
|
||||||
encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
||||||
|
|
||||||
|
function debugFn(log: any, label?: string) {
|
||||||
|
debugLog({ log, addTime: true, title: "loginUser", label });
|
||||||
|
}
|
||||||
|
|
||||||
if (!finalEncryptionKey?.match(/.{8,}/)) {
|
if (!finalEncryptionKey?.match(/.{8,}/)) {
|
||||||
console.log("Encryption key is invalid");
|
console.log("Encryption key is invalid");
|
||||||
return {
|
return {
|
||||||
@ -81,6 +86,7 @@ export default async function loginUser({
|
|||||||
msg: "Encryption key is invalid",
|
msg: "Encryption key is invalid",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!finalEncryptionSalt?.match(/.{8,}/)) {
|
if (!finalEncryptionSalt?.match(/.{8,}/)) {
|
||||||
console.log("Encryption salt is invalid");
|
console.log("Encryption salt is invalid");
|
||||||
return {
|
return {
|
||||||
@ -210,7 +216,7 @@ export default async function loginUser({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log(`loginUser:httpResponse:`, httpResponse);
|
debugFn(httpResponse, "httpResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (httpResponse?.success) {
|
if (httpResponse?.success) {
|
||||||
@ -244,9 +250,9 @@ export default async function loginUser({
|
|||||||
const csrfName = cookieNames.csrfCookieName;
|
const csrfName = cookieNames.csrfCookieName;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log(`loginUser:authKeyName:`, authKeyName);
|
debugFn(authKeyName, "authKeyName");
|
||||||
console.log(`loginUser:csrfName:`, csrfName);
|
debugFn(csrfName, "csrfName");
|
||||||
console.log(`loginUser:encryptedPayload:`, encryptedPayload);
|
debugFn(encryptedPayload, "encryptedPayload");
|
||||||
}
|
}
|
||||||
|
|
||||||
response?.setHeader("Set-Cookie", [
|
response?.setHeader("Set-Cookie", [
|
||||||
@ -255,7 +261,7 @@ export default async function loginUser({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log(`loginUser:Response Sent!`);
|
debugFn("Response Sent!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import { deleteAuthFile } from "../../functions/backend/auth/write-auth-files";
|
|||||||
import parseCookies from "../../utils/backend/parseCookies";
|
import parseCookies from "../../utils/backend/parseCookies";
|
||||||
import { DATASQUIREL_LoggedInUser } from "../../types";
|
import { DATASQUIREL_LoggedInUser } from "../../types";
|
||||||
import grabHostNames from "../../utils/grab-host-names";
|
import grabHostNames from "../../utils/grab-host-names";
|
||||||
|
import debugLog from "../../utils/logging/debug-log";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
encryptedUserString?: string;
|
encryptedUserString?: string;
|
||||||
@ -48,8 +49,12 @@ export default function logoutUser({
|
|||||||
userId: user_id,
|
userId: user_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function debugFn(log: any, label?: string) {
|
||||||
|
debugLog({ log, addTime: true, title: "logoutUser", label });
|
||||||
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("logoutUser:cookieNames", cookieNames);
|
debugFn(cookieNames, "cookieNames");
|
||||||
}
|
}
|
||||||
|
|
||||||
const authKeyName = cookieNames.keyCookieName;
|
const authKeyName = cookieNames.keyCookieName;
|
||||||
@ -84,7 +89,7 @@ export default function logoutUser({
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("logoutUser:decryptedUserJSON", decryptedUserJSON);
|
debugFn(decryptedUserJSON, "decryptedUserJSON");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!decryptedUserJSON) throw new Error("Invalid User");
|
if (!decryptedUserJSON) throw new Error("Invalid User");
|
||||||
|
@ -36,10 +36,3 @@ export default function setUserSchemaData({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
|
72
package-shared/shell/createDbFromSchema/check-db-record.ts
Normal file
72
package-shared/shell/createDbFromSchema/check-db-record.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import varDatabaseDbHandler from "../utils/varDatabaseDbHandler";
|
||||||
|
import { DSQL_DatabaseSchemaType, PostInsertReturn } from "../../types";
|
||||||
|
import { DSQL_DATASQUIREL_USER_DATABASES } from "../../types/dsql";
|
||||||
|
import numberfy from "../../utils/numberfy";
|
||||||
|
import addDbEntry from "../../functions/backend/db/addDbEntry";
|
||||||
|
|
||||||
|
type Param = {
|
||||||
|
userId?: number | string | null;
|
||||||
|
dbSchema: DSQL_DatabaseSchemaType;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* # Create database from Schema Function
|
||||||
|
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||||
|
*/
|
||||||
|
export default async function checkDbRecordCreateDbSchema({
|
||||||
|
userId,
|
||||||
|
dbSchema,
|
||||||
|
}: Param): Promise<DSQL_DATASQUIREL_USER_DATABASES | undefined> {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
dbFullName,
|
||||||
|
dbName,
|
||||||
|
dbSlug,
|
||||||
|
dbDescription,
|
||||||
|
dbImage,
|
||||||
|
childDatabase,
|
||||||
|
childDatabaseDbFullName,
|
||||||
|
} = dbSchema;
|
||||||
|
|
||||||
|
let recordedDbEntryArray = userId
|
||||||
|
? await varDatabaseDbHandler({
|
||||||
|
queryString: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
||||||
|
queryValuesArray: [dbFullName],
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
let recordedDbEntry: DSQL_DATASQUIREL_USER_DATABASES | undefined =
|
||||||
|
recordedDbEntryArray?.[0];
|
||||||
|
|
||||||
|
if (!recordedDbEntry?.id && userId) {
|
||||||
|
const newDbEntryObj: DSQL_DATASQUIREL_USER_DATABASES = {
|
||||||
|
user_id: numberfy(userId),
|
||||||
|
db_name: dbName,
|
||||||
|
db_slug: dbSlug,
|
||||||
|
db_full_name: dbFullName,
|
||||||
|
db_description: dbDescription,
|
||||||
|
db_image: dbImage,
|
||||||
|
active_clone: childDatabase ? 1 : undefined,
|
||||||
|
active_clone_parent_db: childDatabaseDbFullName,
|
||||||
|
};
|
||||||
|
|
||||||
|
const newDbEntry = (await addDbEntry({
|
||||||
|
data: newDbEntryObj,
|
||||||
|
tableName: "user_databases",
|
||||||
|
forceLocal: true,
|
||||||
|
})) as PostInsertReturn;
|
||||||
|
|
||||||
|
if (newDbEntry.insertId) {
|
||||||
|
recordedDbEntryArray = await varDatabaseDbHandler({
|
||||||
|
queryString: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
||||||
|
queryValuesArray: [dbFullName],
|
||||||
|
});
|
||||||
|
recordedDbEntry = recordedDbEntryArray?.[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return recordedDbEntry;
|
||||||
|
} catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
115
package-shared/shell/createDbFromSchema/check-table-record.ts
Normal file
115
package-shared/shell/createDbFromSchema/check-table-record.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import varDatabaseDbHandler from "../utils/varDatabaseDbHandler";
|
||||||
|
import dbHandler from "../utils/dbHandler";
|
||||||
|
import {
|
||||||
|
DSQL_DatabaseSchemaType,
|
||||||
|
DSQL_TableSchemaType,
|
||||||
|
PostInsertReturn,
|
||||||
|
} from "../../types";
|
||||||
|
import {
|
||||||
|
DSQL_DATASQUIREL_USER_DATABASE_TABLES,
|
||||||
|
DSQL_DATASQUIREL_USER_DATABASES,
|
||||||
|
DsqlTables,
|
||||||
|
} from "../../types/dsql";
|
||||||
|
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||||
|
import numberfy from "../../utils/numberfy";
|
||||||
|
import addDbEntry from "../../functions/backend/db/addDbEntry";
|
||||||
|
|
||||||
|
type Param = {
|
||||||
|
userId?: number | string | null;
|
||||||
|
tableSchema?: DSQL_TableSchemaType;
|
||||||
|
dbSchema: DSQL_DatabaseSchemaType[];
|
||||||
|
dbRecord?: DSQL_DATASQUIREL_USER_DATABASES;
|
||||||
|
dbFullName: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* # Create database from Schema Function
|
||||||
|
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||||
|
*/
|
||||||
|
export default async function checkTableRecordCreateDbSchema({
|
||||||
|
userId,
|
||||||
|
tableSchema,
|
||||||
|
dbSchema,
|
||||||
|
dbRecord,
|
||||||
|
dbFullName,
|
||||||
|
}: Param): Promise<DSQL_DATASQUIREL_USER_DATABASE_TABLES | undefined> {
|
||||||
|
if (!tableSchema) return undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const queryObj = sqlGenerator<DSQL_DATASQUIREL_USER_DATABASE_TABLES>({
|
||||||
|
tableName: "user_database_tables" as (typeof DsqlTables)[number],
|
||||||
|
genObject: {
|
||||||
|
query: {
|
||||||
|
db_id: {
|
||||||
|
value: String(dbRecord?.id),
|
||||||
|
},
|
||||||
|
table_slug: {
|
||||||
|
value: tableSchema.tableName,
|
||||||
|
},
|
||||||
|
user_id: {
|
||||||
|
value: String(userId),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dbFullName: "datasquirel",
|
||||||
|
});
|
||||||
|
|
||||||
|
let recordedTableEntryArray = userId
|
||||||
|
? await varDatabaseDbHandler({
|
||||||
|
queryString: queryObj?.string || "",
|
||||||
|
queryValuesArray: queryObj?.values,
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
let recordedTableEntry:
|
||||||
|
| DSQL_DATASQUIREL_USER_DATABASE_TABLES
|
||||||
|
| undefined = recordedTableEntryArray?.[0];
|
||||||
|
|
||||||
|
if (!recordedTableEntry?.id && userId) {
|
||||||
|
const newTableInsertObject: DSQL_DATASQUIREL_USER_DATABASE_TABLES =
|
||||||
|
{
|
||||||
|
user_id: numberfy(userId),
|
||||||
|
db_id: dbRecord?.id,
|
||||||
|
db_slug: dbRecord?.db_slug,
|
||||||
|
table_name: tableSchema.tableFullName,
|
||||||
|
table_slug: tableSchema.tableName,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tableSchema?.childTable && tableSchema.childTableName) {
|
||||||
|
const parentDb = dbSchema.find(
|
||||||
|
(db) => db.dbFullName == tableSchema.childTableDbFullName
|
||||||
|
);
|
||||||
|
const parentDbTable = parentDb?.tables.find(
|
||||||
|
(tbl) => tbl.tableName == tableSchema.childTableName
|
||||||
|
);
|
||||||
|
if (parentDb && parentDbTable) {
|
||||||
|
newTableInsertObject["child_table"] = 1;
|
||||||
|
newTableInsertObject["child_table_parent_database"] =
|
||||||
|
parentDb.dbFullName;
|
||||||
|
newTableInsertObject["child_table_parent_table"] =
|
||||||
|
parentDbTable.tableName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newTableRecordEntry = (await addDbEntry({
|
||||||
|
data: newTableInsertObject,
|
||||||
|
tableName: "user_database_tables",
|
||||||
|
dbContext: "Master",
|
||||||
|
forceLocal: true,
|
||||||
|
})) as PostInsertReturn;
|
||||||
|
|
||||||
|
if (newTableRecordEntry.insertId) {
|
||||||
|
recordedTableEntryArray = await varDatabaseDbHandler({
|
||||||
|
queryString: queryObj?.string || "",
|
||||||
|
queryValuesArray: queryObj?.values,
|
||||||
|
});
|
||||||
|
|
||||||
|
recordedTableEntry = recordedTableEntryArray?.[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return recordedTableEntry;
|
||||||
|
} catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
59
package-shared/shell/createDbFromSchema/handle-indexes.ts
Normal file
59
package-shared/shell/createDbFromSchema/handle-indexes.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import varDatabaseDbHandler from "../utils/varDatabaseDbHandler";
|
||||||
|
import { DSQL_IndexSchemaType } from "../../types";
|
||||||
|
|
||||||
|
type Param = {
|
||||||
|
tableName: string;
|
||||||
|
dbFullName: string;
|
||||||
|
indexes: DSQL_IndexSchemaType[];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle DATASQUIREL Table Indexes
|
||||||
|
* ===================================================
|
||||||
|
* @description Iterate through each datasquirel schema
|
||||||
|
* table index(if available), and perform operations
|
||||||
|
*/
|
||||||
|
export default async function handleIndexescreateDbFromSchema({
|
||||||
|
dbFullName,
|
||||||
|
tableName,
|
||||||
|
indexes,
|
||||||
|
}: Param) {
|
||||||
|
for (let g = 0; g < indexes.length; g++) {
|
||||||
|
const { indexType, indexName, indexTableFields, alias } = indexes[g];
|
||||||
|
|
||||||
|
if (!alias?.match(/./)) continue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Check for existing Index in MYSQL db
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* @type {import("../../types").DSQL_MYSQL_SHOW_INDEXES_Type[]}
|
||||||
|
* @description All indexes from MYSQL db
|
||||||
|
*/ // @ts-ignore
|
||||||
|
const allExistingIndexes: import("../../types").DSQL_MYSQL_SHOW_INDEXES_Type[] =
|
||||||
|
await varDatabaseDbHandler({
|
||||||
|
queryString: `SHOW INDEXES FROM \`${dbFullName}\`.\`${tableName}\``,
|
||||||
|
});
|
||||||
|
|
||||||
|
const existingKeyInDb = allExistingIndexes.filter(
|
||||||
|
(indexObject) => indexObject.Key_name === alias
|
||||||
|
);
|
||||||
|
if (!existingKeyInDb[0])
|
||||||
|
throw new Error("This Index Does not Exist");
|
||||||
|
} catch (error) {
|
||||||
|
/**
|
||||||
|
* @description Create new index if determined that it
|
||||||
|
* doesn't exist in MYSQL db
|
||||||
|
*/
|
||||||
|
await varDatabaseDbHandler({
|
||||||
|
queryString: `CREATE${
|
||||||
|
indexType?.match(/fullText/i) ? " FULLTEXT" : ""
|
||||||
|
} INDEX \`${alias}\` ON \`${dbFullName}\`.\`${tableName}\`(${indexTableFields
|
||||||
|
?.map((nm) => nm.value)
|
||||||
|
.map((nm) => `\`${nm}\``)
|
||||||
|
.join(",")}) COMMENT 'schema_index'`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +1,21 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
import noDatabaseDbHandler from "./utils/noDatabaseDbHandler";
|
import noDatabaseDbHandler from "../utils/noDatabaseDbHandler";
|
||||||
import varDatabaseDbHandler from "./utils/varDatabaseDbHandler";
|
import varDatabaseDbHandler from "../utils/varDatabaseDbHandler";
|
||||||
import createTable from "./utils/createTable";
|
import createTable from "../utils/createTable";
|
||||||
import updateTable from "./utils/updateTable";
|
import updateTable from "../utils/updateTable";
|
||||||
import dbHandler from "./utils/dbHandler";
|
import dbHandler from "../utils/dbHandler";
|
||||||
import EJSON from "../utils/ejson";
|
import EJSON from "../../utils/ejson";
|
||||||
import { DSQL_DatabaseSchemaType } from "../types";
|
import { DSQL_DatabaseSchemaType } from "../../types";
|
||||||
import grabDirNames from "../utils/backend/names/grab-dir-names";
|
import grabDirNames from "../../utils/backend/names/grab-dir-names";
|
||||||
|
import checkDbRecordCreateDbSchema from "./check-db-record";
|
||||||
|
import checkTableRecordCreateDbSchema from "./check-table-record";
|
||||||
|
import handleIndexescreateDbFromSchema from "./handle-indexes";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
userId?: number | string | null;
|
userId?: number | string | null;
|
||||||
targetDatabase?: string;
|
targetDatabase?: string;
|
||||||
dbSchemaData?: import("../types").DSQL_DatabaseSchemaType[];
|
dbSchemaData?: import("../../types").DSQL_DatabaseSchemaType[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,19 +44,15 @@ export default async function createDbFromSchema({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// await createDatabasesFromSchema(dbSchema);
|
|
||||||
|
|
||||||
for (let i = 0; i < dbSchema.length; i++) {
|
for (let i = 0; i < dbSchema.length; i++) {
|
||||||
const database: DSQL_DatabaseSchemaType = dbSchema[i];
|
const database: DSQL_DatabaseSchemaType = dbSchema[i];
|
||||||
|
|
||||||
const { dbFullName, tables, dbName, dbSlug, childrenDatabases } =
|
const { dbFullName, tables, dbSlug, childrenDatabases } = database;
|
||||||
database;
|
|
||||||
|
|
||||||
if (targetDatabase && dbFullName != targetDatabase) {
|
if (targetDatabase && dbFullName != targetDatabase) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {any} */
|
|
||||||
const dbCheck: any = await noDatabaseDbHandler(
|
const dbCheck: any = await noDatabaseDbHandler(
|
||||||
`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbFullName}'`
|
`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbFullName}'`
|
||||||
);
|
);
|
||||||
@ -64,16 +63,14 @@ export default async function createDbFromSchema({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Select all tables
|
|
||||||
* @type {any}
|
|
||||||
* @description Select All tables in target database
|
|
||||||
*/
|
|
||||||
const allTables: any = await noDatabaseDbHandler(
|
const allTables: any = await noDatabaseDbHandler(
|
||||||
`SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${dbFullName}'`
|
`SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${dbFullName}'`
|
||||||
);
|
);
|
||||||
|
|
||||||
// let tableDropped;
|
let recordedDbEntry = await checkDbRecordCreateDbSchema({
|
||||||
|
dbSchema: database,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
for (let tb = 0; tb < allTables.length; tb++) {
|
for (let tb = 0; tb < allTables.length; tb++) {
|
||||||
const { TABLE_NAME } = allTables[tb];
|
const { TABLE_NAME } = allTables[tb];
|
||||||
@ -115,15 +112,6 @@ export default async function createDbFromSchema({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const recordedDbEntryArray = userId
|
|
||||||
? await varDatabaseDbHandler({
|
|
||||||
queryString: `SELECT * FROM datasquirel.user_databases WHERE db_full_name = ?`,
|
|
||||||
queryValuesArray: [dbFullName],
|
|
||||||
})
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const recordedDbEntry = recordedDbEntryArray?.[0];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Iterate through each table and perform table actions
|
* @description Iterate through each table and perform table actions
|
||||||
*/
|
*/
|
||||||
@ -189,11 +177,7 @@ export default async function createDbFromSchema({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
} else {
|
} else {
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Create new Table if table doesnt exist
|
* @description Create new Table if table doesnt exist
|
||||||
*/
|
*/
|
||||||
@ -205,66 +189,28 @@ export default async function createDbFromSchema({
|
|||||||
recordedDbEntry,
|
recordedDbEntry,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (indexes && indexes[0]) {
|
/**
|
||||||
/**
|
* Handle DATASQUIREL Table Indexes
|
||||||
* Handle DATASQUIREL Table Indexes
|
* ===================================================
|
||||||
* ===================================================
|
* @description Iterate through each datasquirel schema
|
||||||
* @description Iterate through each datasquirel schema
|
* table index(if available), and perform operations
|
||||||
* table index(if available), and perform operations
|
*/
|
||||||
*/
|
if (indexes?.[0]) {
|
||||||
if (indexes && indexes[0]) {
|
handleIndexescreateDbFromSchema({
|
||||||
for (let g = 0; g < indexes.length; g++) {
|
dbFullName,
|
||||||
const {
|
indexes,
|
||||||
indexType,
|
tableName,
|
||||||
indexName,
|
});
|
||||||
indexTableFields,
|
|
||||||
alias,
|
|
||||||
} = indexes[g];
|
|
||||||
|
|
||||||
if (!alias?.match(/./)) continue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Check for existing Index in MYSQL db
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
/**
|
|
||||||
* @type {import("../types").DSQL_MYSQL_SHOW_INDEXES_Type[]}
|
|
||||||
* @description All indexes from MYSQL db
|
|
||||||
*/ // @ts-ignore
|
|
||||||
const allExistingIndexes: import("../types").DSQL_MYSQL_SHOW_INDEXES_Type[] =
|
|
||||||
await varDatabaseDbHandler({
|
|
||||||
queryString: `SHOW INDEXES FROM \`${dbFullName}\`.\`${tableName}\``,
|
|
||||||
});
|
|
||||||
|
|
||||||
const existingKeyInDb =
|
|
||||||
allExistingIndexes.filter(
|
|
||||||
(indexObject) =>
|
|
||||||
indexObject.Key_name === alias
|
|
||||||
);
|
|
||||||
if (!existingKeyInDb[0])
|
|
||||||
throw new Error(
|
|
||||||
"This Index Does not Exist"
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
/**
|
|
||||||
* @description Create new index if determined that it
|
|
||||||
* doesn't exist in MYSQL db
|
|
||||||
*/
|
|
||||||
await varDatabaseDbHandler({
|
|
||||||
queryString: `CREATE${
|
|
||||||
indexType?.match(/fullText/i)
|
|
||||||
? " FULLTEXT"
|
|
||||||
: ""
|
|
||||||
} INDEX \`${alias}\` ON \`${dbFullName}\`.\`${tableName}\`(${indexTableFields
|
|
||||||
?.map((nm) => nm.value)
|
|
||||||
.map((nm) => `\`${nm}\``)
|
|
||||||
.join(",")}) COMMENT 'schema_index'`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tableRecord = await checkTableRecordCreateDbSchema({
|
||||||
|
dbFullName,
|
||||||
|
dbSchema,
|
||||||
|
tableSchema: table,
|
||||||
|
dbRecord: recordedDbEntry,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -25,7 +25,7 @@ export default async function dbHandler({
|
|||||||
} else {
|
} else {
|
||||||
results = await CONNECTION.query(query);
|
results = await CONNECTION.query(query);
|
||||||
}
|
}
|
||||||
} catch (/** @type {any} */ error: any) {
|
} catch (error: any) {
|
||||||
if (process.env.FIRST_RUN) {
|
if (process.env.FIRST_RUN) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
323
package-shared/types/dsql.ts
Normal file
323
package-shared/types/dsql.ts
Normal file
@ -0,0 +1,323 @@
|
|||||||
|
export const DsqlTables = [
|
||||||
|
"users",
|
||||||
|
"mariadb_users",
|
||||||
|
"api_keys",
|
||||||
|
"invitations",
|
||||||
|
"user_users",
|
||||||
|
"delegated_user_tables",
|
||||||
|
"user_databases",
|
||||||
|
"user_database_tables",
|
||||||
|
"user_media",
|
||||||
|
"delegated_users",
|
||||||
|
"unsubscribes",
|
||||||
|
"notifications",
|
||||||
|
"docs_pages",
|
||||||
|
"docs_page_extra_links",
|
||||||
|
"deleted_api_keys",
|
||||||
|
"servers",
|
||||||
|
] as const
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
first_name?: string;
|
||||||
|
last_name?: string;
|
||||||
|
uid?: string;
|
||||||
|
email?: string;
|
||||||
|
user_type?: string;
|
||||||
|
user_priviledge?: number;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
image?: string;
|
||||||
|
image_thumbnail?: string;
|
||||||
|
social_login?: number;
|
||||||
|
social_platform?: string;
|
||||||
|
social_id?: string;
|
||||||
|
mariadb_user?: string;
|
||||||
|
mariadb_host?: string;
|
||||||
|
mariadb_pass?: string;
|
||||||
|
disk_usage_in_mb?: number;
|
||||||
|
verification_status?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_MARIADB_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
username?: string;
|
||||||
|
host?: string;
|
||||||
|
password?: string;
|
||||||
|
primary?: number;
|
||||||
|
grants?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_API_KEYS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
name?: string;
|
||||||
|
slug?: string;
|
||||||
|
key?: string;
|
||||||
|
scope?: string;
|
||||||
|
csrf?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_INVITATIONS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
inviting_user_id?: number;
|
||||||
|
invited_user_email?: string;
|
||||||
|
invitation_status?: string;
|
||||||
|
database_access?: string;
|
||||||
|
priviledge?: string;
|
||||||
|
db_tables_data?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_USER_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
invited_user_id?: number;
|
||||||
|
database?: string;
|
||||||
|
database_access?: string;
|
||||||
|
first_name?: string;
|
||||||
|
last_name?: string;
|
||||||
|
email?: string;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
phone?: string;
|
||||||
|
user_type?: string;
|
||||||
|
user_priviledge?: string;
|
||||||
|
image?: string;
|
||||||
|
image_thumbnail?: string;
|
||||||
|
city?: string;
|
||||||
|
state?: string;
|
||||||
|
country?: string;
|
||||||
|
zip_code?: string;
|
||||||
|
address?: string;
|
||||||
|
social_login?: number;
|
||||||
|
social_platform?: string;
|
||||||
|
social_id?: string;
|
||||||
|
verification_status?: number;
|
||||||
|
more_user_data?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_DELEGATED_USER_TABLES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
delegated_user_id?: number;
|
||||||
|
root_user_id?: number;
|
||||||
|
database?: string;
|
||||||
|
table?: string;
|
||||||
|
priviledge?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_USER_DATABASES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
db_name?: string;
|
||||||
|
db_slug?: string;
|
||||||
|
db_full_name?: string;
|
||||||
|
db_image?: string;
|
||||||
|
db_description?: string;
|
||||||
|
remote_connected?: number;
|
||||||
|
remote_connection_type?: string;
|
||||||
|
remote_db_full_name?: string;
|
||||||
|
remote_connection_host?: string;
|
||||||
|
remote_connection_key?: string;
|
||||||
|
active_clone?: number;
|
||||||
|
active_clone_parent_db?: string;
|
||||||
|
active_data?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_USER_DATABASE_TABLES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
db_id?: number;
|
||||||
|
db_slug?: string;
|
||||||
|
table_name?: string;
|
||||||
|
table_slug?: string;
|
||||||
|
table_description?: string;
|
||||||
|
child_table?: number;
|
||||||
|
child_table_parent_database?: string;
|
||||||
|
child_table_parent_table?: string;
|
||||||
|
active_data?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_USER_MEDIA = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
media_name?: string;
|
||||||
|
folder?: string;
|
||||||
|
media_url?: string;
|
||||||
|
media_thumbnail_url?: string;
|
||||||
|
media_path?: string;
|
||||||
|
media_thumbnail_path?: string;
|
||||||
|
media_type?: string;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
size?: number;
|
||||||
|
private?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_DELEGATED_USERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
delegated_user_id?: number;
|
||||||
|
permissions?: string;
|
||||||
|
permission_level_code?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_UNSUBSCRIBES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
email?: string;
|
||||||
|
type?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_NOTIFICATIONS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
title?: string;
|
||||||
|
message?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_DOCS_PAGES = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
title?: string;
|
||||||
|
slug?: string;
|
||||||
|
description?: string;
|
||||||
|
content?: string;
|
||||||
|
text_content?: string;
|
||||||
|
level?: number;
|
||||||
|
page_order?: number;
|
||||||
|
parent_id?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_DOCS_PAGE_EXTRA_LINKS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
docs_page_id?: number;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
url?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_DELETED_API_KEYS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
user_id?: number;
|
||||||
|
key?: string;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DSQL_DATASQUIREL_SERVERS = {
|
||||||
|
id?: number;
|
||||||
|
uuid?: string;
|
||||||
|
server_id?: number;
|
||||||
|
ip?: string;
|
||||||
|
ssh_user?: string;
|
||||||
|
ssh_port?: number;
|
||||||
|
date_created?: string;
|
||||||
|
date_created_code?: number;
|
||||||
|
date_created_timestamp?: string;
|
||||||
|
date_updated?: string;
|
||||||
|
date_updated_code?: number;
|
||||||
|
date_updated_timestamp?: string;
|
||||||
|
}
|
44
package-shared/utils/backend/import-mariadb-database.ts
Normal file
44
package-shared/utils/backend/import-mariadb-database.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { execSync, ExecSyncOptions } from "child_process";
|
||||||
|
import os from "os";
|
||||||
|
import connDbHandler from "../db/conn-db-handler";
|
||||||
|
|
||||||
|
export type ExportMariaDBDatabaseParam = {
|
||||||
|
dbFullName: string;
|
||||||
|
targetFilePath: string;
|
||||||
|
mariadbUser?: string;
|
||||||
|
mariadbHost?: string;
|
||||||
|
mariadbPass?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function importMariadbDatabase({
|
||||||
|
dbFullName,
|
||||||
|
targetFilePath,
|
||||||
|
mariadbHost,
|
||||||
|
mariadbPass,
|
||||||
|
mariadbUser,
|
||||||
|
}: ExportMariaDBDatabaseParam) {
|
||||||
|
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: ExecSyncOptions = {
|
||||||
|
encoding: "utf-8",
|
||||||
|
};
|
||||||
|
|
||||||
|
const importDb = execSync(cmd, execSyncOptions);
|
||||||
|
|
||||||
|
return importDb;
|
||||||
|
}
|
@ -20,7 +20,7 @@ export default function grabDirNames(param?: Param) {
|
|||||||
|
|
||||||
const pakageSharedDir = path.join(appDir, `package-shared`);
|
const pakageSharedDir = path.join(appDir, `package-shared`);
|
||||||
|
|
||||||
const mainDbTypeDefFile = path.join(appDir, `types/dsql.ts`);
|
const mainDbTypeDefFile = path.join(pakageSharedDir, `types/dsql.ts`);
|
||||||
const mainShemaJSONFilePath = path.join(schemasDir, `main.json`);
|
const mainShemaJSONFilePath = path.join(schemasDir, `main.json`);
|
||||||
const defaultTableFieldsJSONFilePath = path.join(
|
const defaultTableFieldsJSONFilePath = path.join(
|
||||||
pakageSharedDir,
|
pakageSharedDir,
|
||||||
@ -57,6 +57,11 @@ export default function grabDirNames(param?: Param) {
|
|||||||
? path.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
? path.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
const userPrivateDbImportZipFileName = `db-export.zip`;
|
||||||
|
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
|
||||||
|
? path.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
schemasDir,
|
schemasDir,
|
||||||
userDirPath,
|
userDirPath,
|
||||||
@ -73,5 +78,7 @@ export default function grabDirNames(param?: Param) {
|
|||||||
userPrivateTempJSONSchemaFilePath,
|
userPrivateTempJSONSchemaFilePath,
|
||||||
userPrivateDbExportZipFileName,
|
userPrivateDbExportZipFileName,
|
||||||
userPrivateDbExportZipFilePath,
|
userPrivateDbExportZipFilePath,
|
||||||
|
userPrivateDbImportZipFileName,
|
||||||
|
userPrivateDbImportZipFilePath,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
type Param = {
|
||||||
|
str: string;
|
||||||
|
userId: string | number;
|
||||||
|
};
|
||||||
|
export default function replaceDatasquirelDbName({
|
||||||
|
str,
|
||||||
|
userId,
|
||||||
|
}: Param): string {
|
||||||
|
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||||
|
const userNameRegex = new RegExp(`${dbNamePrefix}\\d+_`, "g");
|
||||||
|
const newPrefix = `${dbNamePrefix}${userId}_`;
|
||||||
|
|
||||||
|
return str.replace(userNameRegex, newPrefix);
|
||||||
|
}
|
32
package-shared/utils/console-colors.ts
Normal file
32
package-shared/utils/console-colors.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
const consoleColors = {
|
||||||
|
Reset: "\x1b[0m",
|
||||||
|
Bright: "\x1b[1m",
|
||||||
|
Dim: "\x1b[2m",
|
||||||
|
Underscore: "\x1b[4m",
|
||||||
|
Blink: "\x1b[5m",
|
||||||
|
Reverse: "\x1b[7m",
|
||||||
|
Hidden: "\x1b[8m",
|
||||||
|
|
||||||
|
FgBlack: "\x1b[30m",
|
||||||
|
FgRed: "\x1b[31m",
|
||||||
|
FgGreen: "\x1b[32m",
|
||||||
|
FgYellow: "\x1b[33m",
|
||||||
|
FgBlue: "\x1b[34m",
|
||||||
|
FgMagenta: "\x1b[35m",
|
||||||
|
FgCyan: "\x1b[36m",
|
||||||
|
FgWhite: "\x1b[37m",
|
||||||
|
FgGray: "\x1b[90m",
|
||||||
|
|
||||||
|
BgBlack: "\x1b[40m",
|
||||||
|
BgRed: "\x1b[41m",
|
||||||
|
BgGreen: "\x1b[42m",
|
||||||
|
BgYellow: "\x1b[43m",
|
||||||
|
BgBlue: "\x1b[44m",
|
||||||
|
BgMagenta: "\x1b[45m",
|
||||||
|
BgCyan: "\x1b[46m",
|
||||||
|
BgWhite: "\x1b[47m",
|
||||||
|
BgGray: "\x1b[100m",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default consoleColors;
|
||||||
|
export const ccol = consoleColors;
|
60
package-shared/utils/logging/debug-log.ts
Normal file
60
package-shared/utils/logging/debug-log.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { ccol } from "../console-colors";
|
||||||
|
|
||||||
|
const LogTypes = ["error", "warning"] as const;
|
||||||
|
|
||||||
|
type Param = {
|
||||||
|
/**
|
||||||
|
* data to be logged.
|
||||||
|
*/
|
||||||
|
log: any;
|
||||||
|
/**
|
||||||
|
* Log Title. Could be name of function or name of variable
|
||||||
|
*/
|
||||||
|
title?: string;
|
||||||
|
/**
|
||||||
|
* Label for the log
|
||||||
|
*/
|
||||||
|
label?: string;
|
||||||
|
/**
|
||||||
|
* Log type. `error` or `warning` or default
|
||||||
|
*/
|
||||||
|
type?: (typeof LogTypes)[number];
|
||||||
|
/**
|
||||||
|
* Whether to add a time stamp
|
||||||
|
*/
|
||||||
|
addTime?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function debugLog({ log, label, title, type, addTime }: Param) {
|
||||||
|
const logType = (() => {
|
||||||
|
switch (type) {
|
||||||
|
case "error":
|
||||||
|
return ccol.FgRed;
|
||||||
|
|
||||||
|
case "warning":
|
||||||
|
return ccol.FgYellow;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ccol.FgGreen;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
let logTxt = `${logType}DEBUG${ccol.Reset}:::`;
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
const time = date.toLocaleTimeString("en-US", {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric",
|
||||||
|
second: "numeric",
|
||||||
|
hour12: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const logTime = `${date.toLocaleDateString()}][${time}`;
|
||||||
|
|
||||||
|
if (addTime) logTxt = `${ccol.BgWhite}[${logTime}]${ccol.Reset} ` + logTxt;
|
||||||
|
if (title) logTxt += `${ccol.FgBlue}${title}${ccol.Reset}::`;
|
||||||
|
if (label)
|
||||||
|
logTxt += `${ccol.FgWhite}${ccol.Bright}${label}${ccol.Reset} =>`;
|
||||||
|
|
||||||
|
console.log(logTxt, log);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "4.1.2",
|
"version": "4.1.3",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user