// Development database configuration without external dependencies import { EventEmitter } from 'events'; // Mock Redis client for development class MockRedisClient extends EventEmitter { private storage = new Map(); private isConnected = false; async connect() { this.isConnected = true; console.log('✅ Connected to Mock Redis (Development Mode)'); this.emit('connect'); return this; } async disconnect() { this.isConnected = false; return this; } async set(key: string, value: string) { this.storage.set(key, value); return 'OK'; } async get(key: string) { return this.storage.get(key) || null; } async incr(key: string) { const current = parseInt(this.storage.get(key) || '0'); const newValue = current + 1; this.storage.set(key, newValue.toString()); return newValue; } async expire(key: string, seconds: number) { // In a real implementation, you'd set a timeout return 1; } async hSet(key: string, field: string | Record, value?: string) { if (typeof field === 'string' && value !== undefined) { let hash = this.storage.get(key); if (!hash || typeof hash !== 'object') { hash = {}; } hash[field] = value; this.storage.set(key, hash); return 1; } else if (typeof field === 'object') { let hash = this.storage.get(key); if (!hash || typeof hash !== 'object') { hash = {}; } Object.assign(hash, field); this.storage.set(key, hash); return Object.keys(field).length; } return 0; } async hGetAll(key: string) { const hash = this.storage.get(key); return hash && typeof hash === 'object' ? hash : {}; } async sAdd(key: string, member: string) { let set = this.storage.get(key); if (!Array.isArray(set)) { set = []; } if (!set.includes(member)) { set.push(member); this.storage.set(key, set); return 1; } return 0; } async sRem(key: string, member: string) { let set = this.storage.get(key); if (Array.isArray(set)) { const index = set.indexOf(member); if (index > -1) { set.splice(index, 1); this.storage.set(key, set); return 1; } } return 0; } async sMembers(key: string) { const set = this.storage.get(key); return Array.isArray(set) ? set : []; } async sCard(key: string) { const set = this.storage.get(key); return Array.isArray(set) ? set.length : 0; } async multi() { // Simplified mock - just return this for compatibility return this; } } // Mock PostgreSQL pool for development class MockPgPool extends EventEmitter { private isInitialized = false; async connect() { if (!this.isInitialized) { console.log('✅ Connected to Mock PostgreSQL (Development Mode)'); this.isInitialized = true; } return { query: async (sql: string, params?: any[]) => { // Mock responses for different queries if (sql.includes('CREATE TABLE')) { return { rows: [] }; } if (sql.includes('INSERT INTO users')) { return { rows: [{ id: 'mock-user-id', username: 'MockUser', email: 'mock@example.com', is_guest: true, created_at: new Date(), last_seen: new Date() }] }; } if (sql.includes('SELECT') && sql.includes('users')) { return { rows: [{ id: 'mock-user-id', username: 'MockUser', email: 'mock@example.com', is_guest: true, created_at: new Date(), last_seen: new Date() }] }; } return { rows: [] }; }, release: () => {} }; } async query(sql: string, params?: any[]) { const client = await this.connect(); const result = await client.query(sql, params); client.release(); return result; } } export const redisClient = new MockRedisClient() as any; export const pgPool = new MockPgPool() as any; export async function initializeDatabase(): Promise { try { console.log('🔌 Initializing development database (Mock)...'); // Connect to mock Redis await redisClient.connect(); // Test PostgreSQL connection const client = await pgPool.connect(); console.log('✅ Connected to Mock PostgreSQL'); client.release(); // Create mock tables await createTables(); } catch (error) { console.error('❌ Database initialization failed:', error); throw error; } } async function createTables(): Promise { try { await pgPool.query(`CREATE TABLE IF NOT EXISTS users (...)`); await pgPool.query(`CREATE TABLE IF NOT EXISTS canvases (...)`); await pgPool.query(`CREATE TABLE IF NOT EXISTS user_sessions (...)`); console.log('✅ Database tables created/verified (Mock)'); } catch (error) { console.log('✅ Mock tables setup complete'); } }