//! The read side of a mind: a document with the facts of its admission and //! its status, and one typed selection over them. //! //! Nothing here is stored. Status is derived per call through the same //! `docs::Docs` the admission rules use, so a withdrawn resolution reopens its //! subject for a reader exactly when it reopens it for a rule. The facts come //! from the commit receipts, from their `writes` and from nothing else: a //! document's `admitted_at` is the `now` its batch was admitted at //! (`committed_at`), never the store's `stored_at` stamp. A pipeline document //! in the image that no receipt wrote is an integrity fault and refuses; the //! store has one writer and the receipt is its proof. //! //! `query` is CultNet's selection over rows this crate supplies (`rows.rs`). //! The substrate owns the filter, the order, the hop, the cursor and the //! paging; this module owns the snapshot (`Reader::at`: every derivation runs //! over the documents admitted at or before the page's `asOf`), the //! projection to a header or a whole view, and the typing of the edges. //! //! `rank` is the semantic read: the daemon's index supplies candidate ids and //! scores, and this module joins them back through the mind and lets the //! selection decide. No clock, no store handle, no network. use std::collections::BTreeMap; use cultnet_rs::{ Cursor, EdgeAnchor, EdgeMatch, Evaluation, LIMIT_MAX, LIMIT_MIN, PROJECTION_DOCUMENT, Row, Selection, select, validate, }; use eureka_pipeline::{ ClaimOutcome, CommitRange, Date, FindingConfidence, FindingOrigin, FindingSeverity, Label, Line, OrgRepo, PipelineDocument, PipelineKind, PipelineRef, PipelineResolution, ResolutionOutcome, RulingAuthority, RunOperator, RunTurn, Sha, Short, Slug, Title, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use crate::docs::{CitationRole, Docs, Held, citations}; use crate::mind::Mind; use crate::receipt::{self, PipelineProvenance}; use crate::refusal::MindRefusal; use crate::rows::{SelectionRow, Vocabulary, refuse_values}; use crate::store::MindStore; /// What admission recorded about a document when it landed: the receipt that /// wrote it, the `now` that receipt was taken at, who asked, and the /// receipt's ordinal, which is the read side's order and its snapshot /// position. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub struct AdmissionFacts { pub receipt_id: String, pub admitted_at: String, pub provenance: PipelineProvenance, #[schemars(range(min = 1))] pub ordinal: u64, } /// Whether a document still stands, and if not, what closed it. Derived at /// read time; no document carries a status field and no admission writes one. /// The whole closing record travels, not only its outcome, because a reader /// rehydrating wants why. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub enum PipelineStatus { InForce, Resolved { resolution: PipelineRef, record: PipelineResolution }, } /// One document as a reader gets it: its id, the document, the facts of its /// admission and its status. The id travels with the document because a /// `PipelineDocument` does not carry its key and a client must never derive /// one. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub struct PipelineDocumentView { pub id: PipelineRef, pub document: PipelineDocument, pub admission: AdmissionFacts, pub status: PipelineStatus, } /// A semantic query: the text to find documents near, and how many. The index /// owns which fields of each kind are text (`index_text`), so no substring /// filter lives here to become a second answer to that question. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub struct SemanticQuery { pub text: Line, pub top_k: u32, } /// A header's most encoded bytes, whatever the document's lists hold: the /// summary carries only the facts a caller decides what to work on from, /// each bounded by the leaf's own bounds. pub const SUMMARY_MAX_BYTES: usize = 8_192; /// Whether a summarised document stands: the closing record's outcome, not its /// rationale. A caller who wants why opens the resolution. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub enum PipelineStatusSummary { InForce, Resolved { resolution: PipelineRef, outcome: ResolutionOutcome }, } /// The organ's meaning of `projection: header`: a document's id, the facts of /// its admission, its status and the few fields of its kind a caller triages /// by. Derived per read and bounded by `SUMMARY_MAX_BYTES`. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub struct PipelineDocumentSummary { pub id: PipelineRef, pub admission: AdmissionFacts, pub status: PipelineStatusSummary, pub facts: PipelineFacts, } /// The triage fields of each kind, in the leaf's own envelope spelling. Prose /// (`Para`) and unbounded lists are not carried; `finding.claim` and /// `follow_up.item` are, because the leaf typed them as one-line statements. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] #[serde(tag = "kind", content = "value", rename_all = "snake_case")] pub enum PipelineFacts { Campaign { title: Title, repos: Vec }, Target { revision: u32, invariants: Vec