pub struct ServiceDef {
pub name: String,
pub display_name: Option<String>,
pub description: Option<String>,
pub fields: Vec<FieldDef>,
pub actions: Vec<ActionDef>,
pub guards: Vec<GuardDef>,
pub relationships: Vec<RelationshipDef>,
pub intent_hints: Vec<IntentHint>,
pub state_machine: Option<StateMachine>,
}Expand description
A service definition describing a domain entity and its fields.
Constructed via a builder API with method chaining:
use ferro_projections::{ServiceDef, DataType, FieldMeaning};
let order = ServiceDef::new("order")
.display_name("Order")
.description("Manages customer orders")
.field("id", DataType::Integer, FieldMeaning::Identifier)
.field("total", DataType::Float, FieldMeaning::Money)
.optional_field("notes", DataType::String, FieldMeaning::FreeText);Fields§
§name: String§display_name: Option<String>§description: Option<String>§fields: Vec<FieldDef>§actions: Vec<ActionDef>§guards: Vec<GuardDef>§relationships: Vec<RelationshipDef>§intent_hints: Vec<IntentHint>§state_machine: Option<StateMachine>Implementations§
Source§impl ServiceDef
impl ServiceDef
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Creates a new service definition with the given name.
Sourcepub fn display_name(self, name: impl Into<String>) -> Self
pub fn display_name(self, name: impl Into<String>) -> Self
Sets the human-readable display name.
Sourcepub fn description(self, desc: impl Into<String>) -> Self
pub fn description(self, desc: impl Into<String>) -> Self
Sets the service description.
Sourcepub fn field(
self,
name: impl Into<String>,
data_type: DataType,
meaning: FieldMeaning,
) -> Self
pub fn field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self
Adds a required read-write field.
Sourcepub fn optional_field(
self,
name: impl Into<String>,
data_type: DataType,
meaning: FieldMeaning,
) -> Self
pub fn optional_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self
Adds an optional (nullable) read-write field.
Sourcepub fn list_field(
self,
name: impl Into<String>,
data_type: DataType,
meaning: FieldMeaning,
) -> Self
pub fn list_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self
Adds a required read-write list field.
Sourcepub fn read_only_field(
self,
name: impl Into<String>,
data_type: DataType,
meaning: FieldMeaning,
) -> Self
pub fn read_only_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self
Adds a required read-only field (readable but not writable).
For system-assigned or computed fields like id, created_at, or totals.
Sourcepub fn write_only_field(
self,
name: impl Into<String>,
data_type: DataType,
meaning: FieldMeaning,
) -> Self
pub fn write_only_field( self, name: impl Into<String>, data_type: DataType, meaning: FieldMeaning, ) -> Self
Adds a required write-only field (writable but not readable).
For sensitive inputs like passwords or API keys that should not be read back.
Sourcepub fn relationship(self, rel: RelationshipDef) -> Self
pub fn relationship(self, rel: RelationshipDef) -> Self
Adds a relationship definition to this service.
Sourcepub fn belongs_to(
self,
name: impl Into<String>,
target: impl Into<String>,
) -> Self
pub fn belongs_to( self, name: impl Into<String>, target: impl Into<String>, ) -> Self
Adds a many-to-one relationship (this service belongs to target).
Sourcepub fn has_many(
self,
name: impl Into<String>,
target: impl Into<String>,
) -> Self
pub fn has_many( self, name: impl Into<String>, target: impl Into<String>, ) -> Self
Adds a one-to-many relationship (this service has many of target).
Sourcepub fn has_one(self, name: impl Into<String>, target: impl Into<String>) -> Self
pub fn has_one(self, name: impl Into<String>, target: impl Into<String>) -> Self
Adds a one-to-one relationship (this service has one of target).
Sourcepub fn belongs_to_many(
self,
name: impl Into<String>,
target: impl Into<String>,
) -> Self
pub fn belongs_to_many( self, name: impl Into<String>, target: impl Into<String>, ) -> Self
Adds a many-to-many relationship (this service belongs to many of target).
Sourcepub fn intent_hint(self, hint: IntentHint) -> Self
pub fn intent_hint(self, hint: IntentHint) -> Self
Adds an intent hint for overriding structural derivation.
Sourcepub fn state_machine(self, machine: StateMachine) -> Self
pub fn state_machine(self, machine: StateMachine) -> Self
Sets the state machine definition for this service.
Sourcepub fn from_model(meta: &ModelMetadata) -> Self
pub fn from_model(meta: &ModelMetadata) -> Self
Derives a ServiceDef from model metadata.
Infers DataType from column type strings and FieldMeaning from field names.
System fields (id, created_at, updated_at, primary keys) are marked read-only.
Actions, state machines, and relationships are not derived.
Sourcepub fn validate(&self) -> Result<Vec<Warning>, Error>
pub fn validate(&self) -> Result<Vec<Warning>, Error>
Validates the service definition and returns warnings for potential issues.
This is the single validation entry point that subsumes StateMachine::validate().
Guard names form a shared pool referenced from transitions and action preconditions.
Returns Err for fatal issues (undefined guard references, unmatched triggers).
Returns Ok(warnings) for structural concerns (unused guards, missing state machine).
Trait Implementations§
Source§impl Clone for ServiceDef
impl Clone for ServiceDef
Source§fn clone(&self) -> ServiceDef
fn clone(&self) -> ServiceDef
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServiceDef
impl Debug for ServiceDef
Source§impl<'de> Deserialize<'de> for ServiceDef
impl<'de> Deserialize<'de> for ServiceDef
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for ServiceDef
impl JsonSchema for ServiceDef
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more