mcp-quiz-server
Version:
🧠AI-Powered Quiz Management via Model Context Protocol (MCP) - Create, manage, and take quizzes directly from VS Code, Claude, and other AI agents.
87 lines (86 loc) • 2.72 kB
JavaScript
"use strict";
/**
* @fileoverview Base Command Interface - Application Layer
* @version 1.0.0
* @since 2025-07-30
* @lastUpdated 2025-07-30
* @module Command
* @description Base command interface for CQRS implementation in Clean Architecture.
* All commands must implement this interface for consistent handling.
* @contributors Claude Code Agent
* @dependencies None (core application interface)
* @requirements REQ-ARCH-001 (Clean Architecture Application Layer)
* @testCoverage Unit tests for command validation and serialization
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandProcessingError = exports.CommandValidationError = exports.BaseCommand = void 0;
/**
* Base Command Implementation
*
* @description Abstract base class providing common command functionality
*/
class BaseCommand {
constructor(data, userId, correlationId) {
this.data = data;
this.userId = userId;
this.commandId = this.generateCommandId();
this.timestamp = new Date();
this.correlationId = correlationId || this.generateCorrelationId();
}
/**
* Default validation - override in specific commands
*/
isValid() {
return this.data !== null && this.data !== undefined;
}
/**
* Generate command summary for auditing
*/
toSummary() {
return {
commandId: this.commandId,
commandType: this.commandType,
timestamp: this.timestamp,
userId: this.userId,
dataSize: JSON.stringify(this.data).length,
validationStatus: this.isValid() ? 'valid' : 'invalid',
};
}
/**
* Generate unique command ID
*/
generateCommandId() {
return `cmd_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
/**
* Generate correlation ID for tracking
*/
generateCorrelationId() {
return `corr_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
}
exports.BaseCommand = BaseCommand;
/**
* Command Validation Error
*/
class CommandValidationError extends Error {
constructor(message, command, validationErrors) {
super(message);
this.command = command;
this.validationErrors = validationErrors;
this.name = 'CommandValidationError';
}
}
exports.CommandValidationError = CommandValidationError;
/**
* Command Processing Error
*/
class CommandProcessingError extends Error {
constructor(message, command, cause) {
super(message);
this.command = command;
this.cause = cause;
this.name = 'CommandProcessingError';
}
}
exports.CommandProcessingError = CommandProcessingError;