Skip to main content

Core Protocols

PrismFoundation defines the base protocols used across every Prism module. They provide consistent patterns for modeling data, handling errors, generating test fixtures, and logging.

PrismEntity

The standard protocol for data models. Combines Codable, Equatable, Hashable, CustomStringConvertible, and PrismLogger into a single conformance with automatic JSON serialization and logging.
Defining an Entity
PrismEntity arrays also conform automatically — [User] is itself a PrismEntity and can call .log() directly.

PrismError

A typed error protocol that extends Error, LocalizedError, and PrismLogger. Provides structured error descriptions with failure reasons and recovery suggestions.
Defining a Custom Error

PrismMock

A protocol for generating test data. Provides a mock instance and a mocks array (default: 10 items).
Defining Mock Data
Override static var mocks: [Self] if you need a custom collection size or varied data.

PrismLogger

The simplest logging protocol — a single log() method. Both PrismEntity and PrismError conform to it, so any model or error can log itself.
Custom Logger Conformance

PrismSystemLogger

A more structured logging protocol that wraps os.Logger with typed log messages.
System Logger

Protocol Hierarchy

PrismEntity

Codable + Equatable + Hashable + CustomStringConvertible + PrismLogger. The base for all data models. Auto-generates JSON description and logging.

PrismError

Error + LocalizedError + PrismLogger. Structured errors with description, failure reason, and recovery suggestion. Auto-logs all three fields.

PrismMock

Test data generation with mock and mocks. Default implementation provides 10-item arrays.

PrismLogger / PrismSystemLogger

Simple log() protocol and os.Logger wrapper with typed messages for info, warning, and error levels.