Skip to main content

sokf_core/model/
fallback.rs

1//! The store answers questions about the documents that a run doesn't
2//! hold, in five kinds of question: the ids in a store, the documents of a
3//! type, whether a path is a document, the fields that an index lists, and
4//! whether each document's frontmatter parses (CACHE-1_AC-13). The run reads every other
5//! fact about a document from the document's file.
6
7use crate::RepoPath;
8
9/// `Fields` holds the fields of a document that an index entry needs.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct Fields {
12    /// The `id` value.
13    pub id: Option<String>,
14    /// The `title` value.
15    pub title: Option<String>,
16    /// The `description` value.
17    pub description: Option<String>,
18}
19
20/// `SchemaMeta` holds what the store keeps about a schema file that the
21/// run doesn't read: enough to dispatch on the schema, match its globs, and
22/// identify it. The run reads the file only when a check needs the compiled
23/// schema (CACHE-1_AC-25).
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct SchemaMeta {
26    /// The `id` value.
27    pub id: Option<String>,
28    /// The `type` const, when the schema declares a type.
29    pub type_const: Option<String>,
30    /// The `additional-files` globs.
31    pub globs: Vec<String>,
32    /// The `asset-files` globs.
33    pub asset_globs: Vec<String>,
34    /// The names, such as `t:<type>` and `f:<format>`, that the schema refers
35    /// to in the registry.
36    pub uses: Vec<String>,
37    /// The line where the body starts. A finding about the whole schema
38    /// reports this line.
39    pub body_line: usize,
40    /// The `archived` value, which says which documents of the type are
41    /// archived.
42    pub archived: super::Archived,
43}
44
45// sokf:begin fallback
46/// `Fallback` answers questions about the documents that the run doesn't
47/// hold, from the store's rows. A model queries it after searching its own
48/// documents, and never for a path that the model holds.
49pub trait Fallback: std::fmt::Debug {
50    /// `ids` returns the paths of the documents of `knowledge` that have
51    /// `id`.
52    fn ids(&self, knowledge: usize, id: &str) -> Vec<RepoPath>;
53
54    /// `ids_of_type` returns the path and id of each document of
55    /// `knowledge` whose type is `type_name`.
56    fn ids_of_type(&self, knowledge: usize, type_name: &str) -> Vec<(RepoPath, String)>;
57
58    /// `is_document` reports whether `path` is a document of any store.
59    fn is_document(&self, path: &RepoPath) -> bool;
60
61    /// `fields` returns the fields of the document at `path`.
62    fn fields(&self, path: &RepoPath) -> Option<Fields>;
63
64    /// `broken` reports whether the document at `path` has no frontmatter, or
65    /// has frontmatter that fails to parse.
66    fn broken(&self, path: &RepoPath) -> bool;
67
68    /// `broken_in` returns the paths of the documents of `knowledge` whose
69    /// frontmatter is missing or fails to parse.
70    fn broken_in(&self, knowledge: usize) -> Vec<RepoPath>;
71
72    /// `schema_meta` returns what the store keeps about the schema file at
73    /// `path`.
74    fn schema_meta(&self, path: &RepoPath) -> Option<SchemaMeta>;
75
76    /// `scalars_of_type` returns the path and the scalar frontmatter values
77    /// of each document of `knowledge` whose type is `type_name`.
78    fn scalars_of_type(
79        &self,
80        knowledge: usize,
81        type_name: &str,
82    ) -> Vec<(RepoPath, Vec<(String, String)>)>;
83}
84// sokf:end fallback