bookclerk_resolve

Development These docs follow the development version and change with every merge.

Last updated View as Markdown

Sans-IO resolver for the library data model.

Storefronts describe what they sell; the host decides identity. This crate maps one store listing to an FRBR edition, expression and work (library data model ADR):

  1. Listing::from_draft validates and normalises what a plugin reported. It is the untrusted-input boundary.
  2. The caller reads a Snapshot of the stored rows that bear on the listing (the store from SQL, memory::MemoryCatalog from memory).
  3. resolve returns a [Plan]: the rows to insert, the identifiers to attach, the conflicts to record for an Administrator and the events to publish. The caller applies it as one atomic batch.

Nothing here performs I/O, so the fuzz target (library_resolve), the replay test and the store all drive the same code.

Item Kind Summary
IdSource trait Mints ids for new rows; the store uses UUIDs, tests use counters.
EntityKind enum The kind of row a new id is minted for.
resolve function Resolves one listing against a snapshot of the stored rows.
resolve_catalog function Resolves a catalog listing (a title a store sells that nobody in the library holds) against a snapshot of the stored rows.

Re-exports

Modules

  • fuzzing: Fuzz input decoding and the oracle the library_resolve target checks.
  • identifiers: External identifiers: normalisation and the key they are stored under.
  • kinds: Closed vocabularies of the library data model.
  • labels: Store labels that name the same thing in different spellings.
  • language: Language codes: one spelling for the many ways stores write a language.
  • listing: The validated listing a storefront reports, and who holds it.
  • memory: An in-memory library that reads snapshots and applies plans.
  • model: Stored rows the resolver reads, the snapshot of them it is given, and the plan of writes it returns.
  • names: Splitting a store's display string of contributor names.
  • normalize: Title and author cleaning for compares.

Traits

IdSource

pub trait IdSource {
    fn next_id(&mut self, kind: EntityKind) -> String;
    fn edition_id(&mut self, key: &ListingKey) -> String;
}

Mints ids for new rows; the store uses UUIDs, tests use counters.

IdSource::next_id

fn next_id(&mut self, kind: EntityKind) -> String

A fresh id, never returned before, for a new row of kind.

IdSource::edition_id

fn edition_id(&mut self, key: &ListingKey) -> String

The id for a new edition first seen through the listing key.

The store derives it from key, so every node that resolves the same listing first mints the same edition id. The resolver mints an edition only for a listing with no stored edition, but that listing's first edition can outlive it (holding other listings), so a caller deriving ids must check the id is free; the store mints a random one when it is not. The default is IdSource::next_id.

Implemented by: CounterIds

Enums

EntityKind

pub enum EntityKind {
    Work,
    Expression,
    Edition,
    Listing,
}

The kind of row a new id is minted for.

Variants

  • Work: A work.
  • Expression: An expression.
  • Edition: An edition.
  • Listing: A store listing.

Implements: Clone, Copy, Debug, Eq, PartialEq

Functions

resolve

pub fn resolve(
    listing: &Listing,
    holding: &HoldingDraft,
    snapshot: &Snapshot,
    ids: &mut dyn IdSource,
) -> Plan

Resolves one listing against a snapshot of the stored rows.

Arguments

  • listing - The validated listing.
  • holding - Who holds it and how.
  • snapshot - The stored rows that bear on it (Snapshot states what the caller must include).
  • ids - Mints ids for the rows the plan creates.

Returns

The plan of writes. Resolving the same listing again after applying the plan returns a plan for which Plan::is_noop holds.

resolve_catalog

pub fn resolve_catalog(
    listing: &Listing,
    snapshot: &Snapshot,
    ids: &mut dyn IdSource,
) -> Plan

Resolves a catalog listing (a title a store sells that nobody in the library holds) against a snapshot of the stored rows.

The listing reaches a work, an expression and an edition exactly as resolve would place it, so a later scan of the same product finds the same rows; the plan carries no holding, so the library does not hold the edition.

Arguments

  • listing - The validated listing.
  • snapshot - The stored rows that bear on it.
  • ids - Mints ids for the rows the plan creates.

Returns

The plan of writes, with Plan::holding set to None.

Generated from crates/bookclerk-resolve at main · View as Markdown