UNPKG

adpa-enterprise-framework-automation

Version:

Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe

76 lines 2.57 kB
// Database Configuration // filepath: src/config/database.ts import mongoose from 'mongoose'; import { logger } from '../utils/logger.js'; const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/requirements-gathering-agent'; export class DatabaseConnection { static instance; isConnected = false; constructor() { } static getInstance() { if (!DatabaseConnection.instance) { DatabaseConnection.instance = new DatabaseConnection(); } return DatabaseConnection.instance; } async connect() { if (this.isConnected) { logger.info('📊 Database already connected'); return; } try { await mongoose.connect(MONGODB_URI, { maxPoolSize: 10, serverSelectionTimeoutMS: 5000, socketTimeoutMS: 45000, }); this.isConnected = true; logger.info(`📊 Connected to MongoDB: ${MONGODB_URI}`); mongoose.connection.on('error', (error) => { logger.error('❌ MongoDB connection error:', error); this.isConnected = false; }); mongoose.connection.on('disconnected', () => { logger.warn('⚠️ MongoDB disconnected'); this.isConnected = false; }); mongoose.connection.on('reconnected', () => { logger.info('🔄 MongoDB reconnected'); this.isConnected = true; }); } catch (error) { logger.error('❌ Failed to connect to MongoDB:', error); this.isConnected = false; throw error; } } async disconnect() { if (!this.isConnected) { return; } try { await mongoose.disconnect(); this.isConnected = false; logger.info('📊 Disconnected from MongoDB'); } catch (error) { logger.error('❌ Error disconnecting from MongoDB:', error); throw error; } } isConnectionActive() { return this.isConnected && mongoose.connection.readyState === 1; } getConnectionStatus() { const states = { 0: 'disconnected', 1: 'connected', 2: 'connecting', 3: 'disconnecting' }; return states[mongoose.connection.readyState] || 'unknown'; } } export const dbConnection = DatabaseConnection.getInstance(); //# sourceMappingURL=database.js.map