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 OPERAND BUILDER** — [`EqualsFilter`], measured as the thing an emitter can actually reach.
//!
//! Every assertion here is about the ONE property the trait exists for: that the equality operand is
//! spellable at a site holding a filter as a TYPE PARAMETER, where no inherent method resolves. So
//! nothing below names a kind at the call it measures — [`equated`] is generic, and what it is
//! handed is what an emitter's projection would hand it.

use super::*;

/// The emitter's own position, in a function: a filter known only as a parameter, with a value to
/// equate.
///
/// This signature IS the measurement. An inherent `new().with_eq(v)` cannot be written inside it —
/// `F` has no methods — so a body that compiles is the proof that the trait carries the act across
/// the boundary an expansion sits on.
fn equated<F: EqualsFilter<T>, T>(value: T) -> F {
  F::equals(value)
}

/// **THE TRAIT IS THE INHERENT CHAIN**, not a second construction face — so the two roads answer
/// with the same value for every kind that has a row.
///
/// Asserted per kind rather than argued once, because each row is written out and a row that reached
/// for the wrong slot would be invisible to a rule about all of them.
#[test]
fn every_row_is_its_kind_s_own_new_and_with_eq() {
  assert_eq!(
    equated::<ScalarFilter<i64>, _>(7),
    ScalarFilter::new().with_eq(7)
  );
  assert_eq!(
    equated::<TextFilter<String>, _>("clapper".to_owned()),
    TextFilter::new().with_eq("clapper".to_owned())
  );
  assert_eq!(
    equated::<BooleanFilter, _>(true),
    BooleanFilter::new().with_eq(true)
  );
  assert_eq!(
    equated::<BytesFilter<Vec<u8>>, _>(vec![0x89]),
    BytesFilter::new().with_eq(vec![0x89])
  );
  assert_eq!(
    equated::<EnumFilter<u8>, _>(3),
    EnumFilter::new().with_eq(3)
  );
}

/// **ONE OPERATOR AND NO OTHER** — the operand lands in `eq` and every sibling slot stays absent.
///
/// The property a lineage predicate rests on: an emitter asking for one ancestry must not also
/// narrow by a bound nobody wrote. [`ScalarFilter::is_referential`] is the framework's own name for
/// exactly this shape, so it is what the claim is read back through rather than eight `is_none`s.
#[test]
fn the_operand_lands_in_eq_alone() {
  let scoped: ScalarFilter<i64> = equated(1);

  assert_eq!(scoped.eq(), Some(&1));
  assert!(!scoped.is_empty(), "an equated filter narrows something");
  assert!(
    scoped.is_referential(),
    "eq alone is the shape a foreign key collapses on: {scoped:?}"
  );
}

/// **THE WRAPPER TAKES THE OPERAND TO ITS INNER KIND AND LEAVES THE NULL TEST UNSET** — the row the
/// whole trait exists for.
///
/// A nullable column is where the two spellings diverge: `Nullable<F>` has no `with_eq`, so this is
/// the case an emitter could not have written by hand without detecting nullability — which the
/// projection layer forbids. The null test staying `None` is the other half: *is this column null*
/// is a question about the COLUMN, and answering it from an operand nobody wrote would drop rows a
/// caller asked for.
#[test]
fn a_nullable_column_equates_through_its_inner_kind() {
  let scoped: Nullable<ScalarFilter<i64>> = equated(Some(1));

  assert_eq!(scoped.inner().eq(), Some(&1));
  assert_eq!(scoped.null(), None, "the null test is not an operand");
  assert_eq!(scoped, Nullable::new(ScalarFilter::new().with_eq(1)));
}

/// **AN ABSENT OPERAND ON A NULLABLE COLUMN IS THE NULL TEST** — the wrapper's other arm, and the
/// only reading `None` has where the column can hold one.
///
/// It reaches no operator of the inner kind, which is what makes it *this column IS null* rather
/// than *this column equals nothing* — the second being a predicate that matches no rows at all.
#[test]
fn an_absent_operand_on_a_nullable_column_asks_for_null() {
  let scoped: Nullable<ScalarFilter<i64>> = equated(None);

  assert_eq!(scoped.null(), Some(&true));
  assert!(
    scoped.inner().is_empty(),
    "the inner kind is untouched: {scoped:?}"
  );
}

/// **THE PROJECTION IS THE POSITION AN EMITTER WRITES**, and it resolves to both spellings.
///
/// `Column<T>` is `emit::filter_of`'s tokens as a type alias — the exact form a record's expansion
/// puts a lineage column's filter at, and `EqualsFilter<T>` is spelled at the SAME `T`. A bare `i64`
/// resolves to the kind and an `Option<i64>` to the wrapper, one line serves both, and neither
/// spelling appears at the call: that is the whole of what the leg needs and the whole of what a
/// type-blind emitter can promise.
#[test]
fn one_call_serves_a_column_and_its_nullable_twin() {
  type Column<T> = <<T as DefaultMarker>::Marker as crate::ToGraphqlFilter>::Filter;

  fn scoped<T>(value: T) -> Column<T>
  where
    T: DefaultMarker,
    Column<T>: EqualsFilter<T>,
  {
    EqualsFilter::equals(value)
  }

  assert_eq!(scoped(1_i64), ScalarFilter::new().with_eq(1));
  assert_eq!(
    scoped(Some(1_i64)),
    Nullable::new(ScalarFilter::new().with_eq(1))
  );
}

/// **`equals` DOES NOT SHADOW AND IS NOT SHADOWED** — the getters keep their bare names.
///
/// The naming letter, held as a fact: `eq` is the getter, an inherent method wins method resolution,
/// and the trait's own act is reachable by a name of its own with no turbofish. Pinned because the
/// claim is about NAME RESOLUTION rather than about either body, and would otherwise be an
/// assumption a later rename could quietly break.
#[test]
fn the_getter_and_the_builder_do_not_collide() {
  let scoped = <ScalarFilter<i64> as EqualsFilter<i64>>::equals(1);

  assert_eq!(scoped.eq(), Some(&1), "the bare name is still the getter");
  assert_eq!(ScalarFilter::<i32>::equals(2).eq(), Some(&2));
}