pub struct Model {
pub knowledges: Vec<Knowledge>,
pub additional: Vec<AdditionalFile>,
pub dispatch: BTreeMap<RepoPath, Option<SchemaRef>>,
pub tree: Tree,
pub problems: Vec<Finding>,
pub reads: Recorder,
pub fallback: Option<Box<dyn Fallback>>,
pub markers: BTreeMap<RepoPath, Vec<MarkerRow>>,
pub marker_check: MarkerCheck,
pub plans: PlanIndex,
pub chains: Chains,
/* private fields */
}Expand description
A Model holds every knowledge store, every additional file, and the tree.
Fields§
§knowledges: Vec<Knowledge>The knowledge stores, in configuration order.
additional: Vec<AdditionalFile>The additional files that the run has loaded, by path.
dispatch: BTreeMap<RepoPath, Option<SchemaRef>>Each additional file that a schema’s globs match, by path, whether the run has loaded it or not. The value is the schema whose glob matches the file, or none when the globs of more than one schema match it (CACHE-1_AC-15).
tree: TreeThe walked tree.
problems: Vec<Finding>The findings of the build, such as files that fail to load and globs that clash.
reads: RecorderThe reads of the run. The recorder keeps each query that the check of a file makes, under the path of that file (CACHE-1_AC-4).
fallback: Option<Box<dyn Fallback>>The cache. It supplies facts about the documents that the run did not load (CACHE-1_AC-21).
markers: BTreeMap<RepoPath, Vec<MarkerRow>>The markers of each file outside the knowledge roots that the run has loaded, by path. The markers come from a scan of the file, or from the rows that the cache keeps for it.
marker_check: MarkerCheckWhat the run does with markers. It is Off until a check sets it.
plans: PlanIndexplans holds the files that the documents plan (SOKF_SCHEMA_53).
chains: Chainschains holds the chain of extends of each store, resolved when
the model is built (SOKF_SCHEMA_96).
Implementations§
Source§impl Model
impl Model
Sourcepub fn is_archived(
&self,
knowledge: usize,
type_name: Option<&str>,
frontmatter: Option<&Spanned>,
) -> bool
pub fn is_archived( &self, knowledge: usize, type_name: Option<&str>, frontmatter: Option<&Spanned>, ) -> bool
is_archived returns whether a document of store knowledge is
archived, from its type and its frontmatter, as archived_documents
decides it.
Sourcepub fn archived_documents(&self) -> BTreeSet<RepoPath>
pub fn archived_documents(&self) -> BTreeSet<RepoPath>
archived_documents returns the archived documents of every store.
For each document that this run loaded, it reads the frontmatter to
decide whether the document is archived. For every other document, it
reads the store’s rows.
Source§impl Model
impl Model
Sourcepub fn own_roots(&self) -> usize
pub fn own_roots(&self) -> usize
own_roots returns the number of own stores, those of
knowledge.roots, which come before the registered ones
(CLI-6_AC-116).
Sourcepub fn broken(&self, k: usize) -> Option<&Broken>
pub fn broken(&self, k: usize) -> Option<&Broken>
broken returns why store k has no chain of extends, or None
when it has one.
Sourcepub fn in_broken_store(&self, path: &RepoPath) -> bool
pub fn in_broken_store(&self, path: &RepoPath) -> bool
in_broken_store returns whether path lies in a store whose
extends is broken, whose files no check and no fix touches
(FORMAT-5_AC-10).
Sourcepub fn inherited(&self, k: usize) -> Vec<SchemaRef>
pub fn inherited(&self, k: usize) -> Vec<SchemaRef>
inherited returns each schema that store k inherits.
Sourcepub fn claimants(&self, k: usize, type_name: &str) -> Vec<SchemaRef>
pub fn claimants(&self, k: usize, type_name: &str) -> Vec<SchemaRef>
claimants returns the schemas that govern type_name in store k,
through the chain of extends. It records the schema query of each
store that it reads, so that a schema that a store of the chain
adds, removes, or changes makes the reader dirty (CACHE-1_AC-15).
Source§impl Model
impl Model
Sourcepub fn reads_of(&self, reader: &RepoPath) -> BTreeSet<Query>
pub fn reads_of(&self, reader: &RepoPath) -> BTreeSet<Query>
reads_of returns the queries that reader made.
Sourcepub fn reads(&self) -> BTreeMap<RepoPath, BTreeSet<Query>>
pub fn reads(&self) -> BTreeMap<RepoPath, BTreeSet<Query>>
reads returns the queries of every reader.
Sourcepub fn document(&self, knowledge: usize, id: &str) -> Option<&Document>
pub fn document(&self, knowledge: usize, id: &str) -> Option<&Document>
document returns the document with id in knowledge, when the run
has loaded it. Before the checks run, the run loads every document
that a check looks up. If only the cache knows a document, the run
failed to load it, so a debug build stops with an assertion failure.
Sourcepub fn ids(&self, knowledge: usize, id: &str) -> Vec<RepoPath>
pub fn ids(&self, knowledge: usize, id: &str) -> Vec<RepoPath>
ids returns the path of every document and schema of knowledge
that has id. It takes the paths from the documents that the run has
loaded. It then adds each path that the cache knows, unless the run
has loaded it.
Sourcepub fn documents_of(&self, knowledge: usize, type_name: &str) -> Vec<&Document>
pub fn documents_of(&self, knowledge: usize, type_name: &str) -> Vec<&Document>
documents_of returns the documents of type type_name in
knowledge that the run has loaded.
Sourcepub fn ids_of_type(
&self,
knowledge: usize,
type_name: &str,
) -> Vec<(RepoPath, String)>
pub fn ids_of_type( &self, knowledge: usize, type_name: &str, ) -> Vec<(RepoPath, String)>
ids_of_type returns the path and id of every document of type
type_name in knowledge. It takes them from the documents that the
run has loaded. For the paths that the run has not loaded, it adds the
cache’s rows.
Sourcepub fn path_of_id(&self, knowledge: usize, id: &str) -> Option<RepoPath>
pub fn path_of_id(&self, knowledge: usize, id: &str) -> Option<RepoPath>
path_of_id returns the path of the document or schema with id in
knowledge, when exactly one document or schema has it. It counts the
documents that the run has loaded and the ones that the cache knows
(CACHE-1_AC-21).
Sourcepub fn id_of(&self, path: &RepoPath) -> Option<(usize, String)>
pub fn id_of(&self, path: &RepoPath) -> Option<(usize, String)>
id_of returns the knowledge store and id of the document or schema
at path. It takes them from the document when the run has loaded
it, and from the cache’s row for the path otherwise.
Sourcepub fn broken_in(&self, knowledge: usize) -> Vec<RepoPath>
pub fn broken_in(&self, knowledge: usize) -> Vec<RepoPath>
broken_in returns the paths of the documents of knowledge whose
frontmatter doesn’t parse. It takes them from the documents that the
run has loaded. For the documents that the run has not loaded, it adds
the paths that the cache lists as broken.
Sourcepub fn holds(&self, path: &RepoPath) -> bool
pub fn holds(&self, path: &RepoPath) -> bool
holds reports whether the run has loaded a document or schema at
path.
Sourcepub fn is_document(&self, path: &RepoPath) -> bool
pub fn is_document(&self, path: &RepoPath) -> bool
is_document reports whether path is a document of any knowledge
store, whether the run has loaded it or only the cache knows it.
Sourcepub fn admit(&mut self, knowledge: usize, doc: Document)
pub fn admit(&mut self, knowledge: usize, doc: Document)
admit adds to the model a document that the build did not load. The
run has since read the document in full. Such a document is one that the
run checks, or one that a check looks up.
Sourcepub fn admit_schema(&mut self, knowledge: usize, schema: SchemaDocument)
pub fn admit_schema(&mut self, knowledge: usize, schema: SchemaDocument)
admit_schema replaces the cache’s summary of a schema with the
schema read in full. It keeps the same index, so every reference to
the schema stays valid (CACHE-1_AC-25).
Sourcepub fn admit_index(&mut self, knowledge: usize, index: IndexFile)
pub fn admit_index(&mut self, knowledge: usize, index: IndexFile)
admit_index adds to the model an index file that the build did not
load. The run reads the index file of a directory when a change
touches the directory, so that the check of the directory can compare
it with the expected index (CACHE-1_AC-18).
Sourcepub fn exists(&self, path: &RepoPath) -> bool
pub fn exists(&self, path: &RepoPath) -> bool
exists reports whether path is a file or a directory of the
repository, and records the question as a query (CACHE-1_AC-26).
Sourcepub fn is_dir(&self, path: &RepoPath) -> bool
pub fn is_dir(&self, path: &RepoPath) -> bool
is_dir reports whether path is a directory of the repository, and
records the question as the query of exists.
Sourcepub fn by_path(&self, path: &RepoPath) -> Option<Located<'_>>
pub fn by_path(&self, path: &RepoPath) -> Option<Located<'_>>
by_path returns what path is in the model.
Sourcepub fn is_document_of(&self, knowledge: usize, path: &RepoPath) -> bool
pub fn is_document_of(&self, knowledge: usize, path: &RepoPath) -> bool
is_document_of reports whether path is a document of knowledge.
Sourcepub fn is_materialized(&self, path: &RepoPath) -> bool
pub fn is_materialized(&self, path: &RepoPath) -> bool
is_materialized reports whether path is a document of any
knowledge store or an additional file. An include block that refers to
a file by path can’t include such a file.
Sourcepub fn is_additional(&self, path: &RepoPath) -> bool
pub fn is_additional(&self, path: &RepoPath) -> bool
is_additional reports whether a schema’s globs match path as an
additional file, whether the run has loaded it or not.
Sourcepub fn admit_additional(&mut self, file: AdditionalFile)
pub fn admit_additional(&mut self, file: AdditionalFile)
admit_additional adds to the model an additional file that the
build did not load. The run has since read the file in full, because a
check needs it (CACHE-1_AC-20).
Sourcepub fn is_materialized_in(
&self,
knowledge: Option<usize>,
path: &RepoPath,
) -> bool
pub fn is_materialized_in( &self, knowledge: Option<usize>, path: &RepoPath, ) -> bool
is_materialized_in reports whether path is a document of
knowledge or an additional file that its schemas match. An include
block in a document of knowledge can’t include such a file by path
(SOKF_FORMAT_89). is_materialized_in treats an additional file of
another knowledge store as an ordinary repository file, which such an
include block can include. With no knowledge store given, the files of
every knowledge store count. To reject an include block that refers by
path to a document or an asset of any knowledge store, a caller checks
the path separately, through id_at and asset_at.
Sourcepub fn asset_of(&self, sidecar: &RepoPath) -> Option<(usize, &Asset)>
pub fn asset_of(&self, sidecar: &RepoPath) -> Option<(usize, &Asset)>
asset_of returns the asset that the document at sidecar
describes, with its knowledge store.
Sourcepub fn asset_at(&self, path: &RepoPath) -> Option<(usize, &Asset)>
pub fn asset_at(&self, path: &RepoPath) -> Option<(usize, &Asset)>
asset_at returns the asset at path, with its knowledge store.
Sourcepub fn content_path(&self, document: &RepoPath) -> RepoPath
pub fn content_path(&self, document: &RepoPath) -> RepoPath
content_path returns the path that the id of a document refers to
(FORMAT-2_AC-1): the path of the asset for a sidecar, and the path of
the document otherwise. The resolution of an id doesn’t change: an id
still resolves to its document. Only code that needs the content calls
content_path. For example, the code that builds the definition of a
label without a fragment calls it.
Sourcepub fn schema(&self, r: SchemaRef) -> &SchemaDocument
pub fn schema(&self, r: SchemaRef) -> &SchemaDocument
schema returns the schema at r.
Sourcepub fn schema_query(&self, r: SchemaRef) -> Query
pub fn schema_query(&self, r: SchemaRef) -> Query
schema_query returns the query that stands for a read of the schema
at r. The query uses the key that schema_key returns. The key is
the value of the schema’s type const, or, for a schema that
dispatches only by its globs, the schema’s path (CACHE-1_AC-15).
Sourcepub fn knowledge_of(&self, path: &RepoPath) -> Option<usize>
pub fn knowledge_of(&self, path: &RepoPath) -> Option<usize>
knowledge_of returns the knowledge store whose root contains path,
the innermost one when roots nest.
Sourcepub fn is_unit(&self, path: &RepoPath) -> bool
pub fn is_unit(&self, path: &RepoPath) -> bool
is_unit reports whether path is a unit. A unit is a file that a
check produces output for: a document, a schema document, or an
additional file matched by a schema’s globs (CACHE-1_AC-24). It searches the
walk’s sorted list, so it does not build a set of all paths.
Sourcepub fn is_marker_file(&self, path: &RepoPath) -> bool
pub fn is_marker_file(&self, path: &RepoPath) -> bool
is_marker_file reports whether path is a file that the run reads
for markers: a file of the walk outside every knowledge root, when the
run checks markers (SOKF_VALIDATION_50).
Sourcepub fn document_paths(&self) -> BTreeSet<RepoPath>
pub fn document_paths(&self) -> BTreeSet<RepoPath>
document_paths returns the path of every document and schema
document of every knowledge store that the walk lists, whether the run
has loaded it or not. These are the files that a full run reads.
Sourcepub fn documents(&self) -> impl Iterator<Item = (usize, &Document)>
pub fn documents(&self) -> impl Iterator<Item = (usize, &Document)>
documents returns every document of every knowledge store, with the
index of its knowledge store.
Sourcepub fn documents_and_schemas(&self) -> impl Iterator<Item = (usize, &Document)>
pub fn documents_and_schemas(&self) -> impl Iterator<Item = (usize, &Document)>
documents_and_schemas returns every document and every schema
document of every knowledge store, with the index of its knowledge
store.
Source§impl Model
impl Model
Sourcepub fn is_planned(&self, path: &RepoPath) -> bool
pub fn is_planned(&self, path: &RepoPath) -> bool
is_planned reports whether a document plans a file at path, and
records the query for path and for each directory above it, so
that the reader is checked again when the plan of the path or of a
directory that holds it changes.
Source§impl Model
impl Model
Sourcepub fn identity_rows(&self) -> Vec<IdentityRow>
pub fn identity_rows(&self) -> Vec<IdentityRow>
identity_rows returns the current and former identities of every
store, in the form that the cache compares (CACHE-1_AC-16).
Sourcepub fn store(&self, citing: usize, written: &str) -> Option<StoreHit>
pub fn store(&self, citing: usize, written: &str) -> Option<StoreHit>
store finds the store that written refers to from a document of
store citing (SOKF_FORMAT_64). It looks up a name among the
stores in the scope of the citing store, and a scope/name among
every store. It matches the current identities first, then the
former ones. When two stores share an identity, store returns
None, because validation reports that clash on their manifests.
store records a single dependency on the identities of all stores
(CACHE-1_AC-16), not one for each store it reads. A finer dependency
would save little, for two reasons. Renaming a store changes every
qualified id that refers to the store, and few documents need store.
Sourcepub fn stores_named(&self, written: &str) -> Vec<usize>
pub fn stores_named(&self, written: &str) -> Vec<usize>
stores_named returns the stores that written names on the command
line, where no citing store gives a scope. It matches a scope/name
against the whole identity and a name against the name of every
store. It matches the current identities first, then the former ones.
Sourcepub fn store_name(&self, k: usize) -> Option<String>
pub fn store_name(&self, k: usize) -> Option<String>
store_name returns the shortest name of store k on the command
line: its name, or its whole identity when another store shares
that name. It returns None when the store has no identity.
Sourcepub fn document_in(
&self,
citing: usize,
store: Option<&str>,
id: &str,
) -> Option<(usize, &Document)>
pub fn document_in( &self, citing: usize, store: Option<&str>, id: &str, ) -> Option<(usize, &Document)>
document_in finds the document that id refers to in store.
store is a store prefix as a document of store citing wrote it. It
returns the document with the index of the knowledge store that
holds it. When store is None, it looks in citing.
Sourcepub fn id_at(&self, path: &RepoPath) -> Option<(usize, String)>
pub fn id_at(&self, path: &RepoPath) -> Option<(usize, String)>
id_at returns the id of the document or schema at path, in any
store, with the index of its knowledge store.
Sourcepub fn path_label(
&self,
citing: usize,
path: &RepoPath,
fragment: Option<&str>,
) -> Option<String>
pub fn path_label( &self, citing: usize, path: &RepoPath, fragment: Option<&str>, ) -> Option<String>
path_label returns the canonical sokf: label that a document in
store citing should use for a link to path with fragment
(SOKF_FORMAT_65). The label depends on the file at path:
- For a document, the label is its id with the fragment.
- For a sidecar, the label is its id with the fragment, and with an empty fragment when the link has none, because the path refers to the sidecar file and not to the asset.
- For an asset, the label is the id of its sidecar, which refers to the asset.
path_label returns None for any other file, and for an asset
path with a fragment.
Sourcepub fn prefix(&self, citing: usize, target: usize) -> Option<String>
pub fn prefix(&self, citing: usize, target: usize) -> Option<String>
prefix returns the store prefix that a document in store citing
should put before an id in store target. It is the shortest
unambiguous prefix (SOKF_FORMAT_65). The prefix is empty within one store,
name: within one scope, and scope/name: otherwise. prefix
returns None when the two stores differ and either has no
identity.