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
use super::{Row, roster};

/// EVERY ROW, against what the binding actually publishes for it — the table read back out of the
/// schema rather than out of a second list.
///
/// This is the assertion the roster exists to make possible. Before it, a scalar's name and its
/// filter's name were two literals in two files, and the only thing holding them together was a
/// census listing every input object by hand: a renamed scalar with an unrenamed filter passed the
/// census (it lists names, not relationships) and reached a schema as a mismatched pair.
#[test]
fn every_row_is_the_name_the_binding_emits() {
  for row in roster() {
    assert_eq!(
      (row.scalar_face)(),
      row.scalar,
      "the `{}` row's SCALAR name",
      row.rust
    );

    match (row.filter, row.filter_face) {
      (Some(name), Some(face)) => assert_eq!(face(), name, "the `{}` row's FILTER name", row.rust),
      (None, None) => {}
      _ => panic!(
        "the `{}` row states a filter in one column and not the other",
        row.rust
      ),
    }
  }
}

/// **THE DERIVATION LAW** — a filter's name is `UpperCamel(scalar)` and the word `Filter`.
///
/// Written as an assertion rather than trusted to the derivation that produces it, because the
/// derivation is what this pins: a row that grew a hand-spelled filter name — which is how the table
/// looked before the constitution — fails here whatever it spells.
#[test]
fn a_filter_name_is_derived_from_its_scalar() {
  for row in roster() {
    let Some(filter) = row.filter else {
      continue;
    };
    let mut raised = row.scalar.to_owned();
    raised[..1].make_ascii_uppercase();
    assert_eq!(filter, format!("{raised}Filter"), "the `{}` row", row.rust);
  }
}

/// **THE HOUSEHOLD REGISTER**, asserted over the framework's OWN rows and nowhere else.
///
/// Every roster SCALAR is a framework default, and law three spells those lowercase; the FILTERS
/// beside them are input objects and take Pascal like every other type name a schema holds, which is
/// what the test above reads. It is a convention rather than a guard — a declaring crate may mint
/// whatever case it likes, and the constitution says so explicitly — so what this test can honestly
/// hold to the register is this crate's own table, which is exactly what it does.
#[test]
fn the_roster_is_lowercase() {
  for row in roster() {
    assert_eq!(
      row.scalar,
      row.scalar.to_lowercase(),
      "the `{}` row's scalar name is a framework default and takes lowercase",
      row.rust
    );
  }
}

/// The roster's own INVENTORY, so that a row arriving or leaving is a visible line of this file.
///
/// The census in `graphql::tests::wire` lists every input object a schema reaches; this lists the
/// SCALARS the framework mints, which is a shorter and more stable list — a wrapping axis adds
/// input objects and adds no scalar.
///
/// Every row of the table is here, the 2026-08-18 amendment having retired the two that were not:
/// `string` and `bool` left the roster, so their filters are the canonical `StringFilter` and
/// `BooleanFilter` and there is no scalar to list for either. `ingraph/tests/half_roster.rs` is
/// where that merge is pinned against a built schema.
///
/// The optional widths are the two lines with a gate on them, and they are gated for the reason
/// `half`'s manifest row states: a width whose operand is somebody else's type enters when a
/// declaration asks for it.
#[test]
fn the_roster_holds_exactly_these_rows() {
  let mut names: Vec<&str> = roster().iter().map(|row| row.scalar).collect();
  names.sort_unstable();

  let mut expected = vec![
    "bytes", "f32", "f64", "i128", "i16", "i32", "i64", "i8", "u128", "u16", "u32", "u64", "u8",
  ];
  #[cfg(feature = "half")]
  expected.push("f16");
  #[cfg(feature = "rust_decimal")]
  expected.push("f128");
  expected.sort_unstable();

  assert_eq!(names, expected);
}

/// The PASCAL half's whole roster: the six addresses, the uuid and the pattern, in one iterator.
///
/// Two tables rather than one, because each is minted by its own `parsed_text_scalar!` invocation
/// and a `const` cannot be extended from a second place. Joined here so that the two assertions
/// below are written once each and a THIRD table joins by being chained rather than by being copied
/// into two loop headers.
fn named_text_rows() -> impl Iterator<Item = &'static Row> {
  // The pattern's table rides its own word, so it is bound to an empty slice where the word is off
  // rather than gating the chain: a `const` behind a feature cannot be an ELEMENT of the expression,
  // which is `roster()`'s own reason for spending its gates on statements.
  #[cfg(feature = "regex")]
  let patterns: &'static [Row] = super::super::scalar::REGEX_ROWS;
  #[cfg(not(feature = "regex"))]
  let patterns: &'static [Row] = &[];

  super::super::scalar::NET_ROWS
    .iter()
    .chain(super::super::scalar::UUID_ROWS)
    .chain(patterns)
}

/// Every NAMED-TEXT vocabulary — the six addresses, the uuid and the pattern — read the way the
/// roster's own rows are read: the emitted scalar name against the literal its row was handed, and the emitted
/// filter name against the derivation.
///
/// A separate table because these rows are the register's PASCAL half: they are NAMED types rather
/// than widths, so `the_roster_is_lowercase` must not see them and `roster()` must not hold them.
/// What they share with the lowercase rows is the mechanism — one literal per row, the filter name
/// derived from it — and this is where that is asserted.
///
/// It read `NET_ROWS` alone while the addresses were the arm's only users. The uuid row joined them
/// on 2026-08-29 and the pattern's on 2026-08-31 — the third from a HAND-WRITTEN citizenship rather
/// than from `parsed_text_scalar!` at all — and the loop takes all three tables rather than gaining
/// a copy of itself: what is asserted is a property of the MECHANISM, and the mechanism does not
/// know which table a row is in, nor which macro minted it.
#[test]
fn every_parsed_text_row_derives_its_filter_name() {
  for row in named_text_rows() {
    let Row {
      rust,
      scalar,
      filter,
      scalar_face,
      filter_face,
    } = row;
    assert_eq!(scalar_face(), *scalar, "the `{rust}` row's SCALAR name");
    let (Some(name), Some(face)) = (filter, filter_face) else {
      panic!("the `{rust}` row is a declarable column type and states a filter in both columns");
    };
    assert_eq!(face(), *name, "the `{rust}` row's FILTER name");
    assert_eq!(
      *name,
      format!("{scalar}Filter"),
      "the `{rust}` row derives its filter from its scalar, with no case to raise"
    );
  }
}

/// **THE REGISTER'S OTHER HALF** — a named-vocabulary scalar is PASCAL, where every roster row is
/// lowercase.
///
/// The twin of `the_roster_is_lowercase`, and written for the reason that one is: law three is a
/// convention this crate holds its OWN rows to, and a row that changed case would otherwise change
/// nothing that fails. `Uuid` is the row that makes it worth keeping — `UUID` is the spelling a
/// reader expects and the register does not take, so the assertion is what holds the two apart.
#[test]
fn every_parsed_text_row_is_pascal() {
  for row in named_text_rows() {
    let first = row
      .scalar
      .chars()
      .next()
      .expect("a scalar name is not empty");
    assert!(
      first.is_ascii_uppercase(),
      "`{}` is a NAMED type and takes Pascal, not the roster's lowercase",
      row.scalar
    );
  }
}