ingraph-derive 0.1.0

The attribute and derive macros for ingraph: the words a record, node, key, filter and vocabulary declaration is written in.
Documentation
//! **THE ABSENCE ROAD, THROUGH THE EMISSION** — what a widened `locate` makes the two expansions
//! write, at both ends of one seam.
//!
//! [`crate::locate_required_tests`] holds the GRAMMAR of the signature and says in its own note that
//! what the word does to a schema is measured elsewhere. This is the half between the two: the
//! TOKENS. A model carrying `required: true` and an emitted field that spends the signed walk are
//! two different claims, and only the second is what a deployment runs.
//!
//! # Why both ends are in one file
//!
//! The value crosses a seam whose halves are written by two macros that never see each other. A
//! blob's expansion writes the `ArtifactStore` impl that MINTS the `Option`, and a record's writes
//! the field that SPENDS it — so a build where one half moved and the other did not is exactly the
//! failure a per-macro suite cannot see. Reading the mint and the spend beside each other is the
//! whole point of the file.
//!
//! # What is NOT here
//!
//! What a client sees. `ingraph/tests/artifact_absence.rs` runs the schema against a store that can
//! answer presence and reads the answers; a token spelling `Option::None` is not a `null` on the
//! wire, and only one of those is what somebody asked for.

use ingraph_codegen::{index::IndexModel, prelude::*};

use crate::host;

/// The BLOB half's model — a family on the shipped store, whose expansion carries the bridge.
fn blob() -> IndexModel {
  let (host, arguments) = host::split(&syn::parse_quote! {
    #[ingraph(upstream(node = "app::Frame", payload = "pixels"), fs, extension = "png")]
    struct Poster { #[ingraph(repeated)] payload: Vec<u8> }
  });
  crate::index::parse(&host, &arguments, NodeKind::Blob).expect("a family on the shipped store")
}

/// The RECORD half's model — one entity, two positions, differing in the word alone.
fn record() -> RecordModel {
  let (host, options) = host::split(&syn::parse_quote! {
    #[ingraph(sqlite,
      lineage(fields(media)),
      graphql(async_graphql),
      locate(bare = "app::Bare", signed(family = "app::Signed", required)),
    )]
    struct Frame { #[ingraph(id)] at: i64, media: String }
  });
  crate::parse::parse(&host, &options, NodeKind::Record).expect("two positions, one word apart")
}

/// An expansion as one string — what a token claim reads.
fn emitted(tokens: proc_macro2::TokenStream) -> String {
  tokens.to_string()
}

/// **THE MINT: the shipped family's `locate` ANSWERS AN OPTION, and it renders WITHOUT LOOKING.**
///
/// RESPELLED, not retired: it read *…and it looks before it says so* while the emission spent a
/// `try_exists`, and both halves of that claim were true then. The stat has retired — a presence
/// answer expires as it is produced, so fs renders and absence is found at USE — and what the
/// TOKENS must now say is the other side of the same seam.
///
/// The RETURN TYPE survives unchanged and is the load-bearing half: absence stays expressible at
/// this seam, because the seam is every store's and a store that knows presence for free answers
/// `None` through it. What this family answers is `Some`, always, and the absence of `try_exists` is
/// what says the render is pure.
#[test]
fn the_shipped_family_answers_an_option_and_renders_without_looking() {
  let emission = emitted(blob().emit());

  assert!(
    emission
      .contains("core :: result :: Result < :: core :: option :: Option < Self :: Location >"),
    "{emission}"
  );
  assert!(
    !emission.contains("try_exists"),
    "the family stats on a caller's behalf: {emission}"
  );
  assert!(
    emission.contains(":: core :: option :: Option :: Some (:: ingraph"),
    "{emission}"
  );
}

/// **THE RENDER IS THE WHOLE BODY**, which is what the ordering claim became when one of its two
/// acts retired.
///
/// RESPELLED from `the_address_renders_before_the_family_looks`. That pin held an ORDER — render,
/// then look — and its reason was that a root rendering no address must refuse for a missing object
/// exactly as it refuses for a present one, rather than hiding the fault until the day the pipeline
/// succeeds. With the look gone, the same reason is carried by an unconditional refusal: the render
/// is reached on every call, so a store that cannot address refuses on every call.
#[test]
fn the_address_render_is_the_whole_body() {
  let emission = emitted(blob().emit());

  let render = emission
    .find("blob_address")
    .expect("the address is rendered");
  let answer = emission[render..]
    .find(":: core :: option :: Option :: Some")
    .expect("and handed back");

  // NOTHING BETWEEN THEM but the location's own construction: no branch, and no second act that a
  // present object and an absent one could take differently.
  let between = &emission[render..render + answer];
  assert!(!between.contains("if "), "{emission}");
  assert!(!between.contains("try_exists"), "{emission}");
}

/// **THE SPEND: a bare position hands the store's own answer to a client.**
///
/// The EXCLUSION is the load-bearing half. The emission used to MINT the `Option` — a `Result::map`
/// into `Option::Some` around a call that could never be absent — so a field that still wrapped
/// would publish `null` never, whatever the store answered. What is asserted is that no such wrap
/// remains beside this call.
#[test]
fn a_bare_position_publishes_what_the_family_answered() {
  let emission = emitted(record().emit());

  assert!(emission.contains("locate_artifact"), "{emission}");
  assert!(
    emission.contains("Result < :: core :: option :: Option << app :: Bare as"),
    "{emission}"
  );
  assert!(
    !emission.contains(":: core :: option :: Option :: Some ,"),
    "the emission mints no `Option` of its own any more: {emission}"
  );
}

/// **THE SPEND, SIGNED: the promoted position takes the OTHER walk.**
///
/// One word apart from the field above, and the difference is a whole function rather than a branch:
/// the signed field publishes a non-null type, so the absence the bare field returns has nowhere to
/// go, and `locate_signed_artifact` is where it becomes the named refusal instead.
#[test]
fn a_signed_position_takes_the_signed_walk() {
  let emission = emitted(record().emit());

  assert!(emission.contains("locate_signed_artifact"), "{emission}");
  assert!(
    emission.contains("Result << app :: Signed as"),
    "{emission}"
  );
}