envelope

JSON envelope wrapping domain entities with sidecar data. JSON envelope wrapping domain entities with their sidecar data.

Envelope flattens the entity’s own fields into the top level and appends relationship, tag, and (optionally) note collections so that a single JSON response carries everything a consumer needs.

struct Envelope

source

pub struct Envelope<'a, T: Serialize>

A JSON-serializable wrapper that flattens an entity and attaches sidecars.

Field Type Description
entity &'a T The domain entity whose fields are promoted to the top level.
notes Option<Vec<NoteView>> Notes attached to this entity (omitted from output when None).
relationships Vec<RelationshipView> Directed relationships involving this entity.
tags Vec<String> Tag labels attached to this entity.

Implements Clone, Debug, Serialize.

Envelope::load_many

source

pub async fn load_many(
    conn: &Connection,
    entity_type: EntityType,
    entities: &[(Id, &'a T)],
    include_notes: bool,
) -> Result<Vec<Envelope<'a, T>>, Error>

Build envelopes for many entities using batch queries (one query per sidecar type).

Borrows each entity by reference to avoid cloning caller-owned models.

Parameter Type Description
conn &Connection the database connection the sidecars are read from
entity_type EntityType the domain type shared by every entity
entities &[(Id, &'a T)] each entity with its ID, in output order
include_notes bool whether to load notes; when false, notes is None
returns Result<Vec<Envelope<'a, T>>, Error> One envelope per entity, in the order given, or the store error from a sidecar query.

Envelope::load_one

source

pub async fn load_one(
    conn: &Connection,
    entity_type: EntityType,
    entity_id: &Id,
    entity: &'a T,
    include_notes: bool,
) -> Result<Envelope<'a, T>, Error>

Build an envelope for a single entity, loading sidecars from the database.

Parameter Type Description
conn &Connection the database connection the sidecars are read from
entity_type EntityType the domain type of the entity
entity_id &Id the entity’s ID, used to look up its sidecars
entity &'a T the entity, borrowed into the envelope
include_notes bool whether to load notes; when false, notes is None
returns Result<Envelope<'a, T>, Error> The envelope, or the store error from a sidecar query.

struct NoteView

source

pub struct NoteView

Serialization-only view of a note, without entity-linking fields.

Field Type Description
body String Markdown body content.
created_at DateTime<Utc> When the note was first created.
id Id Stable identifier.
updated_at DateTime<Utc> When the note body was last modified.

Implements Clone, Debug, Serialize, From<&Model>.

struct RelationshipView

source

pub struct RelationshipView

Serialization-only view of a relationship, without the source_type field.

Field Type Description
created_at DateTime<Utc> When the relationship was first recorded.
id Id Stable identifier.
rel_type RelationshipType Semantic kind of relationship.
source_id Id Identifier of the source (from-side) entity.
target_id Id Identifier of the target (to-side) entity.
target_type EntityType Domain type of the target entity.
updated_at DateTime<Utc> When the relationship was last modified.

Implements Clone, Debug, Serialize, From<&Model>.