55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = grabAllDbSchemas;
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const path_1 = __importDefault(require("path"));
|
|
const grab_dir_names_1 = __importDefault(require("../../utils/backend/names/grab-dir-names"));
|
|
const ejson_1 = __importDefault(require("../../utils/ejson"));
|
|
const numberfy_1 = __importDefault(require("../../utils/numberfy"));
|
|
/**
|
|
* # Grab All Database Schemas from Directory
|
|
* @param params
|
|
* @returns
|
|
*/
|
|
function grabAllDbSchemas({ userId, parentDbId, parentTableId, }) {
|
|
try {
|
|
let dbSchemas = [];
|
|
const { targetUserPrivateDir } = (0, grab_dir_names_1.default)({
|
|
userId,
|
|
});
|
|
if (!targetUserPrivateDir) {
|
|
console.log(`targetUserPrivateDir not found!`);
|
|
return undefined;
|
|
}
|
|
const dbSchemasFiles = fs_1.default.readdirSync(targetUserPrivateDir);
|
|
for (let i = 0; i < dbSchemasFiles.length; i++) {
|
|
try {
|
|
const dbSchemaFile = dbSchemasFiles[i];
|
|
const fullPath = path_1.default.join(targetUserPrivateDir, dbSchemaFile);
|
|
const json = fs_1.default.readFileSync(fullPath, "utf-8");
|
|
const dbSchema = ejson_1.default.parse(json);
|
|
if (!dbSchema) {
|
|
continue;
|
|
}
|
|
if (parentDbId) {
|
|
const isDbChild = (0, numberfy_1.default)(dbSchema.childDatabaseDbId) ==
|
|
(0, numberfy_1.default)(parentDbId);
|
|
if (isDbChild) {
|
|
dbSchemas.push(dbSchema);
|
|
}
|
|
continue;
|
|
}
|
|
dbSchemas.push(dbSchema);
|
|
}
|
|
catch (error) { }
|
|
}
|
|
return dbSchemas;
|
|
}
|
|
catch (error) {
|
|
return undefined;
|
|
}
|
|
}
|