Updates
This commit is contained in:
parent
a3561da53d
commit
186cc76ffb
2
dist/client/index.d.ts
vendored
2
dist/client/index.d.ts
vendored
@ -40,7 +40,7 @@ declare const datasquirelClient: {
|
|||||||
} | {
|
} | {
|
||||||
[s: string]: any;
|
[s: string]: any;
|
||||||
}[] | undefined;
|
}[] | undefined;
|
||||||
stringify: (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number) => string | undefined;
|
stringify: (value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number) => string | undefined;
|
||||||
};
|
};
|
||||||
numberfy: typeof numberfy;
|
numberfy: typeof numberfy;
|
||||||
slugify: typeof slugify;
|
slugify: typeof slugify;
|
||||||
|
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
@ -25,6 +25,7 @@ import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-g
|
|||||||
import trimSql from "./package-shared/utils/trim-sql";
|
import trimSql from "./package-shared/utils/trim-sql";
|
||||||
import parseCookies from "./package-shared/utils/backend/parseCookies";
|
import parseCookies from "./package-shared/utils/backend/parseCookies";
|
||||||
import httpRequest from "./package-shared/functions/backend/httpRequest";
|
import httpRequest from "./package-shared/functions/backend/httpRequest";
|
||||||
|
import connDbHandler from "./package-shared/utils/db/conn-db-handler";
|
||||||
/**
|
/**
|
||||||
* Main Export
|
* Main Export
|
||||||
*/
|
*/
|
||||||
@ -83,7 +84,7 @@ declare const datasquirel: {
|
|||||||
} | {
|
} | {
|
||||||
[s: string]: any;
|
[s: string]: any;
|
||||||
}[] | undefined;
|
}[] | undefined;
|
||||||
stringify: (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number) => string | undefined;
|
stringify: (value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number) => string | undefined;
|
||||||
};
|
};
|
||||||
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;
|
||||||
@ -103,6 +104,7 @@ declare const datasquirel: {
|
|||||||
};
|
};
|
||||||
parseCookies: typeof parseCookies;
|
parseCookies: typeof parseCookies;
|
||||||
httpRequest: typeof httpRequest;
|
httpRequest: typeof httpRequest;
|
||||||
|
connDbHandler: typeof connDbHandler;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export default datasquirel;
|
export default datasquirel;
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
@ -32,6 +32,7 @@ const sql_delete_generator_1 = __importDefault(require("./package-shared/functio
|
|||||||
const trim_sql_1 = __importDefault(require("./package-shared/utils/trim-sql"));
|
const trim_sql_1 = __importDefault(require("./package-shared/utils/trim-sql"));
|
||||||
const parseCookies_1 = __importDefault(require("./package-shared/utils/backend/parseCookies"));
|
const parseCookies_1 = __importDefault(require("./package-shared/utils/backend/parseCookies"));
|
||||||
const httpRequest_1 = __importDefault(require("./package-shared/functions/backend/httpRequest"));
|
const httpRequest_1 = __importDefault(require("./package-shared/functions/backend/httpRequest"));
|
||||||
|
const conn_db_handler_1 = __importDefault(require("./package-shared/utils/db/conn-db-handler"));
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
@ -92,6 +93,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,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
exports.default = datasquirel;
|
exports.default = datasquirel;
|
||||||
|
@ -55,7 +55,7 @@ function githubLogin(_a) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch ( /** @type {any} */error) {
|
||||||
console.log("ERROR in githubLogin.js backend function =>", error.message);
|
console.log("ERROR in githubLogin.ts backend function =>", error.message);
|
||||||
}
|
}
|
||||||
return gitHubUser;
|
return gitHubUser;
|
||||||
});
|
});
|
||||||
|
@ -182,16 +182,16 @@ function handleSocialDb(_a) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("Social User Failed to insert in 'handleSocialDb.js' backend function =>", newUser);
|
console.log("Social User Failed to insert in 'handleSocialDb.ts' backend function =>", newUser);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "Social User Failed to insert in 'handleSocialDb.js' backend function",
|
msg: "Social User Failed to insert in 'handleSocialDb.ts' backend function",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log("ERROR in 'handleSocialDb.js' backend function =>", error.message);
|
console.log("ERROR in 'handleSocialDb.ts' backend function =>", error.message);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
|
@ -88,7 +88,7 @@ function apiGoogleLogin(_a) {
|
|||||||
return Object.assign({}, loggedInGoogleUser);
|
return Object.assign({}, loggedInGoogleUser);
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch ( /** @type {any} */error) {
|
||||||
console.log(`apo-google-login.js ERROR: ${error.message}`);
|
console.log(`api-google-login.ts ERROR: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: undefined,
|
payload: undefined,
|
||||||
|
@ -71,7 +71,7 @@ function addUsersTableToDb(_a) {
|
|||||||
return `Done!`;
|
return `Done!`;
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch ( /** @type {any} */error) {
|
||||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||||
(0, serverError_1.default)({
|
(0, serverError_1.default)({
|
||||||
component: "addUsersTableToDb",
|
component: "addUsersTableToDb",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
* @description this function takes in a text(or number) and returns a sanitized
|
* @description this function takes in a text(or number) and returns a sanitized
|
||||||
* text, usually without spaces
|
* text, usually without spaces
|
||||||
*/
|
*/
|
||||||
declare function sanitizeSql(text: any, spaces: boolean, regex?: RegExp | null): any;
|
declare function sanitizeSql(text: any, spaces?: boolean, regex?: RegExp | null): any;
|
||||||
export default sanitizeSql;
|
export default sanitizeSql;
|
||||||
|
@ -32,7 +32,7 @@ function grabNewUsersTableSchema(params) {
|
|||||||
return userPreset;
|
return userPreset;
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch ( /** @type {any} */error) {
|
||||||
console.log(`grabNewUsersTableSchema.js ERROR: ${error.message}`);
|
console.log(`grabNewUsersTableSchema.ts ERROR: ${error.message}`);
|
||||||
(0, serverError_1.default)({
|
(0, serverError_1.default)({
|
||||||
component: "grabNewUsersTableSchema",
|
component: "grabNewUsersTableSchema",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
|
@ -56,9 +56,9 @@ function grabSchemaFieldsFromData({ data, fields, excludeData, excludeFields, })
|
|||||||
return finalFields;
|
return finalFields;
|
||||||
}
|
}
|
||||||
catch ( /** @type {any} */error) {
|
catch ( /** @type {any} */error) {
|
||||||
console.log(`grabSchemaFieldsFromData.js ERROR: ${error.message}`);
|
console.log(`grabSchemaFieldsFromData.ts ERROR: ${error.message}`);
|
||||||
(0, serverError_1.default)({
|
(0, serverError_1.default)({
|
||||||
component: "grabSchemaFieldsFromData.js",
|
component: "grabSchemaFieldsFromData.ts",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
});
|
});
|
||||||
return [];
|
return [];
|
||||||
|
@ -52,7 +52,7 @@ function updateUsersTableSchema(_a) {
|
|||||||
return `Done!`;
|
return `Done!`;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||||
(0, serverError_1.default)({
|
(0, serverError_1.default)({
|
||||||
component: "addUsersTableToDb",
|
component: "addUsersTableToDb",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
|
@ -41,4 +41,3 @@ function encrypt({ data, encryptionKey, encryptionSalt, }) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = encrypt;
|
|
||||||
|
25
dist/package-shared/shell/createDbFromSchema.js
vendored
25
dist/package-shared/shell/createDbFromSchema.js
vendored
@ -15,20 +15,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.default = createDbFromSchema;
|
exports.default = createDbFromSchema;
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
require("dotenv").config({ path: "./../.env" });
|
|
||||||
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 execFlag = process.argv.find((arg) => arg === "--exec");
|
const util_1 = require("util");
|
||||||
/**
|
/**
|
||||||
* # Create database from Schema Function
|
* # Create database from Schema Function
|
||||||
*/
|
*/
|
||||||
function createDbFromSchema(_a) {
|
function createDbFromSchema(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ userId, targetDatabase, dbSchemaData, }) {
|
return __awaiter(this, arguments, void 0, function* ({ userId, targetDatabase, dbSchemaData, }) {
|
||||||
var _b, _c;
|
var _b, _c;
|
||||||
|
console.log("///////////////////////////////");
|
||||||
|
console.log("///////////////////////////////");
|
||||||
|
console.log("Rebuilding Database ...");
|
||||||
|
console.log("process.env.DSQL_DB_HOST", process.env.DSQL_DB_HOST);
|
||||||
|
console.log("process.env.DSQL_DB_USERNAME", process.env.DSQL_DB_USERNAME);
|
||||||
|
console.log("process.env.DSQL_DB_PASSWORD", process.env.DSQL_DB_PASSWORD);
|
||||||
|
console.log("process.env.DSQL_DB_NAME", process.env.DSQL_DB_NAME);
|
||||||
const schemaPath = userId
|
const schemaPath = userId
|
||||||
? path_1.default.join(String(process.env.DSQL_USER_DB_SCHEMA_PATH), `/user-${userId}/main.json`)
|
? path_1.default.join(String(process.env.DSQL_USER_DB_SCHEMA_PATH), `/user-${userId}/main.json`)
|
||||||
: path_1.default.resolve(__dirname, "../../jsonData/dbSchemas/main.json");
|
: path_1.default.resolve(__dirname, "../../jsonData/dbSchemas/main.json");
|
||||||
@ -46,8 +52,10 @@ function createDbFromSchema(_a) {
|
|||||||
if (targetDatabase && dbFullName != targetDatabase) {
|
if (targetDatabase && dbFullName != targetDatabase) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
console.log("Checking Database ...");
|
||||||
/** @type {any} */
|
/** @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}'`);
|
||||||
|
console.log("DB Checked Success!");
|
||||||
if (dbCheck && ((_b = dbCheck[0]) === null || _b === void 0 ? void 0 : _b.dbFullName)) {
|
if (dbCheck && ((_b = dbCheck[0]) === null || _b === void 0 ? void 0 : _b.dbFullName)) {
|
||||||
// Database Exists
|
// Database Exists
|
||||||
}
|
}
|
||||||
@ -238,8 +246,19 @@ function createDbFromSchema(_a) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log("Database Successfully Rebuilt!");
|
||||||
|
console.log("///////////////////////////////");
|
||||||
|
console.log("///////////////////////////////");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (execFlag) {
|
const { values } = (0, util_1.parseArgs)({
|
||||||
|
args: process.argv,
|
||||||
|
options: {
|
||||||
|
exec: { type: "boolean" },
|
||||||
|
},
|
||||||
|
strict: true,
|
||||||
|
allowPositionals: true,
|
||||||
|
});
|
||||||
|
if (values.exec) {
|
||||||
createDbFromSchema({});
|
createDbFromSchema({});
|
||||||
}
|
}
|
||||||
|
2
dist/package-shared/shell/lessWatch.js
vendored
2
dist/package-shared/shell/lessWatch.js
vendored
@ -22,7 +22,7 @@ for (let i = 0; i < sourceFiles.length; i++) {
|
|||||||
const srcFolder = sourceFiles[i];
|
const srcFolder = sourceFiles[i];
|
||||||
const dstFile = dstFiles[i];
|
const dstFile = dstFiles[i];
|
||||||
fs_1.default.watch(srcFolder, { recursive: true }, (evtType, prev) => {
|
fs_1.default.watch(srcFolder, { recursive: true }, (evtType, prev) => {
|
||||||
if ((prev === null || prev === void 0 ? void 0 : prev.match(/\(/)) || (prev === null || prev === void 0 ? void 0 : prev.match(/\.js$/i))) {
|
if ((prev === null || prev === void 0 ? void 0 : prev.match(/\(/)) || (prev === null || prev === void 0 ? void 0 : prev.match(/\.(j|t)s$/i))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let finalSrcPath = `${srcFolder}/main.less`;
|
let finalSrcPath = `${srcFolder}/main.less`;
|
||||||
|
@ -1,4 +1 @@
|
|||||||
/**
|
|
||||||
* # Create database from Schema Function
|
|
||||||
*/
|
|
||||||
export default function noDatabaseDbHandler(queryString: string): Promise<any>;
|
export default function noDatabaseDbHandler(queryString: string): Promise<any>;
|
||||||
|
@ -14,37 +14,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = noDatabaseDbHandler;
|
exports.default = noDatabaseDbHandler;
|
||||||
const dbHandler_1 = __importDefault(require("./dbHandler"));
|
const dbHandler_1 = __importDefault(require("./dbHandler"));
|
||||||
/**
|
|
||||||
* # Create database from Schema Function
|
|
||||||
*/
|
|
||||||
function noDatabaseDbHandler(queryString) {
|
function noDatabaseDbHandler(queryString) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
/**
|
|
||||||
* Declare variables
|
|
||||||
*
|
|
||||||
* @description Declare "results" variable
|
|
||||||
*/
|
|
||||||
let results;
|
let results;
|
||||||
/**
|
|
||||||
* Fetch from db
|
|
||||||
*
|
|
||||||
* @description Fetch data from db if no cache
|
|
||||||
*/
|
|
||||||
try {
|
try {
|
||||||
/** ********************* Run Query */
|
|
||||||
results = yield (0, dbHandler_1.default)({ query: queryString });
|
results = yield (0, dbHandler_1.default)({ query: queryString });
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Return results
|
|
||||||
*
|
|
||||||
* @description Return results add to cache if "req" param is passed
|
|
||||||
*/
|
|
||||||
if (results) {
|
if (results) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
107
dist/package-shared/types/index.d.ts
vendored
107
dist/package-shared/types/index.d.ts
vendored
@ -117,6 +117,7 @@ export interface DSQL_MYSQL_user_databases_Type {
|
|||||||
db_image: string;
|
db_image: string;
|
||||||
db_description: string;
|
db_description: string;
|
||||||
active_clone: number;
|
active_clone: number;
|
||||||
|
active_data: 0 | 1;
|
||||||
active_clone_parent_db: string;
|
active_clone_parent_db: string;
|
||||||
remote_connected?: number;
|
remote_connected?: number;
|
||||||
remote_db_full_name?: string;
|
remote_db_full_name?: string;
|
||||||
@ -323,7 +324,7 @@ export interface MetricsType {
|
|||||||
export interface DashboardContextType {
|
export interface DashboardContextType {
|
||||||
user?: UserType;
|
user?: UserType;
|
||||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||||
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type>>;
|
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>>;
|
||||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||||
metrics?: MetricsType;
|
metrics?: MetricsType;
|
||||||
}
|
}
|
||||||
@ -375,7 +376,7 @@ export interface AddEntryContextType {
|
|||||||
richTextEditors: React.MutableRefObject<RichTextEditorsRefArray[]>;
|
richTextEditors: React.MutableRefObject<RichTextEditorsRefArray[]>;
|
||||||
jsonTextEditors: React.MutableRefObject<JSONTextEditorsRefArray[]>;
|
jsonTextEditors: React.MutableRefObject<JSONTextEditorsRefArray[]>;
|
||||||
query: any;
|
query: any;
|
||||||
duplicateEntry?: any;
|
duplicateEntry: any;
|
||||||
confirmedDelegetedUser: any;
|
confirmedDelegetedUser: any;
|
||||||
}
|
}
|
||||||
export interface UserDatabasesContextType {
|
export interface UserDatabasesContextType {
|
||||||
@ -435,13 +436,13 @@ export interface SingleDatabaseContextType {
|
|||||||
confirmedDelegetedUser: any;
|
confirmedDelegetedUser: any;
|
||||||
}
|
}
|
||||||
export interface ApiKeysContextType {
|
export interface ApiKeysContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
apiKeys: any[];
|
apiKeys?: any[];
|
||||||
setApiKeys: React.Dispatch<React.SetStateAction<any[]>>;
|
setApiKeys?: React.Dispatch<React.SetStateAction<any[]>>;
|
||||||
targetApiKey: any | null;
|
targetApiKey?: any | null;
|
||||||
setTargetApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
setTargetApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||||
newApiKey: any | null;
|
newApiKey?: any | null;
|
||||||
setNewApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
setNewApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||||
}
|
}
|
||||||
export interface LoginFormContextType {
|
export interface LoginFormContextType {
|
||||||
user?: UserType | null;
|
user?: UserType | null;
|
||||||
@ -469,27 +470,27 @@ export interface DocsAsidePageObject {
|
|||||||
level?: number;
|
level?: number;
|
||||||
}
|
}
|
||||||
export interface AllUserUsersContextType {
|
export interface AllUserUsersContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
users: MYSQL_delegated_users_table_def[];
|
users?: MYSQL_delegated_users_table_def[];
|
||||||
targetUser: MYSQL_user_users_table_def | null;
|
targetUser?: MYSQL_user_users_table_def | undefined;
|
||||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | null>>;
|
setTargetUser?: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | undefined>>;
|
||||||
databases: DSQL_MYSQL_user_databases_Type[];
|
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||||
pendingInvitations: MYSQL_invitations_table_def[];
|
pendingInvitations?: MYSQL_invitations_table_def[];
|
||||||
pendingInvitationsReceived: any[];
|
pendingInvitationsReceived?: any[];
|
||||||
adminUsers: any[];
|
adminUsers?: any[];
|
||||||
invitedAccounts: any[];
|
invitedAccounts?: any[];
|
||||||
}
|
}
|
||||||
export interface AddSocialLoginContextType {
|
export interface AddSocialLoginContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database?: DSQL_MYSQL_user_databases_Type;
|
||||||
query: any;
|
query?: any;
|
||||||
socialLogins: SocialLoginObjectType[];
|
socialLogins?: SocialLoginObjectType[];
|
||||||
}
|
}
|
||||||
export interface DelegatedDbContextType {
|
export interface DelegatedDbContextType {
|
||||||
user: UserType;
|
user: UserType;
|
||||||
users: MYSQL_user_users_table_def[];
|
users: MYSQL_user_users_table_def[];
|
||||||
targetUser: MYSQL_user_users_table_def | null;
|
targetUser: MYSQL_user_users_table_def | undefined;
|
||||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | null>>;
|
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | undefined>>;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database: DSQL_MYSQL_user_databases_Type;
|
||||||
}
|
}
|
||||||
export interface AddUserUserContextType {
|
export interface AddUserUserContextType {
|
||||||
@ -502,8 +503,8 @@ export interface AddUserUserContextType {
|
|||||||
export interface UserUsersContextType {
|
export interface UserUsersContextType {
|
||||||
user: UserType;
|
user: UserType;
|
||||||
users: MYSQL_user_users_table_def[];
|
users: MYSQL_user_users_table_def[];
|
||||||
targetUser: MYSQL_user_users_table_def;
|
targetUser?: MYSQL_user_users_table_def;
|
||||||
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | null>>;
|
setTargetUser: React.Dispatch<React.SetStateAction<MYSQL_user_users_table_def | undefined>>;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database: DSQL_MYSQL_user_databases_Type;
|
||||||
table: DSQL_TableSchemaType;
|
table: DSQL_TableSchemaType;
|
||||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||||
@ -604,14 +605,14 @@ export interface UserSchemaContextType {
|
|||||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
dbSchemaData: DSQL_DatabaseSchemaType[];
|
||||||
}
|
}
|
||||||
export interface ConnectContextType {
|
export interface ConnectContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
query: any;
|
query?: any;
|
||||||
mariadbUserCred: MariaDBUserCredType;
|
mariadbUserCred?: MariaDBUserCredType;
|
||||||
mariadbUsers: MYSQL_mariadb_users_table_def[];
|
mariadbUsers?: MYSQL_mariadb_users_table_def[];
|
||||||
targetMariadbUser: MYSQL_mariadb_users_table_def | null;
|
targetMariadbUser?: MYSQL_mariadb_users_table_def | null;
|
||||||
setTargetMariadbUser: React.Dispatch<React.SetStateAction<MYSQL_mariadb_users_table_def | null>>;
|
setTargetMariadbUser?: React.Dispatch<React.SetStateAction<MYSQL_mariadb_users_table_def | null>>;
|
||||||
refresh: number;
|
refresh?: number;
|
||||||
setRefresh: React.Dispatch<React.SetStateAction<number>>;
|
setRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||||
}
|
}
|
||||||
export interface MYSQL_mariadb_users_table_def {
|
export interface MYSQL_mariadb_users_table_def {
|
||||||
id?: number;
|
id?: number;
|
||||||
@ -632,7 +633,7 @@ export interface DbContextType {
|
|||||||
user?: UserType;
|
user?: UserType;
|
||||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||||
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type>>;
|
setTargetDatabase?: React.Dispatch<React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>>;
|
||||||
}
|
}
|
||||||
export interface MariaDBUserCredType {
|
export interface MariaDBUserCredType {
|
||||||
mariadb_user?: string;
|
mariadb_user?: string;
|
||||||
@ -640,26 +641,26 @@ export interface MariaDBUserCredType {
|
|||||||
mariadb_pass?: string;
|
mariadb_pass?: string;
|
||||||
}
|
}
|
||||||
export interface AddTableContextType {
|
export interface AddTableContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database?: DSQL_MYSQL_user_databases_Type;
|
||||||
tables: DSQL_TableSchemaType[];
|
tables?: DSQL_TableSchemaType[];
|
||||||
tableFields: DSQL_FieldSchemaType[];
|
tableFields?: DSQL_FieldSchemaType[];
|
||||||
setTableFields: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType[]>>;
|
setTableFields?: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType[]>>;
|
||||||
targetField: DSQL_FieldSchemaType | null;
|
targetField?: DSQL_FieldSchemaType | null;
|
||||||
setTargetField: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType | null>>;
|
setTargetField?: React.Dispatch<React.SetStateAction<DSQL_FieldSchemaType | null>>;
|
||||||
pageRefresh: number | null;
|
pageRefresh?: number | null;
|
||||||
setPageRefresh: React.Dispatch<React.SetStateAction<number>>;
|
setPageRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||||
refreshFieldsListRef: React.MutableRefObject<React.Dispatch<React.SetStateAction<number>>>;
|
refreshFieldsListRef?: React.MutableRefObject<React.Dispatch<React.SetStateAction<number>> | undefined>;
|
||||||
query: any;
|
query?: any;
|
||||||
}
|
}
|
||||||
export interface DbSchemaContextType {
|
export interface DbSchemaContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database?: DSQL_MYSQL_user_databases_Type;
|
||||||
dbImage: string;
|
dbImage?: string;
|
||||||
setDbImage: React.Dispatch<React.SetStateAction<string>>;
|
setDbImage?: React.Dispatch<React.SetStateAction<string>>;
|
||||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||||
tables: any[];
|
tables?: any[];
|
||||||
}
|
}
|
||||||
export interface DbShellContextType {
|
export interface DbShellContextType {
|
||||||
user?: UserType;
|
user?: UserType;
|
||||||
|
@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = DB_HANDLER;
|
exports.default = DB_HANDLER;
|
||||||
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
|
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
|
||||||
const grabDbSSL_1 = __importDefault(require("../grabDbSSL"));
|
|
||||||
const MASTER = (0, serverless_mysql_1.default)({
|
const MASTER = (0, serverless_mysql_1.default)({
|
||||||
config: {
|
config: {
|
||||||
host: process.env.DSQL_DB_HOST,
|
host: process.env.DSQL_DB_HOST,
|
||||||
@ -25,7 +24,7 @@ const MASTER = (0, serverless_mysql_1.default)({
|
|||||||
? Number(process.env.DSQL_DB_PORT)
|
? Number(process.env.DSQL_DB_PORT)
|
||||||
: undefined,
|
: undefined,
|
||||||
charset: "utf8mb4",
|
charset: "utf8mb4",
|
||||||
ssl: (0, grabDbSSL_1.default)(),
|
// ssl: grabDbSSL(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
|
@ -100,4 +100,3 @@ function DSQL_USER_DB_HANDLER({ paradigm, database, queryString, queryValues, })
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = DSQL_USER_DB_HANDLER;
|
|
||||||
|
25
dist/package-shared/utils/db/conn-db-handler.d.ts
vendored
Normal file
25
dist/package-shared/utils/db/conn-db-handler.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { ServerlessMysql } from "serverless-mysql";
|
||||||
|
type QueryObject = {
|
||||||
|
query: string;
|
||||||
|
values?: (string | number | undefined)[];
|
||||||
|
};
|
||||||
|
type Return<ReturnType = any> = ReturnType | null;
|
||||||
|
/**
|
||||||
|
* # Run Query From MySQL Connection
|
||||||
|
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||||
|
* setup with `serverless-mysql` npm module
|
||||||
|
*/
|
||||||
|
export default function connDbHandler<ReturnType = any>(
|
||||||
|
/**
|
||||||
|
* ServerlessMySQL Connection Object
|
||||||
|
*/
|
||||||
|
conn: ServerlessMysql,
|
||||||
|
/**
|
||||||
|
* String Or `QueryObject` Array
|
||||||
|
*/
|
||||||
|
query: QueryObject["query"] | QueryObject[],
|
||||||
|
/**
|
||||||
|
* Array of Values to Sanitize and Inject
|
||||||
|
*/
|
||||||
|
values?: QueryObject["values"]): Promise<Return<ReturnType>>;
|
||||||
|
export {};
|
57
dist/package-shared/utils/db/conn-db-handler.js
vendored
Normal file
57
dist/package-shared/utils/db/conn-db-handler.js
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
"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());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = connDbHandler;
|
||||||
|
/**
|
||||||
|
* # Run Query From MySQL Connection
|
||||||
|
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||||
|
* setup with `serverless-mysql` npm module
|
||||||
|
*/
|
||||||
|
function connDbHandler(
|
||||||
|
/**
|
||||||
|
* ServerlessMySQL Connection Object
|
||||||
|
*/
|
||||||
|
conn,
|
||||||
|
/**
|
||||||
|
* String Or `QueryObject` Array
|
||||||
|
*/
|
||||||
|
query,
|
||||||
|
/**
|
||||||
|
* Array of Values to Sanitize and Inject
|
||||||
|
*/
|
||||||
|
values) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
if (typeof query == "string") {
|
||||||
|
const res = yield conn.query(query, values);
|
||||||
|
return JSON.parse(JSON.stringify(res));
|
||||||
|
}
|
||||||
|
else if (typeof query == "object") {
|
||||||
|
const resArray = [];
|
||||||
|
for (let i = 0; i < query.length; i++) {
|
||||||
|
const queryObj = query[i];
|
||||||
|
const queryObjRes = yield conn.query(queryObj.query, queryObj.values);
|
||||||
|
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
|
||||||
|
}
|
||||||
|
return resArray;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
conn.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
2
dist/package-shared/utils/ejson.d.ts
vendored
2
dist/package-shared/utils/ejson.d.ts
vendored
@ -9,7 +9,7 @@ declare function parse(string: string | null | number, reviver?: (this: any, key
|
|||||||
/**
|
/**
|
||||||
* # EJSON stringify object
|
* # EJSON stringify object
|
||||||
*/
|
*/
|
||||||
declare function stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string | undefined;
|
declare function stringify(value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number): string | undefined;
|
||||||
declare const EJSON: {
|
declare const EJSON: {
|
||||||
parse: typeof parse;
|
parse: typeof parse;
|
||||||
stringify: typeof stringify;
|
stringify: typeof stringify;
|
||||||
|
2
dist/package-shared/utils/ejson.js
vendored
2
dist/package-shared/utils/ejson.js
vendored
@ -22,7 +22,7 @@ function parse(string, reviver) {
|
|||||||
*/
|
*/
|
||||||
function stringify(value, replacer, space) {
|
function stringify(value, replacer, space) {
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(value, replacer, space);
|
return JSON.stringify(value, replacer || undefined, space);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
7
dist/package-shared/utils/endConnection.d.ts
vendored
7
dist/package-shared/utils/endConnection.d.ts
vendored
@ -1 +1,6 @@
|
|||||||
export {};
|
import mysql from "mysql";
|
||||||
|
/**
|
||||||
|
* # End MYSQL Connection
|
||||||
|
*/
|
||||||
|
declare function endConnection(connection: mysql.Connection): void;
|
||||||
|
export default endConnection;
|
||||||
|
2
dist/package-shared/utils/endConnection.js
vendored
2
dist/package-shared/utils/endConnection.js
vendored
@ -10,4 +10,4 @@ function endConnection(connection) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = endConnection;
|
exports.default = endConnection;
|
||||||
|
2
index.ts
2
index.ts
@ -33,6 +33,7 @@ import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-g
|
|||||||
import trimSql from "./package-shared/utils/trim-sql";
|
import trimSql from "./package-shared/utils/trim-sql";
|
||||||
import parseCookies from "./package-shared/utils/backend/parseCookies";
|
import parseCookies from "./package-shared/utils/backend/parseCookies";
|
||||||
import httpRequest from "./package-shared/functions/backend/httpRequest";
|
import httpRequest from "./package-shared/functions/backend/httpRequest";
|
||||||
|
import connDbHandler from "./package-shared/utils/db/conn-db-handler";
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
@ -98,6 +99,7 @@ const datasquirel = {
|
|||||||
},
|
},
|
||||||
parseCookies,
|
parseCookies,
|
||||||
httpRequest,
|
httpRequest,
|
||||||
|
connDbHandler,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ export default async function githubLogin({
|
|||||||
}
|
}
|
||||||
} catch (/** @type {any} */ error: any) {
|
} catch (/** @type {any} */ error: any) {
|
||||||
console.log(
|
console.log(
|
||||||
"ERROR in githubLogin.js backend function =>",
|
"ERROR in githubLogin.ts backend function =>",
|
||||||
error.message
|
error.message
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -221,19 +221,19 @@ export default async function handleSocialDb({
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"Social User Failed to insert in 'handleSocialDb.js' backend function =>",
|
"Social User Failed to insert in 'handleSocialDb.ts' backend function =>",
|
||||||
newUser
|
newUser
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
payload: null,
|
payload: null,
|
||||||
msg: "Social User Failed to insert in 'handleSocialDb.js' backend function",
|
msg: "Social User Failed to insert in 'handleSocialDb.ts' backend function",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(
|
console.log(
|
||||||
"ERROR in 'handleSocialDb.js' backend function =>",
|
"ERROR in 'handleSocialDb.ts' backend function =>",
|
||||||
error.message
|
error.message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export default async function apiGoogleLogin({
|
|||||||
|
|
||||||
return { ...loggedInGoogleUser };
|
return { ...loggedInGoogleUser };
|
||||||
} catch (/** @type {any} */ error: any) {
|
} catch (/** @type {any} */ error: any) {
|
||||||
console.log(`apo-google-login.js ERROR: ${error.message}`);
|
console.log(`api-google-login.ts ERROR: ${error.message}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -85,7 +85,7 @@ export default async function addUsersTableToDb({
|
|||||||
|
|
||||||
return `Done!`;
|
return `Done!`;
|
||||||
} catch (/** @type {any} */ error: any) {
|
} catch (/** @type {any} */ error: any) {
|
||||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||||
|
|
||||||
serverError({
|
serverError({
|
||||||
component: "addUsersTableToDb",
|
component: "addUsersTableToDb",
|
||||||
|
@ -6,7 +6,7 @@ import _ from "lodash";
|
|||||||
* @description this function takes in a text(or number) and returns a sanitized
|
* @description this function takes in a text(or number) and returns a sanitized
|
||||||
* text, usually without spaces
|
* text, usually without spaces
|
||||||
*/
|
*/
|
||||||
function sanitizeSql(text: any, spaces: boolean, regex?: RegExp | null): any {
|
function sanitizeSql(text: any, spaces?: boolean, regex?: RegExp | null): any {
|
||||||
if (!text) return "";
|
if (!text) return "";
|
||||||
if (typeof text == "number" || typeof text == "boolean") return text;
|
if (typeof text == "number" || typeof text == "boolean") return text;
|
||||||
if (typeof text == "string" && !text?.toString()?.match(/./)) return "";
|
if (typeof text == "string" && !text?.toString()?.match(/./)) return "";
|
||||||
@ -55,7 +55,7 @@ function sanitizeSql(text: any, spaces: boolean, regex?: RegExp | null): any {
|
|||||||
*
|
*
|
||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
function sanitizeObjects(object: any, spaces: boolean): object {
|
function sanitizeObjects(object: any, spaces?: boolean): object {
|
||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
let objectUpdated: any = { ...object };
|
let objectUpdated: any = { ...object };
|
||||||
const keys = Object.keys(objectUpdated);
|
const keys = Object.keys(objectUpdated);
|
||||||
@ -92,7 +92,7 @@ function sanitizeObjects(object: any, spaces: boolean): object {
|
|||||||
*/
|
*/
|
||||||
function sanitizeArrays(
|
function sanitizeArrays(
|
||||||
array: any[],
|
array: any[],
|
||||||
spaces: boolean
|
spaces?: boolean
|
||||||
): string[] | number[] | object[] {
|
): string[] | number[] | object[] {
|
||||||
let arrayUpdated = _.cloneDeep(array);
|
let arrayUpdated = _.cloneDeep(array);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ export default function grabNewUsersTableSchema(params: {
|
|||||||
|
|
||||||
return userPreset;
|
return userPreset;
|
||||||
} catch (/** @type {any} */ error: any) {
|
} catch (/** @type {any} */ error: any) {
|
||||||
console.log(`grabNewUsersTableSchema.js ERROR: ${error.message}`);
|
console.log(`grabNewUsersTableSchema.ts ERROR: ${error.message}`);
|
||||||
|
|
||||||
serverError({
|
serverError({
|
||||||
component: "grabNewUsersTableSchema",
|
component: "grabNewUsersTableSchema",
|
||||||
|
@ -75,10 +75,10 @@ export default function grabSchemaFieldsFromData({
|
|||||||
|
|
||||||
return finalFields;
|
return finalFields;
|
||||||
} catch (/** @type {any} */ error: any) {
|
} catch (/** @type {any} */ error: any) {
|
||||||
console.log(`grabSchemaFieldsFromData.js ERROR: ${error.message}`);
|
console.log(`grabSchemaFieldsFromData.ts ERROR: ${error.message}`);
|
||||||
|
|
||||||
serverError({
|
serverError({
|
||||||
component: "grabSchemaFieldsFromData.js",
|
component: "grabSchemaFieldsFromData.ts",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import nodemailer, { SendMailOptions } from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
|
|
||||||
let transporter = nodemailer.createTransport({
|
let transporter = nodemailer.createTransport({
|
||||||
host: process.env.DSQL_MAIL_HOST,
|
host: process.env.DSQL_MAIL_HOST,
|
||||||
@ -68,7 +68,7 @@ export default async function handleNodemailer({
|
|||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let mailObject: SendMailOptions = {};
|
let mailObject: any = {};
|
||||||
|
|
||||||
mailObject["from"] = `"${senderName || "Datasquirel"}" <${sender}>`;
|
mailObject["from"] = `"${senderName || "Datasquirel"}" <${sender}>`;
|
||||||
mailObject["sender"] = sender;
|
mailObject["sender"] = sender;
|
||||||
|
@ -65,7 +65,7 @@ export default async function updateUsersTableSchema({
|
|||||||
|
|
||||||
return `Done!`;
|
return `Done!`;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(`addUsersTableToDb.js ERROR: ${error.message}`);
|
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
|
||||||
|
|
||||||
serverError({
|
serverError({
|
||||||
component: "addUsersTableToDb",
|
component: "addUsersTableToDb",
|
||||||
|
@ -56,5 +56,3 @@ export default function encrypt({
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = encrypt;
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
require("dotenv").config({ path: "./../.env" });
|
|
||||||
|
|
||||||
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";
|
||||||
@ -10,8 +8,7 @@ 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 { parseArgs } from "util";
|
||||||
const execFlag = process.argv.find((arg) => arg === "--exec");
|
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
userId?: number | string | null;
|
userId?: number | string | null;
|
||||||
@ -27,6 +24,14 @@ export default async function createDbFromSchema({
|
|||||||
targetDatabase,
|
targetDatabase,
|
||||||
dbSchemaData,
|
dbSchemaData,
|
||||||
}: Param) {
|
}: Param) {
|
||||||
|
console.log("///////////////////////////////");
|
||||||
|
console.log("///////////////////////////////");
|
||||||
|
console.log("Rebuilding Database ...");
|
||||||
|
console.log("process.env.DSQL_DB_HOST", process.env.DSQL_DB_HOST);
|
||||||
|
console.log("process.env.DSQL_DB_USERNAME", process.env.DSQL_DB_USERNAME);
|
||||||
|
console.log("process.env.DSQL_DB_PASSWORD", process.env.DSQL_DB_PASSWORD);
|
||||||
|
console.log("process.env.DSQL_DB_NAME", process.env.DSQL_DB_NAME);
|
||||||
|
|
||||||
const schemaPath = userId
|
const schemaPath = userId
|
||||||
? path.join(
|
? path.join(
|
||||||
String(process.env.DSQL_USER_DB_SCHEMA_PATH),
|
String(process.env.DSQL_USER_DB_SCHEMA_PATH),
|
||||||
@ -58,11 +63,15 @@ export default async function createDbFromSchema({
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Checking Database ...");
|
||||||
|
|
||||||
/** @type {any} */
|
/** @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}'`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log("DB Checked Success!");
|
||||||
|
|
||||||
if (dbCheck && dbCheck[0]?.dbFullName) {
|
if (dbCheck && dbCheck[0]?.dbFullName) {
|
||||||
// Database Exists
|
// Database Exists
|
||||||
} else {
|
} else {
|
||||||
@ -297,8 +306,21 @@ export default async function createDbFromSchema({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Database Successfully Rebuilt!");
|
||||||
|
console.log("///////////////////////////////");
|
||||||
|
console.log("///////////////////////////////");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (execFlag) {
|
const { values } = parseArgs({
|
||||||
|
args: process.argv,
|
||||||
|
options: {
|
||||||
|
exec: { type: "boolean" },
|
||||||
|
},
|
||||||
|
strict: true,
|
||||||
|
allowPositionals: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (values.exec) {
|
||||||
createDbFromSchema({});
|
createDbFromSchema({});
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ for (let i = 0; i < sourceFiles.length; i++) {
|
|||||||
const dstFile = dstFiles[i];
|
const dstFile = dstFiles[i];
|
||||||
|
|
||||||
fs.watch(srcFolder, { recursive: true }, (evtType, prev) => {
|
fs.watch(srcFolder, { recursive: true }, (evtType, prev) => {
|
||||||
if (prev?.match(/\(/) || prev?.match(/\.js$/i)) {
|
if (prev?.match(/\(/) || prev?.match(/\.(j|t)s$/i)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,39 +1,16 @@
|
|||||||
import dbHandler from "./dbHandler";
|
import dbHandler from "./dbHandler";
|
||||||
|
|
||||||
/**
|
|
||||||
* # Create database from Schema Function
|
|
||||||
*/
|
|
||||||
export default async function noDatabaseDbHandler(
|
export default async function noDatabaseDbHandler(
|
||||||
queryString: string
|
queryString: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
/**
|
|
||||||
* Declare variables
|
|
||||||
*
|
|
||||||
* @description Declare "results" variable
|
|
||||||
*/
|
|
||||||
let results;
|
let results;
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch from db
|
|
||||||
*
|
|
||||||
* @description Fetch data from db if no cache
|
|
||||||
*/
|
|
||||||
try {
|
try {
|
||||||
/** ********************* Run Query */
|
|
||||||
results = await dbHandler({ query: queryString });
|
results = await dbHandler({ query: queryString });
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return results
|
|
||||||
*
|
|
||||||
* @description Return results add to cache if "req" param is passed
|
|
||||||
*/
|
|
||||||
if (results) {
|
if (results) {
|
||||||
return results;
|
return results;
|
||||||
} else {
|
} else {
|
||||||
|
@ -131,6 +131,7 @@ export interface DSQL_MYSQL_user_databases_Type {
|
|||||||
db_image: string;
|
db_image: string;
|
||||||
db_description: string;
|
db_description: string;
|
||||||
active_clone: number;
|
active_clone: number;
|
||||||
|
active_data: 0 | 1;
|
||||||
active_clone_parent_db: string;
|
active_clone_parent_db: string;
|
||||||
remote_connected?: number;
|
remote_connected?: number;
|
||||||
remote_db_full_name?: string;
|
remote_db_full_name?: string;
|
||||||
@ -365,7 +366,7 @@ export interface DashboardContextType {
|
|||||||
user?: UserType;
|
user?: UserType;
|
||||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||||
setTargetDatabase?: React.Dispatch<
|
setTargetDatabase?: React.Dispatch<
|
||||||
React.SetStateAction<DSQL_MYSQL_user_databases_Type>
|
React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>
|
||||||
>;
|
>;
|
||||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||||
metrics?: MetricsType;
|
metrics?: MetricsType;
|
||||||
@ -428,7 +429,7 @@ export interface AddEntryContextType {
|
|||||||
richTextEditors: React.MutableRefObject<RichTextEditorsRefArray[]>;
|
richTextEditors: React.MutableRefObject<RichTextEditorsRefArray[]>;
|
||||||
jsonTextEditors: React.MutableRefObject<JSONTextEditorsRefArray[]>;
|
jsonTextEditors: React.MutableRefObject<JSONTextEditorsRefArray[]>;
|
||||||
query: any;
|
query: any;
|
||||||
duplicateEntry?: any;
|
duplicateEntry: any;
|
||||||
confirmedDelegetedUser: any;
|
confirmedDelegetedUser: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,13 +506,13 @@ export interface SingleDatabaseContextType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiKeysContextType {
|
export interface ApiKeysContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
apiKeys: any[];
|
apiKeys?: any[];
|
||||||
setApiKeys: React.Dispatch<React.SetStateAction<any[]>>;
|
setApiKeys?: React.Dispatch<React.SetStateAction<any[]>>;
|
||||||
targetApiKey: any | null;
|
targetApiKey?: any | null;
|
||||||
setTargetApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
setTargetApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||||
newApiKey: any | null;
|
newApiKey?: any | null;
|
||||||
setNewApiKey: React.Dispatch<React.SetStateAction<any | null>>;
|
setNewApiKey?: React.Dispatch<React.SetStateAction<any | null>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginFormContextType {
|
export interface LoginFormContextType {
|
||||||
@ -544,32 +545,32 @@ export interface DocsAsidePageObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AllUserUsersContextType {
|
export interface AllUserUsersContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
users: MYSQL_delegated_users_table_def[];
|
users?: MYSQL_delegated_users_table_def[];
|
||||||
targetUser: MYSQL_user_users_table_def | null;
|
targetUser?: MYSQL_user_users_table_def | undefined;
|
||||||
setTargetUser: React.Dispatch<
|
setTargetUser?: React.Dispatch<
|
||||||
React.SetStateAction<MYSQL_user_users_table_def | null>
|
React.SetStateAction<MYSQL_user_users_table_def | undefined>
|
||||||
>;
|
>;
|
||||||
databases: DSQL_MYSQL_user_databases_Type[];
|
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||||
pendingInvitations: MYSQL_invitations_table_def[];
|
pendingInvitations?: MYSQL_invitations_table_def[];
|
||||||
pendingInvitationsReceived: any[];
|
pendingInvitationsReceived?: any[];
|
||||||
adminUsers: any[];
|
adminUsers?: any[];
|
||||||
invitedAccounts: any[];
|
invitedAccounts?: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddSocialLoginContextType {
|
export interface AddSocialLoginContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database?: DSQL_MYSQL_user_databases_Type;
|
||||||
query: any;
|
query?: any;
|
||||||
socialLogins: SocialLoginObjectType[];
|
socialLogins?: SocialLoginObjectType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DelegatedDbContextType {
|
export interface DelegatedDbContextType {
|
||||||
user: UserType;
|
user: UserType;
|
||||||
users: MYSQL_user_users_table_def[];
|
users: MYSQL_user_users_table_def[];
|
||||||
targetUser: MYSQL_user_users_table_def | null;
|
targetUser: MYSQL_user_users_table_def | undefined;
|
||||||
setTargetUser: React.Dispatch<
|
setTargetUser: React.Dispatch<
|
||||||
React.SetStateAction<MYSQL_user_users_table_def | null>
|
React.SetStateAction<MYSQL_user_users_table_def | undefined>
|
||||||
>;
|
>;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database: DSQL_MYSQL_user_databases_Type;
|
||||||
}
|
}
|
||||||
@ -585,9 +586,9 @@ export interface AddUserUserContextType {
|
|||||||
export interface UserUsersContextType {
|
export interface UserUsersContextType {
|
||||||
user: UserType;
|
user: UserType;
|
||||||
users: MYSQL_user_users_table_def[];
|
users: MYSQL_user_users_table_def[];
|
||||||
targetUser: MYSQL_user_users_table_def;
|
targetUser?: MYSQL_user_users_table_def;
|
||||||
setTargetUser: React.Dispatch<
|
setTargetUser: React.Dispatch<
|
||||||
React.SetStateAction<MYSQL_user_users_table_def | null>
|
React.SetStateAction<MYSQL_user_users_table_def | undefined>
|
||||||
>;
|
>;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database: DSQL_MYSQL_user_databases_Type;
|
||||||
table: DSQL_TableSchemaType;
|
table: DSQL_TableSchemaType;
|
||||||
@ -717,16 +718,16 @@ export interface UserSchemaContextType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ConnectContextType {
|
export interface ConnectContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
query: any;
|
query?: any;
|
||||||
mariadbUserCred: MariaDBUserCredType;
|
mariadbUserCred?: MariaDBUserCredType;
|
||||||
mariadbUsers: MYSQL_mariadb_users_table_def[];
|
mariadbUsers?: MYSQL_mariadb_users_table_def[];
|
||||||
targetMariadbUser: MYSQL_mariadb_users_table_def | null;
|
targetMariadbUser?: MYSQL_mariadb_users_table_def | null;
|
||||||
setTargetMariadbUser: React.Dispatch<
|
setTargetMariadbUser?: React.Dispatch<
|
||||||
React.SetStateAction<MYSQL_mariadb_users_table_def | null>
|
React.SetStateAction<MYSQL_mariadb_users_table_def | null>
|
||||||
>;
|
>;
|
||||||
refresh: number;
|
refresh?: number;
|
||||||
setRefresh: React.Dispatch<React.SetStateAction<number>>;
|
setRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MYSQL_mariadb_users_table_def {
|
export interface MYSQL_mariadb_users_table_def {
|
||||||
@ -750,7 +751,7 @@ export interface DbContextType {
|
|||||||
databases?: DSQL_MYSQL_user_databases_Type[];
|
databases?: DSQL_MYSQL_user_databases_Type[];
|
||||||
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
targetDatabase?: DSQL_MYSQL_user_databases_Type;
|
||||||
setTargetDatabase?: React.Dispatch<
|
setTargetDatabase?: React.Dispatch<
|
||||||
React.SetStateAction<DSQL_MYSQL_user_databases_Type>
|
React.SetStateAction<DSQL_MYSQL_user_databases_Type | undefined>
|
||||||
>;
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,33 +762,33 @@ export interface MariaDBUserCredType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AddTableContextType {
|
export interface AddTableContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database?: DSQL_MYSQL_user_databases_Type;
|
||||||
tables: DSQL_TableSchemaType[];
|
tables?: DSQL_TableSchemaType[];
|
||||||
tableFields: DSQL_FieldSchemaType[];
|
tableFields?: DSQL_FieldSchemaType[];
|
||||||
setTableFields: React.Dispatch<
|
setTableFields?: React.Dispatch<
|
||||||
React.SetStateAction<DSQL_FieldSchemaType[]>
|
React.SetStateAction<DSQL_FieldSchemaType[]>
|
||||||
>;
|
>;
|
||||||
targetField: DSQL_FieldSchemaType | null;
|
targetField?: DSQL_FieldSchemaType | null;
|
||||||
setTargetField: React.Dispatch<
|
setTargetField?: React.Dispatch<
|
||||||
React.SetStateAction<DSQL_FieldSchemaType | null>
|
React.SetStateAction<DSQL_FieldSchemaType | null>
|
||||||
>;
|
>;
|
||||||
pageRefresh: number | null;
|
pageRefresh?: number | null;
|
||||||
setPageRefresh: React.Dispatch<React.SetStateAction<number>>;
|
setPageRefresh?: React.Dispatch<React.SetStateAction<number>>;
|
||||||
refreshFieldsListRef: React.MutableRefObject<
|
refreshFieldsListRef?: React.MutableRefObject<
|
||||||
React.Dispatch<React.SetStateAction<number>>
|
React.Dispatch<React.SetStateAction<number>> | undefined
|
||||||
>;
|
>;
|
||||||
query: any;
|
query?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DbSchemaContextType {
|
export interface DbSchemaContextType {
|
||||||
user: UserType;
|
user?: UserType;
|
||||||
database: DSQL_MYSQL_user_databases_Type;
|
database?: DSQL_MYSQL_user_databases_Type;
|
||||||
dbImage: string;
|
dbImage?: string;
|
||||||
setDbImage: React.Dispatch<React.SetStateAction<string>>;
|
setDbImage?: React.Dispatch<React.SetStateAction<string>>;
|
||||||
dbSchemaData: DSQL_DatabaseSchemaType[];
|
dbSchemaData?: DSQL_DatabaseSchemaType[];
|
||||||
tables: any[];
|
tables?: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DbShellContextType {
|
export interface DbShellContextType {
|
||||||
|
@ -11,7 +11,7 @@ const MASTER = mysql({
|
|||||||
? Number(process.env.DSQL_DB_PORT)
|
? Number(process.env.DSQL_DB_PORT)
|
||||||
: undefined,
|
: undefined,
|
||||||
charset: "utf8mb4",
|
charset: "utf8mb4",
|
||||||
ssl: grabDbSSL(),
|
// ssl: grabDbSSL(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -120,5 +120,3 @@ export default function DSQL_USER_DB_HANDLER({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = DSQL_USER_DB_HANDLER;
|
|
||||||
|
52
package-shared/utils/db/conn-db-handler.ts
Normal file
52
package-shared/utils/db/conn-db-handler.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import { ServerlessMysql } from "serverless-mysql";
|
||||||
|
|
||||||
|
type QueryObject = {
|
||||||
|
query: string;
|
||||||
|
values?: (string | number | undefined)[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type Return<ReturnType = any> = ReturnType | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* # Run Query From MySQL Connection
|
||||||
|
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||||
|
* setup with `serverless-mysql` npm module
|
||||||
|
*/
|
||||||
|
export default async function connDbHandler<ReturnType = any>(
|
||||||
|
/**
|
||||||
|
* ServerlessMySQL Connection Object
|
||||||
|
*/
|
||||||
|
conn: ServerlessMysql,
|
||||||
|
/**
|
||||||
|
* String Or `QueryObject` Array
|
||||||
|
*/
|
||||||
|
query: QueryObject["query"] | QueryObject[],
|
||||||
|
/**
|
||||||
|
* Array of Values to Sanitize and Inject
|
||||||
|
*/
|
||||||
|
values?: QueryObject["values"]
|
||||||
|
): Promise<Return<ReturnType>> {
|
||||||
|
try {
|
||||||
|
if (typeof query == "string") {
|
||||||
|
const res = await conn.query(query, values);
|
||||||
|
return JSON.parse(JSON.stringify(res));
|
||||||
|
} else if (typeof query == "object") {
|
||||||
|
const resArray = [];
|
||||||
|
for (let i = 0; i < query.length; i++) {
|
||||||
|
const queryObj = query[i];
|
||||||
|
const queryObjRes = await conn.query(
|
||||||
|
queryObj.query,
|
||||||
|
queryObj.values
|
||||||
|
);
|
||||||
|
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
|
||||||
|
}
|
||||||
|
return resArray as any;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
conn.end();
|
||||||
|
}
|
||||||
|
}
|
@ -20,11 +20,11 @@ function parse(
|
|||||||
*/
|
*/
|
||||||
function stringify(
|
function stringify(
|
||||||
value: any,
|
value: any,
|
||||||
replacer?: (this: any, key: string, value: any) => any,
|
replacer?: ((this: any, key: string, value: any) => any) | null,
|
||||||
space?: string | number
|
space?: string | number
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(value, replacer, space);
|
return JSON.stringify(value, replacer || undefined, space);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,4 @@ function endConnection(connection: mysql.Connection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = endConnection;
|
export default endConnection;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "3.4.0",
|
"version": "3.4.1",
|
||||||
"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