UNPKG

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.

89 lines (88 loc) • 2.43 kB
"use strict"; /** * @fileoverview QuestionId Value Object - Domain Identifier * @version 1.0.0 * @since 2025-07-29 * @lastUpdated 2025-07-29 * @module QuestionId Value Object * @description Immutable value object representing a Question identifier with validation * @contributors Claude Code Agent * @dependencies crypto (Node.js built-in) * @requirements REQ-ARCH-001 (Clean Architecture Domain Layer) * @testCoverage Unit tests for value object behavior and validation */ Object.defineProperty(exports, "__esModule", { value: true }); exports.QuestionId = void 0; const crypto_1 = require("crypto"); /** * QuestionId Value Object * * @description Immutable value object that ensures question identifiers are valid UUIDs. * Provides type safety and encapsulates ID generation logic. * * @example * ```typescript * const questionId = QuestionId.generate(); * const existingId = QuestionId.fromString('123e4567-e89b-12d3-a456-426614174000'); * ``` * * @since 2025-07-29 * @author Claude Code Agent * @requirements REQ-ARCH-001 (Clean Architecture Domain Layer) */ class QuestionId { constructor(_value) { this._value = _value; this.validate(); } /** * Generate a new QuestionId with a UUID v4 */ static generate() { return new QuestionId((0, crypto_1.randomUUID)()); } /** * Create QuestionId from existing string value */ static fromString(value) { return new QuestionId(value); } /** * Get the string value of the ID */ get value() { return this._value; } /** * Check equality with another QuestionId */ equals(other) { return this._value === other._value; } /** * String representation */ toString() { return this._value; } /** * JSON serialization */ toJSON() { return this._value; } /** * Validate the ID format (UUID v4) */ validate() { if (!this._value) { throw new Error('QuestionId cannot be empty'); } // UUID v4 regex pattern const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; if (!uuidPattern.test(this._value)) { throw new Error(`Invalid QuestionId format: ${this._value}. Must be a valid UUID v4.`); } } } exports.QuestionId = QuestionId;