Problem
The existing protobuf-generated Entity Reference API allows inconsistent states:
- Multiple entities can reference and change the same attribute
- Duplicate entity types per resource
- Manual synchronization between entity keys and attributes
- Dangling references to non-existent attributes
Proposed Solution
Introduce a higher-level API (to eventually replace the protobuf-generated one) that ensures data integrity and enforces the following requirements:
Attribute Synchronization
Provide a simple API for modifying entity attributes that keeps both the entity’s attribute key fields and the shared attributes map in sync.
Attribute Ownership
Each resource attribute key must be owned by at most one entity. Adding an attribute to an entity should only be allowed if no existing attribute with the same key exists in the shared resource attributes map. The API for reading an entity’s attributes should return only the attributes it owns.
Entity Type Uniqueness
The API must enforce that all entities associated with a resource have unique types.