UNPKG

curriculum-mcp

Version:

A Model Context Protocol (MCP) server for managing online course curriculum, todos, project components, APIs, coding standards, and now, full course curriculums. This server provides tools and resources for Claude Code to interact with your project's know

184 lines 7.3 kB
"use strict"; 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.DatabaseManager = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const DB_PATH = path.join(process.cwd(), 'data', 'db.json'); class DatabaseManager { constructor() { this.db = this.loadDatabase(); } static getInstance() { if (!DatabaseManager.instance) { DatabaseManager.instance = new DatabaseManager(); } return DatabaseManager.instance; } loadDatabase() { try { // Ensure data directory exists const dataDir = path.dirname(DB_PATH); if (!fs.existsSync(dataDir)) { fs.mkdirSync(dataDir, { recursive: true }); } // Load existing database or create new one if (fs.existsSync(DB_PATH)) { const data = fs.readFileSync(DB_PATH, 'utf8'); const parsedDb = JSON.parse(data); // Ensure all required collections exist const initialDb = { components: [], apis: [], environment: [], 'style-guide': [], state: [], hooks: [], conventions: [], units: [], lessons: [], lessonPhases: [], appConnections: [], assessments: [], tasks: [] }; // Merge with existing data, ensuring all arrays exist return { ...initialDb, ...parsedDb, // Ensure arrays are actually arrays components: Array.isArray(parsedDb.components) ? parsedDb.components : [], apis: Array.isArray(parsedDb.apis) ? parsedDb.apis : [], environment: Array.isArray(parsedDb.environment) ? parsedDb.environment : [], 'style-guide': Array.isArray(parsedDb['style-guide']) ? parsedDb['style-guide'] : [], state: Array.isArray(parsedDb.state) ? parsedDb.state : [], hooks: Array.isArray(parsedDb.hooks) ? parsedDb.hooks : [], conventions: Array.isArray(parsedDb.conventions) ? parsedDb.conventions : [], units: Array.isArray(parsedDb.units) ? parsedDb.units : [], lessons: Array.isArray(parsedDb.lessons) ? parsedDb.lessons : [], lessonPhases: Array.isArray(parsedDb.lessonPhases) ? parsedDb.lessonPhases : [], appConnections: Array.isArray(parsedDb.appConnections) ? parsedDb.appConnections : [], assessments: Array.isArray(parsedDb.assessments) ? parsedDb.assessments : [], tasks: Array.isArray(parsedDb.tasks) ? parsedDb.tasks : [] }; } else { // Initialize empty database const initialDb = { components: [], apis: [], environment: [], 'style-guide': [], state: [], hooks: [], conventions: [], units: [], lessons: [], lessonPhases: [], appConnections: [], assessments: [], tasks: [] }; this.saveDatabase(initialDb); return initialDb; } } catch (error) { throw new Error(`Failed to load database: ${error}`); } } saveDatabase(db) { try { fs.writeFileSync(DB_PATH, JSON.stringify(db, null, 2)); } catch (error) { throw new Error(`Failed to save database: ${error}`); } } getDatabase() { return this.db; } updateDatabase(updates) { this.db = { ...this.db, ...updates }; this.saveDatabase(this.db); } // Generic CRUD operations getCollection(collectionName) { return this.db[collectionName]; } addToCollection(collectionName, item) { const collection = this.db[collectionName]; // Ensure collection exists and is an array if (!collection || !Array.isArray(collection)) { throw new Error(`Collection ${collectionName} is not properly initialized`); } // Check if item with same ID already exists if (collection.some(existing => existing.id === item.id)) { throw new Error(`Item with ID ${item.id} already exists in ${collectionName}`); } collection.push(item); this.saveDatabase(this.db); return item; } updateInCollection(collectionName, id, updates) { const collection = this.db[collectionName]; const index = collection.findIndex(item => item.id === id); if (index === -1) { return null; } collection[index] = { ...collection[index], ...updates }; this.saveDatabase(this.db); return collection[index]; } deleteFromCollection(collectionName, id) { const collection = this.db[collectionName]; const index = collection.findIndex(item => item.id === id); if (index === -1) { return false; } collection.splice(index, 1); this.saveDatabase(this.db); return true; } findById(collectionName, id) { const collection = this.db[collectionName]; return collection.find(item => item.id === id) || null; } generateId() { return Date.now().toString(36) + Math.random().toString(36).substr(2); } } exports.DatabaseManager = DatabaseManager; //# sourceMappingURL=database.js.map