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 FAMILY-scale claims: the wiring every citizen here shares, and the refusals the module note
//! argues.
//!
//! What each citizen's grammar is belongs to its own file. What is here is the shape the house has
//! as a house — that a codec is ONE column read under the composite marker, that its filter is
//! named by its own wire type, and that the two refused faces are refused for all three.

use super::{
  AudioCodec, AudioCodecWire, SubtitleCodec, SubtitleCodecWire, VideoCodec, VideoCodecWire,
};

/// **EACH CITIZEN IS ONE COLUMN, READ UNDER THE COMPOSITE MARKER** — the reading a value occupying
/// a column of its own takes, and the one that makes `Option<VideoCodec>` a nullable column rather
/// than a collection.
#[test]
fn each_citizen_is_one_column_under_the_composite_reading() {
  const fn one_column<T: crate::ColumnKind>() {}
  const fn composite<T: crate::DefaultMarker<Marker = crate::CompositeMarker<T>>>() {}

  one_column::<VideoCodec>();
  one_column::<AudioCodec>();
  one_column::<SubtitleCodec>();

  composite::<VideoCodec>();
  composite::<AudioCodec>();
  composite::<SubtitleCodec>();
}

/// **THE FILTER IS NAMED BY THE WIRE TYPE**, and each of the three is named for itself.
///
/// The names are a SCHEMA COMMITMENT — an input object a client spells — so they are asserted here
/// rather than left to whatever the macro happened to be passed.
#[test]
fn the_filter_names_are_the_schema_commitment() {
  use crate::ScalarWire;

  assert_eq!(
    <VideoCodecWire as ScalarWire<VideoCodec>>::NAME,
    "VideoCodecFilter"
  );
  assert_eq!(
    <AudioCodecWire as ScalarWire<AudioCodec>>::NAME,
    "AudioCodecFilter"
  );
  assert_eq!(
    <SubtitleCodecWire as ScalarWire<SubtitleCodec>>::NAME,
    "SubtitleCodecFilter"
  );
}

/// **THE COLUMN WORD IS TEXT's**, delegated rather than named — a codec IS its canonical slug, so
/// the dialect's own word for a text column is the only answer, and the delegation carries the
/// admission with it.
#[cfg(all(feature = "sqlx", feature = "sqlite"))]
#[test]
fn the_column_word_is_the_dialects_own_word_for_text() {
  use crate::StoredAs;

  type Db = sqlx::Sqlite;

  assert_eq!(
    <VideoCodec as StoredAs<Db>>::WORDS,
    <String as StoredAs<Db>>::WORDS,
  );
  assert_eq!(
    <AudioCodec as StoredAs<Db>>::WORDS,
    <String as StoredAs<Db>>::WORDS,
  );
  assert_eq!(
    <SubtitleCodec as StoredAs<Db>>::WORDS,
    <String as StoredAs<Db>>::WORDS,
  );
}

/// **THE WIRE CROSSING IS THE IDENTITY, IN BOTH DIRECTIONS** — the type is its own scalar, so an
/// operand needs no second spelling and a returned value is a borrow of the one the row holds.
#[test]
fn the_wire_crossing_is_the_identity() {
  use crate::{ToGraphqlInput, ToGraphqlOutput};

  let codec = VideoCodec::new("H264");

  let carried = <VideoCodec as ToGraphqlInput>::carry(&codec);
  assert_eq!(
    <VideoCodec as ToGraphqlInput>::cross(carried),
    Ok(codec.clone()),
  );

  assert_eq!(
    <VideoCodec as ToGraphqlOutput>::to_graphql_output(&codec),
    &codec
  );
}