lightspeed/data_ergonomics
ORM/data ergonomics parity profile contracts for M57.
Types
Dashboard summary for common status cards.
pub type DashboardSummary {
DashboardSummary(
total_rows: Int,
draft_rows: Int,
published_rows: Int,
stale_rows: Int,
)
}
Constructors
-
DashboardSummary( total_rows: Int, draft_rows: Int, published_rows: Int, stale_rows: Int, )
Typed data errors for CRUD and concurrency flows.
pub type DataError {
ValidationFailed(String)
NotFound(String)
ConcurrencyConflict(id: String, expected: Int, actual: Int)
}
Constructors
-
ValidationFailed(String) -
NotFound(String) -
ConcurrencyConflict(id: String, expected: Int, actual: Int)
One mapped field in a changeset.
pub type Field {
Field(
name: String,
value: FieldValue,
rules: List(ValidationRule),
errors: List(String),
)
}
Constructors
-
Field( name: String, value: FieldValue, rules: List(ValidationRule), errors: List(String), )
Typed field value for changeset input mapping.
pub type FieldValue {
TextValue(String)
IntValue(Int)
BoolValue(Bool)
EmptyValue
}
Constructors
-
TextValue(String) -
IntValue(Int) -
BoolValue(Bool) -
EmptyValue
Query diagnostic event.
pub type QueryDiagnostic {
NPlusOneDetected(query: String, statement_count: Int)
SlowQueryDetected(query: String, latency_ms: Int)
TraceCorrelated(trace_id: String, query: String)
}
Constructors
-
NPlusOneDetected(query: String, statement_count: Int) -
SlowQueryDetected(query: String, latency_ms: Int) -
TraceCorrelated(trace_id: String, query: String)
Query shape used for diagnostics.
pub type QueryShape {
QueryShape(
name: String,
projected_rows: Int,
statement_count: Int,
estimated_latency_ms: Int,
trace_id: String,
)
}
Constructors
-
QueryShape( name: String, projected_rows: Int, statement_count: Int, estimated_latency_ms: Int, trace_id: String, )
One persisted row.
pub type Row {
Row(
id: String,
revision: Int,
resource: String,
attributes: List(#(String, String)),
)
}
Constructors
-
Row( id: String, revision: Int, resource: String, attributes: List(#(String, String)), )
Runtime
opaqueDeterministic runtime storage.
pub opaque type Runtime
Unit-of-work contract.
pub type UnitOfWork {
UnitOfWork(name: String, operations: List(UnitOperation))
}
Constructors
-
UnitOfWork(name: String, operations: List(UnitOperation))
Validation rule for one mapped field.
pub type ValidationRule {
Required
MinLength(Int)
MinInt(Int)
}
Constructors
-
Required -
MinLength(Int) -
MinInt(Int)
Values
pub fn bool_field(
name: String,
value: Bool,
rules: List(ValidationRule),
) -> Field
Build one bool field.
pub fn changeset(
resource: String,
fields: List(Field),
nested: List(Changeset),
) -> Changeset
Build one changeset.
pub fn changeset_error_signature(changeset: Changeset) -> String
Stable changeset error signature.
pub fn changeset_errors(changeset: Changeset) -> List(String)
All errors on one validated changeset.
pub fn changeset_valid(changeset: Changeset) -> Bool
True when a validated changeset has no errors.
pub fn create(
runtime: Runtime,
changeset: Changeset,
) -> Result(#(Runtime, Row), DataError)
Create one row from a changeset.
pub fn dashboard_signature(summary: DashboardSummary) -> String
Stable dashboard summary signature.
pub fn dashboard_summary(runtime: Runtime) -> DashboardSummary
Build dashboard summary for common CRUD status cards.
pub fn dashboard_with_diagnostics(
runtime: Runtime,
shape: QueryShape,
) -> #(DashboardSummary, List(QueryDiagnostic))
Dashboard summary with query diagnostics.
pub fn diagnose_query(shape: QueryShape) -> List(QueryDiagnostic)
Derive deterministic diagnostics for a query shape.
pub fn diagnostic_label(diagnostic: QueryDiagnostic) -> String
Stable query diagnostic label.
pub fn diagnostics_signature(
diagnostics: List(QueryDiagnostic),
) -> String
Stable query diagnostics signature.
pub fn empty_field(
name: String,
rules: List(ValidationRule),
) -> Field
Build one empty field for required validation paths.
pub fn int_field(
name: String,
value: Int,
rules: List(ValidationRule),
) -> Field
Build one int field.
pub fn query_shape(
name: String,
projected_rows: Int,
statement_count: Int,
estimated_latency_ms: Int,
trace_id: String,
) -> QueryShape
Build one query shape.
pub fn row(
id: String,
revision: Int,
resource: String,
attributes: List(#(String, String)),
) -> Row
Build one row record.
pub fn run_unit_of_work(
runtime: Runtime,
unit_of_work: UnitOfWork,
) -> Result(#(Runtime, List(String)), UnitOfWorkError)
Apply one unit-of-work with atomic semantics.
pub fn runtime_signature(runtime: Runtime) -> String
Stable runtime signature for fixtures.
pub fn text_field(
name: String,
value: String,
rules: List(ValidationRule),
) -> Field
Build one text field.
pub fn unit_of_work(
name: String,
operations: List(UnitOperation),
) -> UnitOfWork
Build one unit-of-work from typed operations.
pub fn unit_of_work_error_label(error: UnitOfWorkError) -> String
Stable unit-of-work error label.
pub fn update(
runtime: Runtime,
id: String,
expected_revision: Int,
changeset: Changeset,
) -> Result(#(Runtime, Row), DataError)
Update one row with optimistic-concurrency checks.