ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
//! The constructors every citizen's tests build values with, and the family-scale claims no single
//! citizen's module can make.
//!
//! `pub(super)` rather than private, so each household's own test module reaches these rather than
//! keeping a copy — the arrangement [`mediatime`](crate::primitives::mediatime)'s own fixtures take.

use super::{BoundingBox, NormCoord, Point2, Quad};

pub(super) fn coord(value: f32) -> NormCoord {
  NormCoord::new(value).expect("the fixture's coordinates are in range")
}

pub(super) fn point(x: f32, y: f32) -> Point2<NormCoord> {
  Point2::new(coord(x), coord(y))
}

pub(super) fn bbox(x: f32, y: f32, width: f32, height: f32) -> BoundingBox<NormCoord> {
  BoundingBox::try_unit(x, y, width, height).expect("the fixture's rectangles are inside the frame")
}

/// The four corners DISTINGUISHABLE from one another, so a transposition anywhere in the family
/// changes a value rather than merely rearranging equal ones.
pub(super) fn quad() -> Quad<NormCoord> {
  Quad::new(
    point(0.10, 0.11),
    point(0.90, 0.12),
    point(0.91, 0.88),
    point(0.13, 0.89),
  )
}

/// **THE WIDTHS, pinned** — what a declaration of each holder costs in columns.
///
/// The numbers are the whole reason the leaf guard exists. A component that came to span two columns
/// would double every one of them silently at the `SEGMENTS` const and leave the
/// [`StoredAs`](crate::StoredAs) rows — which are FIXED-length arrays — describing a row that is no
/// longer the row being written. Pinning the counts is what makes such a drift a red test rather
/// than a rendered `CREATE TABLE` nobody read.
#[test]
fn each_holder_states_how_many_columns_it_spans() {
  const fn spans<T: crate::ColumnKind>() -> usize {
    crate::width(T::SEGMENTS)
  }

  assert!(
    <NormCoord as crate::ColumnKind>::SEGMENTS.is_empty(),
    "a SCALAR joins by stating nothing, so its column comes from the field that names it"
  );
  assert_eq!(spans::<Point2<NormCoord>>(), 2, "x, y");
  assert_eq!(
    spans::<BoundingBox<NormCoord>>(),
    5,
    "x, y, width, height — and the DERIVED area beside them"
  );
  assert_eq!(spans::<Quad<NormCoord>>(), 8, "four corners of two each");
}

/// **The width is the COMPONENT-INDEPENDENT half of the promise**, and this is where that is
/// checked: every leaf component gives the same arity, because the arity is the holder's shape and
/// not the component's.
#[test]
fn a_holders_width_does_not_move_with_its_component() {
  const fn spans<T: crate::ColumnKind>() -> usize {
    crate::width(T::SEGMENTS)
  }

  assert_eq!(spans::<BoundingBox<f32>>(), 5);
  assert_eq!(spans::<BoundingBox<f64>>(), 5);
  assert_eq!(spans::<BoundingBox<u32>>(), 5);
  assert_eq!(spans::<BoundingBox<i64>>(), 5);
  assert_eq!(spans::<Quad<u32>>(), 8);
}

/// **THE ADMISSION, and the width an edge table writes for one element of each.**
///
/// The admission is a bound rather than a value, so what a test can reach is its supertrait's
/// answer. A `Vec` of any of these is what a detection pass produces, so the row that admits one is
/// load-bearing rather than decorative.
#[test]
fn each_admitted_element_states_the_columns_one_row_of_it_holds() {
  const fn admitted<E: crate::CollectionElement>() -> usize {
    crate::width(E::SEGMENTS)
  }

  // The coordinate is admitted too, and its width is the SCALAR answer — no segments, the one
  // column coming from the field an edge table names rather than from the type.
  assert_eq!(admitted::<NormCoord>(), 0);
  assert_eq!(admitted::<Point2<NormCoord>>(), 2);
  assert_eq!(admitted::<BoundingBox<NormCoord>>(), 5);
  assert_eq!(admitted::<Quad<NormCoord>>(), 8);
}

/// **The `Vec` reading is the QUANTIFIED one for all three holders, and it carries the holder's OWN
/// filter whole** — the half a marker row can get wrong in silence, a quantified marker resolving
/// its inner filter through the element's `DefaultMarker`.
#[test]
fn a_collection_of_any_holder_is_asked_through_its_own_filter() {
  fn quantified_over<T>() -> &'static str
  where
    T: crate::DefaultVecMarker,
    T::Marker: crate::ToGraphqlFilter,
  {
    core::any::type_name::<<T::Marker as crate::ToGraphqlFilter>::Filter>()
  }

  assert!(quantified_over::<BoundingBox<NormCoord>>().contains("BoundingBoxFilter"));
  assert!(quantified_over::<Point2<NormCoord>>().contains("Point2Filter"));
  assert!(quantified_over::<Quad<NormCoord>>().contains("QuadFilter"));

  assert!(quantified_over::<BoundingBox<NormCoord>>().contains("QuantifiedFilter"));
  assert!(quantified_over::<Point2<NormCoord>>().contains("QuantifiedFilter"));
  assert!(quantified_over::<Quad<NormCoord>>().contains("QuantifiedFilter"));
}

/// **A SCALAR component is read as a scalar and a HOLDER as a composite**, which is the split every
/// face below depends on: a composite reading is what puts a value's columns under its own frame,
/// and a scalar one is what makes a coordinate a column rather than a table.
#[test]
fn the_coordinate_is_read_as_a_scalar_and_the_holders_as_composites() {
  fn marker<T: crate::DefaultMarker>() -> &'static str {
    core::any::type_name::<T::Marker>()
  }

  assert!(marker::<NormCoord>().contains("ScalarMarker"));
  assert!(marker::<Point2<NormCoord>>().contains("CompositeMarker"));
  assert!(marker::<BoundingBox<NormCoord>>().contains("CompositeMarker"));
  assert!(marker::<Quad<NormCoord>>().contains("CompositeMarker"));
}

/// **EXACTLY ONE CITIZEN HERE DECLARES A DERIVED LEAF, and this is the family's ledger of which.**
///
/// *A derived leaf serves the semantic order only; every structural judgment walks value leaves
/// only* — ruled 2026-08-29, written out at [`ColumnShape`](crate::ColumnShape). What that law costs
/// a family is a SECOND numbering of its columns, and this house now pays it at ONE type: a
/// rectangle is FIVE columns and FOUR of them are the value, the fifth being the `area` an
/// area filter is answered on.
///
/// The position and the quadrilateral are untouched and are asserted so. That is not decoration:
/// a quad holds four positions and nothing else, so a derived leaf appearing one level down would
/// silently widen it, and a position is the component's own two columns with no reduction of any
/// kind. The two widths coinciding is the claim, and it is the claim that would go silently false.
#[test]
fn only_the_rectangle_carries_an_index_leaf() {
  const fn value_columns<T: crate::ColumnKind>() -> usize {
    crate::value_width(T::SEGMENTS)
  }
  const fn columns<T: crate::ColumnKind>() -> usize {
    crate::width(T::SEGMENTS)
  }

  assert_eq!(columns::<Point2<NormCoord>>(), 2);
  assert_eq!(columns::<BoundingBox<NormCoord>>(), 5);
  assert_eq!(columns::<Quad<NormCoord>>(), 8);

  assert_eq!(
    value_columns::<Point2<NormCoord>>(),
    columns::<Point2<NormCoord>>(),
    "every column of a position holds part of the position"
  );
  assert_eq!(
    value_columns::<BoundingBox<NormCoord>>(),
    4,
    "a rectangle is four numbers, however many columns it is written into"
  );
  assert_eq!(
    value_columns::<Quad<NormCoord>>(),
    columns::<Quad<NormCoord>>(),
    "and a quadrilateral is its four positions, whose parts carry no reduction either"
  );

  // The COMPONENT too, at the width the family is generic over: a holder inherits its component's
  // leaves, so an index leaf one level down would reach all three of the rows above.
  assert!(<NormCoord as crate::ColumnKind>::SEGMENTS.is_empty());
  assert!(<f32 as crate::ColumnKind>::SEGMENTS.is_empty());
}

/// **THE DISCIPLINE INTERLOCK, at the seam the 2026-08-30 双收 ruling put it on.**
///
/// A structural judgment names [`value_width`](crate::value_width) columns on its left-hand side and
/// binds [`Carrier::push_value_bind`](crate::Carrier::push_value_bind) on its right, and the two
/// have to be the same number or the statement does not parse. This is that pairing measured for the
/// one citizen here that has an index leaf to leave out.
///
/// The whole-width bind is asserted beside it, because a `push_value_bind` that simply forgot to
/// override would pass a test that only counted one of them.
///
/// The dialect is PostgreSQL because its placeholders are countable — `$1`, `$2` — where SQLite's
/// are all one character and MySQL's all another. Nothing about the widths is the dialect's, which
/// `geometry_columns.rs` is the second reading of: the same pairing through SQLite, as a statement
/// the engine parses and a row it finds.
#[cfg(all(feature = "sqlx", feature = "postgres"))]
#[test]
fn the_value_bind_is_as_wide_as_the_value_columns_and_the_whole_bind_is_wider() {
  fn placeholders(render: impl FnOnce(&mut sqlx::QueryBuilder<sqlx::Postgres>)) -> usize {
    let mut qb = sqlx::QueryBuilder::<sqlx::Postgres>::default();
    render(&mut qb);
    qb.sql().as_ref().matches('$').count()
  }

  let region = bbox(0.10, 0.20, 0.50, 0.40);

  assert_eq!(
    placeholders(|qb| crate::Carrier::push_value_bind(&region, qb)),
    crate::value_width(<BoundingBox<NormCoord> as crate::ColumnKind>::SEGMENTS),
    "the STRUCTURAL bind is the four value columns"
  );
  assert_eq!(
    placeholders(|qb| crate::Carrier::push_bind(&region, qb)),
    crate::width(<BoundingBox<NormCoord> as crate::ColumnKind>::SEGMENTS),
    "…and the WRITE bind is all five, the derived one included"
  );
}

/// **THE COMPOSED WIRE NAMES, and the Pascal tail the 2026-08-29 ruling put on them.**
///
/// The house had no assertion over these at all, which is how `BoundingBoxf32` outlived a module
/// note and an SDL sketch that both said `BoundingBoxF32`. A name is what a client writes into a
/// query, so it is pinned here rather than described.
///
/// The FILTER names are pinned beside them because the two halves compose from different sources —
/// a component's published scalar and a component filter's own name — and the property that matters
/// is that they now agree: strip a filter's suffix and the object's name is what remains.
#[cfg(feature = "async-graphql")]
#[test]
fn the_composed_names_take_a_pascal_tail() {
  use async_graphql::{InputType, OutputType};

  type F32Filter = crate::ScalarFilter<f32>;

  assert_eq!(
    <Point2<NormCoord> as OutputType>::type_name(),
    "Point2F32",
    "a coordinate crosses as `f32`'s roster carrier, and a composed tail is RAISED"
  );
  assert_eq!(
    <BoundingBox<NormCoord> as OutputType>::type_name(),
    "BoundingBoxF32"
  );
  assert_eq!(<Quad<NormCoord> as OutputType>::type_name(), "QuadF32");

  // The width the family is generic over, asked directly: the raise is the component's published
  // name's and not the coordinate newtype's.
  assert_eq!(
    <BoundingBox<f64> as OutputType>::type_name(),
    "BoundingBoxF64"
  );

  for (object, filter) in [
    (
      <Point2<NormCoord> as OutputType>::type_name(),
      <super::Point2Filter<F32Filter> as InputType>::type_name(),
    ),
    (
      <BoundingBox<NormCoord> as OutputType>::type_name(),
      <super::BoundingBoxFilter<F32Filter> as InputType>::type_name(),
    ),
    (
      <Quad<NormCoord> as OutputType>::type_name(),
      <super::QuadFilter<F32Filter> as InputType>::type_name(),
    ),
  ] {
    assert_eq!(
      filter.strip_suffix("Filter"),
      Some(object.as_ref()),
      "the two composed names differ only by the suffix a filter wears"
    );
  }
}

/// **THE `area` FACET ON THE WIRE — parsed, held and rendered back, under the component's own input
/// object.**
///
/// The 2026-08-29 ruling's wire half: the filter face grows `area` WIDE, which means it takes the
/// SAME input object the four stored facets take rather than a narrowed kind of its own. So the
/// assertion is written at the two doors a client meets — a longhand object carrying `area` parses
/// into the facet, and the value renders back under the same name — and it is written with `eq`,
/// which is one of the two slots the ancestor's four-slot `AreaFilter` did not have.
#[cfg(feature = "async-graphql")]
#[test]
fn the_area_facet_parses_and_renders_under_the_components_own_filter() {
  use async_graphql::{InputType, Value, value};

  type Face = super::BoundingBoxFilter<crate::ScalarFilter<f32>>;

  let sent = value!({ "width": { "gte": 0.5 }, "area": { "eq": 0.25 } });
  let parsed = <Face as InputType>::parse(Some(sent)).expect("both facets are the face's own");

  assert_eq!(
    parsed.area().and_then(crate::ScalarFilter::eq),
    Some(&0.25),
    "an `eq` over an area is a question, and the wide kind is what carries it"
  );
  assert_eq!(
    parsed.width().and_then(crate::ScalarFilter::gte),
    Some(&0.5),
    "…beside a stored facet, which is untouched by the derived one"
  );

  let Value::Object(rendered) = InputType::to_value(&parsed) else {
    panic!("a filter renders as an object");
  };
  assert!(
    rendered.contains_key("area"),
    "the facet renders back under the name it was sent as: {rendered:?}"
  );

  // The empty filter is still empty with the fifth facet present, which is what a caller asks before
  // deciding whether a predicate is worth rendering at all.
  assert!(crate::GraphqlFilter::is_empty(&Face::new()));
  assert!(!crate::GraphqlFilter::is_empty(
    &Face::new().with_area(crate::ScalarFilter::new().with_gt(0.1))
  ));
}