Core Types
This document defines the fundamental type definitions that serve as building blocks for the NERV architecture. These types form the foundation upon which the patterns and components are built.
Type Variables
Type variables enable generic programming throughout the NERV architecture, allowing for type-safe abstractions.
Type Variables for Generic Definitions
Variable | Purpose | Used For |
---|---|---|
T | General data | Any generic data type |
S | State | Component state representations |
R | Result | Operation results |
E | Event | Event data types |
V | Value | Values in effectful operations |
P | Perspective | Projected views of data |
K | Key | Dictionary/map keys |
C | Context | Execution context |
M | Message | Communication messages |
T_in | Input | Boundary input types |
T_out | Output | Boundary output types |
Purpose and Usage
Each type variable has a specific semantic meaning within the NERV architecture:
Variable | Purpose | Used For |
---|---|---|
T | General data | Any generic data type |
S | State | Component state representations |
R | Result | Operation results |
E | Event | Event data types |
V | Value | Values in effectful operations |
P | Perspective | Projected views of data |
K | Key | Dictionary/map keys |
C | Context | Execution context |
M | Message | Communication messages |
T_in | Input | Boundary input types |
T_out | Output | Boundary output types |
Identity Types
Identity types provide unique identification for various entities in the system.
Identity Types
Type | Definition | Purpose |
---|---|---|
EntityId | String identifier | Unique identifier for any entity in the system |
VersionId | String identifier | Unique identifier for a versioned state |
ResourceId | String identifier | Identifier for a resource |
EventId | String identifier | Identifier for an event |
Purpose and Usage
These identity types provide consistent identification across the system:
Type | Purpose | Used For |
---|---|---|
EntityId | Identify any entity | Component references |
VersionId | Identify versions | State history tracking |
ResourceId | Identify resources | Resource management |
EventId | Identify events | Event correlation |
Core Enumerations
Enumerations define fixed sets of values for various aspects of the system.
EventType Enumeration
The EventType enumeration defines the core event types in the system:
System Lifecycle Events
SYSTEM_INIT
: System initializationSYSTEM_SHUTDOWN
: System shutdown
Provider Events
PROVIDER_CREATED
: Provider instance createdPROVIDER_CONNECTED
: Provider connected to servicePROVIDER_DISCONNECTED
: Provider disconnected from servicePROVIDER_ERROR
: Provider encountered an error
(Plus many more event types…)
EffectType Enumeration
The EffectType enumeration defines types of side effects in the system:
I/O Effects
FILE_READ
: Reading from a fileFILE_WRITE
: Writing to a fileNETWORK_REQUEST
: Making a network requestDATABASE_QUERY
: Querying a database
(Plus more effect types…)
LifecycleState Enumeration
The LifecycleState enumeration defines lifecycle states for stateful components:
CREATED
: Component has been instantiatedINITIALIZING
: Component is initializing resourcesREADY
: Component is ready but not activeACTIVE
: Component is actively processingPAUSED
: Component is temporarily pausedSTOPPING
: Component is in the process of stoppingSTOPPED
: Component has stopped but not disposedERROR
: Component is in an error stateDISPOSED
: Component has been disposed
StreamState Enumeration
The StreamState enumeration defines states for streaming operations:
PENDING
: Stream operation pending startACTIVE
: Stream is actively flowingPAUSED
: Stream is temporarily pausedCOMPLETED
: Stream has successfully completedCANCELLED
: Stream was cancelled by userERROR
: Stream encountered an error
ResourceType Enumeration
The ResourceType enumeration defines types of managed resources:
CONNECTION
: Network connection resourceFILE
: File system resourceTHREAD
: Thread resourcePROCESS
: Process resourceSOCKET
: Socket resourceDATABASE
: Database connection resourceMODEL
: Model resource
UnitState Enumeration
The UnitState enumeration defines possible states for a quantum unit:
PENDING
: Not yet executedREADY
: Ready to execute (dependencies satisfied)RUNNING
: Currently executingCOMPLETED
: Successfully completedFAILED
: Execution failedCANCELLED
: Execution cancelled
Core Data Classes
Data classes define structured data types used throughout the system.
Event Data Class
The Event data class represents the core event structure for the event bus:
Fields:
id
: EventId - Unique identifier generated using UUIDtype
: EventType - The type of eventdata
: Optional[T] - Optional event payload datatimestamp
: float - When the event occurredsource
: Optional[EntityId] - Optional source entity ID
Effect Data Class
The Effect data class represents a side effect:
Fields:
type
: EffectType - The type of effectpayload
: Any - Optional effect payloaddescription
: str - Human-readable description
Resource Data Class
The Resource data class represents a managed resource:
Fields:
id
: ResourceId - Unique resource identifiertype
: ResourceType - The type of resourcestate
: LifecycleState - Current lifecycle statecreated_at
: float - Creation timestampmetadata
: Dict[str, Any] - Additional resource metadata
VersionedState Data Class
The VersionedState data class represents a state with version history information:
Fields:
version_id
: str - Unique version identifierdata
: Any - The versioned dataparent_version_id
: Optional[str] - Optional parent versiontimestamp
: float - When this version was createdchange_description
: str - Description of the change
UnitResult Data Class
The UnitResult data class represents the result of a quantum unit execution:
Fields:
success
: bool - Whether execution succeededvalue
: Optional[R] - Optional result valueerror
: Optional[Exception] - Optional error if failedexecution_time
: float - How long execution tookmetadata
: Dict[str, Any] - Additional execution metadata
ValidationResult Data Class
The ValidationResult data class represents the result of data validation at a boundary:
Fields:
is_valid
: bool - Whether validation succeededdata
: Optional[T_out] - Optional validated dataerrors
: List[Dict[str, Union[str, int, float, bool]]] - Validation errors
DeltaMetadata Data Class
The DeltaMetadata data class contains metadata about a delta change:
Fields:
timestamp
: float - When the delta was createdsource
: Optional[EntityId] - Optional source entitydescription
: str - Human-readable descriptiontags
: List[str] - Optional categorization tags
Error Types
Error classes define the hierarchy of exceptions used in the system.
Error Hierarchy
Base Error Class:
AtlasError
: Base class for all Atlas errors- Fields: message, details dictionary
Boundary Error Classes:
BoundaryError
: Base class for boundary errors- Additional field: boundary name
- Inherits from AtlasError
Specialized Boundary Errors:
ValidationError
: For validation failures- Additional field: validation_errors list
- Inherits from BoundaryError
NetworkError
: For network failures- Additional fields: status_code, response
- Inherits from BoundaryError
Abstract Base Classes
Abstract base classes provide partial implementations of interfaces.
Delta Abstract Base Class
The Delta abstract base class represents a change to be applied to a state:
Factory Methods:
function_delta(fn)
: Creates a delta from a state transformation functionpatch_delta(patch)
: Creates a delta from a dictionary patch
Abstract Methods:
apply(state)
: Abstract method to apply the delta to a state
Delta Implementations
FunctionDelta:
- Represents a delta as a function that transforms state
- Takes a transform function in constructor
- Implements apply() by calling the function on the state
PatchDelta:
- Represents a delta as a dictionary patch
- Takes a patch dictionary in constructor
- Implements apply() by merging the patch with the state dictionary
Type Relationships
These core types form the foundation of the NERV architecture:
- Type Variables enable generic programming across the system
- Identity Types provide consistent identification schemes
- Enumerations define fixed sets of values with semantic meaning
- Data Classes define structured data with clear semantics
- Error Types provide a consistent error handling hierarchy
- Abstract Base Classes provide partial implementations for reuse
These core types are used to build the more complex interfaces that define component behavior, which in turn are implemented by the components of the system.