This commit is contained in:
Benjamin Toby
2025-01-13 09:00:21 +01:00
parent 6364f6a312
commit e0a030f10d
859 changed files with 5397 additions and 10163 deletions
@@ -1,11 +1,11 @@
// @ts-check
const fs = require("fs");
const path = require("path");
import fs from "fs";
import path from "path";
const excludeRegexp = /\/node_modules|\/dump|\/.tmp|\/.next/;
function traverse(/** @type {String} - Directory path */ dir) {
function traverse(dir: string) {
const files = fs.readdirSync(dir);
if (dir.match(excludeRegexp)) return;
@@ -1,13 +1,15 @@
// @ts-check
const { execSync } = require("child_process");
import { execSync } from "child_process";
/**
*
* @param {number | string | null | undefined} port
* @returns
*/
module.exports = async function killProcessOnPort(port) {
export default async function killProcessOnPort(
port: number | string | null | undefined
) {
if (!port) {
console.error("Error: No port specified");
return;
@@ -41,7 +43,7 @@ module.exports = async function killProcessOnPort(port) {
)
.toString()
.trim();
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
console.log(
`Error finding PID on ${process.platform}:`,
error.message
@@ -62,7 +64,7 @@ module.exports = async function killProcessOnPort(port) {
execSync(`kill -9 ${processId}`);
}
console.log(`Killed process ${processId} on port ${targetPort}`);
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
console.error("Error:", error.message);
}
};
}
@@ -1,12 +1,12 @@
// @ts-check
const httpsRequest = require("../package-shared/functions/backend/httpsRequest");
const cron = require("cron");
const path = require("path");
const { dbSchemaExecDbUpdate } = require("../functions/backend/dbSchemaExec");
const dbHandler = require("../package-shared/functions/backend/dbHandler");
import httpsRequest from "../package-shared/functions/backend/httpsRequest";
import cron from "cron";
import path from "path";
import { dbSchemaExecDbUpdate } from "../functions/backend/dbSchemaExec";
import dbHandler from "../package-shared/functions/backend/dbHandler";
module.exports = async function () {
export default async function () {
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
@@ -15,7 +15,9 @@ module.exports = async function () {
"20 * * * * *",
async () => {
/** @type {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type[] | null} */ // @ts-ignore
const remoteConnectedDbs = await dbHandler(
const remoteConnectedDbs:
| import("@/package-shared/types").DSQL_MYSQL_user_databases_Type[]
| null = await dbHandler(
`SELECT * FROM user_databases WHERE remote_connected = 1`
);
@@ -34,7 +36,7 @@ module.exports = async function () {
} = database;
if (database.remote_connection_type == "pull") {
const dbSchema = await httpsRequest({
const dbSchema = (await httpsRequest({
url: remote_connection_host,
headers: {
Authorization: remote_connection_key,
@@ -45,11 +47,13 @@ module.exports = async function () {
/^datasquirel_user_\d+_/i,
""
)}`,
});
})) as any;
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | null | undefined} */
const remoteDbSchemaData =
JSON.parse(dbSchema).payload;
const remoteDbSchemaData:
| import("@/package-shared/types").DSQL_DatabaseSchemaType
| null
| undefined = JSON.parse(dbSchema).payload;
if (remoteDbSchemaData) {
const update = dbSchemaExecDbUpdate({
@@ -61,7 +65,7 @@ module.exports = async function () {
console.log(update);
}
}
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
console.log(error.message);
}
}
@@ -75,4 +79,4 @@ module.exports = async function () {
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
};
}
@@ -1,7 +1,7 @@
// @ts-check
const fs = require("fs");
const path = require("path");
import fs from "fs";
import path from "path";
const ignorePattern = /node_modules/;
@@ -15,7 +15,7 @@ const searchMatchPattern = {
* @param {object} param0
* @param {string} param0.dir
*/
function replaceDir({ dir }) {
function replaceDir({ dir }: { dir: string }) {
const dirContent = fs.readdirSync(dir);
dirContent.forEach((fileFolder, index) => {
const fileFolderPath = path.join(dir, fileFolder);
@@ -1,6 +1,6 @@
// @ts-check
const fs = require("fs");
const path = require("path");
import fs from "fs";
import path from "path";
const isLocal = process.env.NEXT_PUBLIC_DSQL_LOCAL || null;
const production = process.env.NODE_ENV == "production";
@@ -11,7 +11,7 @@ const isBuilding = process.env.BUILDING_APP;
* @description This returns the relative path from the CWD. Eg `./.dist/build-1`
* @returns {string | undefined}
*/
function grabDist() {
export default function grabDist(): string | undefined {
if (isLocal) {
return ".local_dist";
}
@@ -28,7 +28,7 @@ function grabDist() {
"utf-8"
);
return `.dist/build-${buildNumber}`;
} catch (/** @type {*} */ error) {
} catch (/** @type {*} */ error: any) {
console.log("Build Number Generation Error =>", error.message);
process.exit();
}
@@ -47,7 +47,7 @@ function grabDist() {
"utf-8"
);
return `.dist/build-${buildNumber}`;
} catch (/** @type {*} */ error) {
} catch (/** @type {*} */ error: any) {
console.log("Build Number Parse Error =>", error.message);
process.exit();
}
@@ -58,5 +58,3 @@ function grabDist() {
return undefined;
}
module.exports = grabDist;
@@ -1,19 +1,14 @@
// @ts-check
const http = require("http");
const path = require("path");
const fs = require("fs");
const { Server } = require("socket.io");
const { parse } = require("url");
const parseCookies = require("@moduletrace/datasquirel/utils/functions/parseCookies");
const suSocketAuth = require("../package-shared/functions/backend/suSocketAuth");
const pty = require("node-pty");
import { Server as HttpServer } from "http";
import path from "path";
import fs from "fs";
import { Server } from "socket.io";
import { parse } from "url";
import suSocketAuth from "../package-shared/functions/backend/suSocketAuth";
import parseCookies from "@/package-shared/utils/backend/parseCookies";
/**
*
* @param {http.Server} server
*/
module.exports = async function serverSocket(server) {
export default async function serverSocket(server: HttpServer) {
const io = new Server(server);
io.on("connection", async (socket) => {
@@ -37,7 +32,7 @@ module.exports = async function serverSocket(server) {
socket.emit("console", "Welcome");
process.stdin.on("data", (data) => {
console.log("STDOUT data =>", data.toString("utf8"));
console.log("STDOUT data =>", data.toString());
});
const originalConsoleLog = console.log;
@@ -76,44 +71,32 @@ module.exports = async function serverSocket(server) {
const CANCEL = "\x03";
const RESUME = "\x11";
const ptyProcess = pty.spawn("bash", [], {
name: "xterm-color",
});
// const ptyProcess = pty.spawn("bash", [], {
// name: "xterm-color",
// });
socket.on("shell", (message) => {
ptyProcess.write(message);
});
// socket.on("shell", (message) => {
// ptyProcess.write(message);
// });
ptyProcess.onData((data) => {
socket.emit("shell", data);
});
// ptyProcess.onData((data) => {
// socket.emit("shell", data);
// });
socket.on("disconnect", () => {
ptyProcess.kill("SIGTERM");
});
// socket.on("disconnect", () => {
// ptyProcess.kill("SIGTERM");
// });
}
socket.on("clear-log", (message) => {
if (fs.existsSync(logPath))
fs.writeFileSync(logPath, "", "utf-8");
});
//////////////////////////////////////////
//////////////////////////////////////////
//////////////////////////////////////////
} catch (/** @type {any} */ error) {
//////////////////////////////////////////
//////////////////////////////////////////
//////////////////////////////////////////
} catch (error: any) {
console.log("Error in Console socket =>", error.message);
}
break;
//////////////////////////////////////////
//////////////////////////////////////////
//////////////////////////////////////////
default:
break;
}
@@ -122,4 +105,4 @@ module.exports = async function serverSocket(server) {
io.on("error", (err) => {
console.log("Socket Server Error =>", err);
});
};
}
@@ -1,14 +1,14 @@
// @ts-check
const fs = require("fs");
const path = require("path");
import fs from "fs";
import path from "path";
require("dotenv").config({
path: path.resolve(__dirname, "../.env"),
});
const grabDbSSL = require("../package-shared/utils/backend/grabDbSSL");
const mysql = require("serverless-mysql");
import grabDbSSL from "../package-shared/utils/backend/grabDbSSL";
import mysql from "serverless-mysql";
const connection = mysql({
config: {
@@ -33,13 +33,13 @@ if (!table) {
connection
.query("SHOW COLUMNS FROM" + " " + table)
.then((result) => {
.then((result: any) => {
let typedefStart = `/**\n * @typedef {object} MYSQL_${table}_table_def\n`;
let typedefMid = "";
let typedefEnd = ` */`;
console.log("Result =>", result);
result.forEach((/** @type {any} */ res) => {
result.forEach((res: any) => {
const parsedResult = JSON.parse(JSON.stringify(res));
const { Field, Type, Null, Key, Default, Extra } = parsedResult;
const type = (() => {