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.

96 lines (95 loc) • 2.77 kB
"use strict"; /** * @fileoverview Domain Event Base Class * @version 1.0.0 * @since 2025-07-29 * @lastUpdated 2025-07-29 * @module DomainEvent Base Class * @description Abstract base class for all domain events in the system. * Provides common properties and behavior for event-driven architecture. * @contributors Claude Code Agent * @dependencies crypto (Node.js built-in) * @requirements REQ-ARCH-001 (Clean Architecture Domain Layer) * @testCoverage Unit tests for event behavior and serialization */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DomainEvent = void 0; const crypto_1 = require("crypto"); /** * Abstract Domain Event Base Class * * @description Base class for all domain events. Domain events represent * significant business occurrences that other parts of the system * need to know about. * * @example * ```typescript * class UserRegisteredEvent extends DomainEvent { * constructor(public readonly userId: string, public readonly email: string) { * super('UserRegistered'); * } * } * ``` * * @since 2025-07-29 * @author Claude Code Agent * @requirements REQ-ARCH-001 (Clean Architecture Domain Layer) */ class DomainEvent { constructor(eventType, version = 1) { this.eventType = eventType; this.eventId = (0, crypto_1.randomUUID)(); this.occurredOn = new Date(); this.version = version; } /** * Convert event to plain object for serialization */ toPlainObject() { return { eventId: this.eventId, eventType: this.eventType, aggregateId: this.getAggregateId(), occurredOn: this.occurredOn.toISOString(), version: this.version, data: this.getEventData(), }; } /** * JSON serialization */ toJSON() { return this.toPlainObject(); } /** * String representation for logging */ toString() { return `${this.eventType}(${this.eventId}) occurred on ${this.occurredOn.toISOString()}`; } /** * Check if this event occurred before another event */ occurredBefore(other) { return this.occurredOn < other.occurredOn; } /** * Check if this event occurred after another event */ occurredAfter(other) { return this.occurredOn > other.occurredOn; } /** * Get the age of this event in milliseconds */ getAgeInMs() { return Date.now() - this.occurredOn.getTime(); } /** * Check if event is older than specified milliseconds */ isOlderThan(milliseconds) { return this.getAgeInMs() > milliseconds; } } exports.DomainEvent = DomainEvent;