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
//! What a blueprint owes: it is an ITEM, it carries the name the target creates under, and one type
//! may be described in two targets whose blueprints share no member.

use super::{Habitat, Layout, SlotColumn, SlotSchema, SlotSpec};
use crate::{ColumnDoor, Describe, SlotName};

/// A full-text target and a vector one — two homes, two vocabularies.
struct Corpora;
struct Coordinates;

impl Habitat for Corpora {
  type Blueprint = &'static [SlotSchema];
}

impl Habitat for Coordinates {
  type Blueprint = &'static [SlotSpec];
}

/// ONE declaration, described in BOTH — which is the shape a mixed-mode node has, and the reason
/// the blueprint is the target's answer rather than one struct with four arms.
struct Media;

impl Describe<Corpora> for Media {
  const BLUEPRINT: &'static [SlotSchema] = &[
    SlotSchema::new(
      SlotName::new("media__title__lexical"),
      &[SlotColumn::text("title")],
    ),
    SlotSchema::new(
      SlotName::new("media__body__lexical"),
      &[SlotColumn::text("body")],
    )
    .keeping(),
  ];
}

impl Describe<Coordinates> for Media {
  const BLUEPRINT: &'static [SlotSpec] = &[SlotSpec::new(
    SlotName::new("media__clip__hnsw"),
    &[SlotColumn::new("clip", ColumnDoor::Bytes)],
    768,
  )];
}

/// A blueprint is a `const`, so a walk that reads one allocates nothing and two boots cannot see two
/// schemas — [`Table`](crate::Table)'s own property, restated for the engine kinds.
const _: () = {
  assert!(<Media as Describe<Corpora>>::BLUEPRINT.len() == 2);
  assert!(<Media as Describe<Coordinates>>::BLUEPRINT[0].width() == 768);
};

/// The blueprint carries the DURABLE NAME, which is what makes a slot maker able to create anything
/// at all: a corpus is created under a name, and the name is the declaration's.
#[test]
fn a_corpus_blueprint_names_the_corpus_it_describes() {
  let corpora = <Media as Describe<Corpora>>::BLUEPRINT;
  let names: Vec<&str> = corpora.iter().map(|slot| slot.slot().as_ref()).collect();
  assert_eq!(names, ["media__title__lexical", "media__body__lexical"]);
}

/// The `stored` word is the TEXT SEAT and it rides the blueprint — one corpus keeps what it indexed
/// and the other does not, which is a fact of the DECLARATION and not of a deployment.
#[test]
fn the_text_seat_is_per_corpus() {
  let corpora = <Media as Describe<Corpora>>::BLUEPRINT;
  assert!(!corpora[0].is_stored());
  assert!(corpora[1].is_stored());
  assert_eq!(
    SlotSchema::of(SlotName::new("kept"), &[], true).is_stored(),
    SlotSchema::new(SlotName::new("kept"), &[])
      .keeping()
      .is_stored(),
    "`of` reads the declaration's word and `keeping` states it — the same posture either way",
  );
}

/// A column names itself and the DOOR its values cross by, which is the engine families' own
/// vocabulary rather than a SQL dialect's storage word.
#[test]
fn a_slot_column_carries_the_door_its_values_cross_by() {
  let corpora = <Media as Describe<Corpora>>::BLUEPRINT;
  let title = corpora[0].columns()[0];
  assert_eq!(title.name(), "title");
  assert_eq!(title.door(), ColumnDoor::Text);

  let clip = <Media as Describe<Coordinates>>::BLUEPRINT[0].columns()[0];
  assert_eq!(clip.door(), ColumnDoor::Bytes);
}

/// A blob family's home is its name, and the type says so rather than carrying members nothing
/// reads.
#[test]
fn a_blob_layout_is_its_name() {
  const THUMBNAILS: Layout = Layout::new(SlotName::new("thumbnails"));
  assert_eq!(THUMBNAILS.slot().as_ref(), "thumbnails");
}