@tucmc/hazel
Version:
Clubs Data Processing Framework
54 lines (53 loc) • 2.56 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Database = void 0;
const process = __importStar(require("process"));
const Colour_1 = require("../debugger/Colour");
const Debugger_1 = require("../debugger/Debugger");
class Database {
db;
debug = new Debugger_1.Debugger(this.constructor.name || 'DBUnit');
constructor() {
this.db = this.initDB();
}
getDB() {
if (this.isProdDB()) {
if (process.env.RUNTIME_MODE !== 'PROD') {
throw Error(`${Colour_1.ConsoleColour.RED} Accessing production database in DEV mode is prohibited.\n${Colour_1.ConsoleColour.RESET}${Colour_1.ConsoleColour.BGYELLOW}Please change your runtime mode to ${Colour_1.ConsoleColour.BOLD}PROD${Colour_1.ConsoleColour.RESET}${Colour_1.ConsoleColour.BGYELLOW} in order to connect to the production database.\n${Colour_1.ConsoleColour.RESET}`);
}
this.debug.warn('accessing production database. Please check your snippet carefully in case of unintended changes.');
if (process.env.SKIP_YESNO !== 'yes') {
const con = this.debug.pauseForYNQuestion();
if (!con) {
throw Error(`${Colour_1.ConsoleColour.RED} user terminated the snippet.${Colour_1.ConsoleColour.RESET}`);
}
}
this.debug.info('action authorised. Note: The snippet might manipulate the production database.');
}
return this.db;
}
}
exports.Database = Database;