pub struct Store { /* private fields */ }Expand description
An open store: one connection, one id minter (behind the in-use check of
mint). All writes go through it.
Implementations§
Source§impl Store
impl Store
Sourcepub fn docs_create(
&mut self,
ctx: &DocOpContext,
doc_store: &mut dyn DocStore,
path: &str,
markdown: &str,
frontmatter: Option<&Map<String, Value>>,
) -> Result<DocOpResult>
pub fn docs_create( &mut self, ctx: &DocOpContext, doc_store: &mut dyn DocStore, path: &str, markdown: &str, frontmatter: Option<&Map<String, Value>>, ) -> Result<DocOpResult>
§6 docs_create: a new document from complete bytes (frontmatter as
a mapping); path_taken when a live doc or a file exists; ingested
with the reconciling resolver (reason: "create <path>").
Sourcepub fn docs_move(
&mut self,
ctx: &DocOpContext,
doc_store: &mut dyn DocStore,
doc_ref: &str,
to_path: &str,
retarget_inbound: bool,
) -> Result<DocMoveResult>
pub fn docs_move( &mut self, ctx: &DocOpContext, doc_store: &mut dyn DocStore, doc_ref: &str, to_path: &str, retarget_inbound: bool, ) -> Result<DocMoveResult>
§6 docs_move: rename a document (identity kept); an api commit
with no revision; open edges from other documents re-pointed to
phantom:<old path> (a self edge only when its link names the path);
phantoms at the new path adopted. With retarget_inbound — the
surface’s default since mutate 1.3 — the dangling links are rewritten
as one follow-up changeset; false leaves them as written.
Sourcepub fn docs_delete(
&mut self,
ctx: &DocOpContext,
doc_store: &mut dyn DocStore,
doc_ref: &str,
) -> Result<DocOpResult>
pub fn docs_delete( &mut self, ctx: &DocOpContext, doc_store: &mut dyn DocStore, doc_ref: &str, ) -> Result<DocOpResult>
§6 docs_delete: one transaction — an api commit, FTS rows dropped,
live blocks and the doc tombstoned, nothing pooled — then the file
removed.
Sourcepub fn docs_set_meta(
&mut self,
ctx: &DocOpContext,
doc_store: &mut dyn DocStore,
doc_ref: &str,
set: Option<&Map<String, Value>>,
unset: &[String],
) -> Result<DocOpResult>
pub fn docs_set_meta( &mut self, ctx: &DocOpContext, doc_store: &mut dyn DocStore, doc_ref: &str, set: Option<&Map<String, Value>>, unset: &[String], ) -> Result<DocOpResult>
§6 docs_set_meta: read the file, split the frontmatter, merge set,
delete unset, compose, write, ingest with the reconciling resolver
(reason: "set_meta <path>").
Source§impl Store
impl Store
Sourcepub fn tasks_complete(&self, blocks: &[String]) -> Result<Vec<Op>>
pub fn tasks_complete(&self, blocks: &[String]) -> Result<Vec<Op>>
§5 tasks_complete: one update { attrs: { checked: true } } per
block, with the live CAS token when the block is known.
Sourcepub fn sections_rename(&self, heading: &str, title: &str) -> Result<Vec<Op>>
pub fn sections_rename(&self, heading: &str, title: &str) -> Result<Vec<Op>>
§5 sections_rename: the level from the live raw’s leading # run.
Sourcepub fn sections_move(&self, heading: &str, to: &To) -> Result<Vec<Op>>
pub fn sections_move(&self, heading: &str, to: &To) -> Result<Vec<Op>>
§5 sections_move: the heading’s section run (top-level ids from the
heading to before the next heading of level ≤ its own); [] when the
heading is unknown.
Sourcepub fn lists_insert_item(anchor: &str, at: At, markdown: &str) -> Vec<Op>
pub fn lists_insert_item(anchor: &str, at: At, markdown: &str) -> Vec<Op>
§5 lists_insert_item.
Sourcepub fn node_set(
&self,
node_id: &str,
prop: &str,
value: &str,
) -> Result<Vec<Op>>
pub fn node_set( &self, node_id: &str, prop: &str, value: &str, ) -> Result<Vec<Op>>
§5 node_set: the adapter’s editor for (kind, prop) over the node’s
block raw and byte span → one update with the CAS token.
Sourcepub fn links_retarget(
&self,
repo_id: &str,
from: &str,
to: &str,
path_glob: Option<&str>,
) -> Result<LinkRepairPlan>
pub fn links_retarget( &self, repo_id: &str, from: &str, to: &str, path_glob: Option<&str>, ) -> Result<LinkRepairPlan>
§5 links_retarget: the one-pair form of Store::links_repair.
Sourcepub fn links_repair(
&self,
repo_id: &str,
repairs: &[LinkRepair],
path_glob: Option<&str>,
) -> Result<LinkRepairPlan>
pub fn links_repair( &self, repo_id: &str, repairs: &[LinkRepair], path_glob: Option<&str>, ) -> Result<LinkRepairPlan>
§5 links_repair: for every live non-code_fence block whose raw
contains a slash-less from, rewrite each whole link destination that
names it (first matching pair wins, fragment re-appended, never inside
code spans); one update per changed top-most block.
Source§impl Store
impl Store
Sourcepub fn load_mut_doc(&self, doc_id: &str) -> Result<Option<MutDoc>>
pub fn load_mut_doc(&self, doc_id: &str) -> Result<Option<MutDoc>>
§1: load_mut_doc on this store.
Sourcepub fn find_doc_by_ref(&self, repo_id: &str, r: &str) -> Result<Option<DocInfo>>
pub fn find_doc_by_ref(&self, repo_id: &str, r: &str) -> Result<Option<DocInfo>>
A live doc by id or path.
Sourcepub fn apply(
&mut self,
req: &ApplyRequest,
doc_store: &mut dyn DocStore,
ts: &str,
) -> Result<ApplyResult>
pub fn apply( &mut self, req: &ApplyRequest, doc_store: &mut dyn DocStore, ts: &str, ) -> Result<ApplyResult>
§4: apply a changeset at ts (RFC 3339 UTC, stamped on every commit
the request records). Steps 1–4 in memory; unless dry_run, the
commit phase per loaded document in load order — file-CAS against
doc_store (a mismatch ingests the on-disk bytes as observed and
raises sync_conflict), the atomic write, the api ingest with the
known ids. Atomic up to the commit phase; a sync_conflict on the
n-th document leaves the earlier ones committed (§10).
Source§impl Store
impl Store
Sourcepub fn observe_batch(
&mut self,
repo_id: &str,
items: &[BatchItem],
ts: &str,
config: &Config,
) -> Result<Vec<BatchOutcome>>
pub fn observe_batch( &mut self, repo_id: &str, items: &[BatchItem], ts: &str, config: &Config, ) -> Result<Vec<BatchOutcome>>
§5: observe a batch of members at ts (RFC 3339 UTC, §2.4) with the
spec/reconcile thresholds in config. Does not sweep the pool
(§5.5: the caller does, once per batch).
Sourcepub fn reconciling_ingest(
&mut self,
repo_id: &str,
path: &str,
source: &str,
ts: &str,
origin: Origin,
actor: Option<&str>,
reason: Option<&str>,
config: &Config,
) -> Result<Committed>
pub fn reconciling_ingest( &mut self, repo_id: &str, path: &str, source: &str, ts: &str, origin: Origin, actor: Option<&str>, reason: Option<&str>, config: &Config, ) -> Result<Committed>
Parse and reconcile source at path against the stored tree (the
pool offered when a doc row exists, §5.1 step 4) and commit it with
the given provenance — the reference’s ingestFile with
makeReconcilingResolver: docs_create/docs_set_meta (api) and
the file-CAS conflict ingest of spec/mutate §4 (observed). No echo
gate, no conflicted update, no sweep. The sync layer’s recovery and
attach_source (spec/sync §4.3, §6) ingest through this too, with
Origin::Observed.
Sourcepub fn fresh_ingest(
&mut self,
repo_id: &str,
path: &str,
source: &str,
ts: &str,
origin: Origin,
) -> Result<Committed>
pub fn fresh_ingest( &mut self, repo_id: &str, path: &str, source: &str, ts: &str, origin: Origin, ) -> Result<Committed>
Parse source at path and commit it with a fresh b id for every
block — the reference’s ingestFile without a resolver (no
dispositions, nothing pooled): the re-mint path spec/sync §6 pins for
a borne source’s attach_source (§9). No echo gate, no sweep.
Sourcepub fn observe_one(
&mut self,
repo_id: &str,
path: &str,
source: &str,
ts: &str,
config: &Config,
) -> Result<ObserveOutcome>
pub fn observe_one( &mut self, repo_id: &str, path: &str, source: &str, ts: &str, config: &Config, ) -> Result<ObserveOutcome>
A batch of one (§5: “the same procedure without the middle”). Does not sweep the pool.
Sourcepub fn observe_delete(
&mut self,
repo_id: &str,
path: &str,
ts: &str,
) -> Result<DeleteOutcome>
pub fn observe_delete( &mut self, repo_id: &str, path: &str, ts: &str, ) -> Result<DeleteOutcome>
Observe that path is gone (§5.6) and sweep the pool at ts (§5.5),
as the reference’s observeDelete does. A path with no live doc is a
no-op (doc_id: None).
Source§impl Store
impl Store
Sourcepub fn plan_update(
&mut self,
repo_id: &str,
doc_ref: &str,
content: &str,
config: &Config,
) -> Result<Opset>
pub fn plan_update( &mut self, repo_id: &str, doc_ref: &str, content: &str, config: &Config, ) -> Result<Opset>
§7 plan_update: the opset for replacing doc_ref’s content with
content. Never writes; mints (the reconcile’s new ids, the dry-run
verification’s) as the reference does.
Sourcepub fn apply_opset(
&mut self,
repo_id: &str,
opset: &Opset,
origin: &ApplyOrigin,
dry_run: bool,
doc_store: &mut dyn DocStore,
ts: &str,
) -> Result<ApplyResult>
pub fn apply_opset( &mut self, repo_id: &str, opset: &Opset, origin: &ApplyOrigin, dry_run: bool, doc_store: &mut dyn DocStore, ts: &str, ) -> Result<ApplyResult>
§7.2 apply_opset: refuse a non-convergent plan, check the
preconditions (stale_plan with the current revision and hash), then
apply the plan’s kernel ops with its frontmatter override.
Sourcepub fn docs_update(
&mut self,
repo_id: &str,
doc_ref: &str,
content: &str,
config: &Config,
origin: &ApplyOrigin,
dry_run: bool,
doc_store: &mut dyn DocStore,
ts: &str,
) -> Result<(Opset, Option<ApplyResult>)>
pub fn docs_update( &mut self, repo_id: &str, doc_ref: &str, content: &str, config: &Config, origin: &ApplyOrigin, dry_run: bool, doc_store: &mut dyn DocStore, ts: &str, ) -> Result<(Opset, Option<ApplyResult>)>
docs_update: plan then apply (None result on a dry run).
Source§impl Store
impl Store
Sourcepub fn text_search(
&self,
repo_id: &str,
query: &str,
limit: usize,
) -> Result<TextSearchResult>
pub fn text_search( &self, repo_id: &str, query: &str, limit: usize, ) -> Result<TextSearchResult>
spec/search §1.3.
Sourcepub fn build_embed_tasks(&self, repo_id: &str) -> Result<Vec<EmbedTask>>
pub fn build_embed_tasks(&self, repo_id: &str) -> Result<Vec<EmbedTask>>
spec/search §2.2: the embeddable blocks’ tasks, (path, ordinal) order.
Sourcepub fn build_doc_embed_tasks(&self, repo_id: &str) -> Result<Vec<DocEmbedTask>>
pub fn build_doc_embed_tasks(&self, repo_id: &str) -> Result<Vec<DocEmbedTask>>
spec/search §2.4: the live documents’ tasks, path order.
Sourcepub fn embed_process(
&self,
tasks: &[EmbedTask],
provider: &dyn EmbeddingProvider,
) -> Result<EmbedStats>
pub fn embed_process( &self, tasks: &[EmbedTask], provider: &dyn EmbeddingProvider, ) -> Result<EmbedStats>
spec/search §2.3: embed the cache misses among tasks.
Sourcepub fn embed_process_docs(
&self,
tasks: &[DocEmbedTask],
provider: &dyn EmbeddingProvider,
) -> Result<DocEmbedStats>
pub fn embed_process_docs( &self, tasks: &[DocEmbedTask], provider: &dyn EmbeddingProvider, ) -> Result<DocEmbedStats>
spec/search §2.4–§2.5: one vector per document, whole or pooled.
Sourcepub fn drain(
&self,
repo_id: &str,
provider: &dyn EmbeddingProvider,
) -> Result<DrainStats>
pub fn drain( &self, repo_id: &str, provider: &dyn EmbeddingProvider, ) -> Result<DrainStats>
spec/search §2.6: one drain — the block pass, then the document pass.
Sourcepub fn cached_vector(
&self,
content_hash_hex: &str,
ctx: &str,
model: &str,
) -> Result<Option<Vec<f32>>>
pub fn cached_vector( &self, content_hash_hex: &str, ctx: &str, model: &str, ) -> Result<Option<Vec<f32>>>
The cached vector for a block cache key under model.
Sourcepub fn cached_doc_vector(
&self,
task: &DocEmbedTask,
model: &str,
) -> Result<Option<DocVectorRow>>
pub fn cached_doc_vector( &self, task: &DocEmbedTask, model: &str, ) -> Result<Option<DocVectorRow>>
The fresh cached document vector for a task under model.
Sourcepub fn stale_blocks(
&self,
tasks: &[EmbedTask],
model: &str,
) -> Result<Vec<String>>
pub fn stale_blocks( &self, tasks: &[EmbedTask], model: &str, ) -> Result<Vec<String>>
Block ids among tasks with no cached vector under model.
Sourcepub fn stale_docs(
&self,
tasks: &[DocEmbedTask],
model: &str,
) -> Result<Vec<String>>
pub fn stale_docs( &self, tasks: &[DocEmbedTask], model: &str, ) -> Result<Vec<String>>
Doc ids among tasks with no fresh cached vector under model.
Sourcepub fn foreign_vector_count(&self, model: &str) -> Result<ForeignVectors>
pub fn foreign_vector_count(&self, model: &str) -> Result<ForeignVectors>
spec/search §2.6: vectors under another model.
Sourcepub fn prune_foreign_vectors(&self, model: &str) -> Result<ForeignVectors>
pub fn prune_foreign_vectors(&self, model: &str) -> Result<ForeignVectors>
spec/search §2.6: delete vectors under another model.
Sourcepub fn block_vector(
&self,
block_id: &str,
model: &str,
) -> Result<Option<Vec<u8>>>
pub fn block_vector( &self, block_id: &str, model: &str, ) -> Result<Option<Vec<u8>>>
spec/search §3 (1.1): a live block’s vector — the row for its current
(content_hash, ctx_hash) under model — as the stored blob, None
when stale or not live. Serves semantic() (spec/surface §1.3).
Sourcepub fn vector_search(
&self,
repo_id: &str,
model: &str,
query: &[f32],
limit: usize,
) -> Result<Vec<VectorHit>>
pub fn vector_search( &self, repo_id: &str, model: &str, query: &[f32], limit: usize, ) -> Result<Vec<VectorHit>>
spec/search §3 over blocks.
Sourcepub fn doc_vector_search(
&self,
repo_id: &str,
model: &str,
query: &[f32],
limit: usize,
) -> Result<Vec<DocVectorHit>>
pub fn doc_vector_search( &self, repo_id: &str, model: &str, query: &[f32], limit: usize, ) -> Result<Vec<DocVectorHit>>
spec/search §3 over documents.
Sourcepub fn hybrid_search(
&self,
repo_id: &str,
q: &HybridQuery,
) -> Result<Vec<HybridHit>>
pub fn hybrid_search( &self, repo_id: &str, q: &HybridQuery, ) -> Result<Vec<HybridHit>>
spec/search §4.
Source§impl Store
impl Store
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open (creating parent directories and the file as needed) with the
production minter. :memory: is a valid path.
Sourcepub fn open_with_minter(
path: impl AsRef<Path>,
minter: Box<dyn IdMinter>,
) -> Result<Self>
pub fn open_with_minter( path: impl AsRef<Path>, minter: Box<dyn IdMinter>, ) -> Result<Self>
Store::open with a replaceable minter (§2.2).
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
A fresh in-memory store (tests, fixtures).
Sourcepub fn open_in_memory_with_minter(minter: Box<dyn IdMinter>) -> Result<Self>
pub fn open_in_memory_with_minter(minter: Box<dyn IdMinter>) -> Result<Self>
A fresh in-memory store with a replaceable minter.
Sourcepub fn from_connection(
conn: Connection,
minter: Box<dyn IdMinter>,
) -> Result<Self>
pub fn from_connection( conn: Connection, minter: Box<dyn IdMinter>, ) -> Result<Self>
Adopt an existing connection: apply the §1 pragmas, register
cosine, run the opener (fresh → schema.sql; older → migrations;
newer → Error::SchemaTooNew).
Sourcepub fn conn(&self) -> &Connection
pub fn conn(&self) -> &Connection
The underlying connection.
Sourcepub fn mint(&mut self, prefix: &str) -> Result<String>
pub fn mint(&mut self, prefix: &str) -> Result<String>
Mint an id with prefix (§2.1): never one in use.
Sourcepub fn transaction(&self) -> Result<Transaction<'_>>
pub fn transaction(&self) -> Result<Transaction<'_>>
Begin a write transaction (one per commit, §1); rolls back on drop.
Sourcepub fn create_repo(&mut self, slug: &str) -> Result<String>
pub fn create_repo(&mut self, slug: &str) -> Result<String>
Create a repo with slug (mints rp); returns its id.
Sourcepub fn user_version(&self) -> Result<i64>
pub fn user_version(&self) -> Result<i64>
PRAGMA user_version.
Sourcepub fn put_tree_node(&self, entries: &[TreeEntry]) -> Result<String>
pub fn put_tree_node(&self, entries: &[TreeEntry]) -> Result<String>
Sourcepub fn write_block_tree(&self, blocks: &[TreeInputBlock]) -> Result<String>
pub fn write_block_tree(&self, blocks: &[TreeInputBlock]) -> Result<String>
Sourcepub fn new_commit(&mut self, input: &NewCommit<'_>) -> Result<(String, i64)>
pub fn new_commit(&mut self, input: &NewCommit<'_>) -> Result<(String, i64)>
writers::new_commit; returns (commit_id, seq).
Sourcepub fn write_revision(
&mut self,
input: &NewRevision<'_>,
) -> Result<(String, i64)>
pub fn write_revision( &mut self, input: &NewRevision<'_>, ) -> Result<(String, i64)>
writers::write_revision; returns (rev_id, seq).
Sourcepub fn reconstruct(&self, doc_id: &str) -> Result<Option<String>>
pub fn reconstruct(&self, doc_id: &str) -> Result<Option<String>>
§6.1: the current bytes of a live doc; None when tombstoned or unknown.
Sourcepub fn read_at_revision(
&self,
doc_id: &str,
rev_id: &str,
) -> Result<Option<RevisionRead>>
pub fn read_at_revision( &self, doc_id: &str, rev_id: &str, ) -> Result<Option<RevisionRead>>
§6.2: the bytes at a revision, from its Merkle root.
Sourcepub fn changes_since(
&self,
repo_id: &str,
cursor: i64,
limit: usize,
origin: Option<&str>,
) -> Result<ChangesPage>
pub fn changes_since( &self, repo_id: &str, cursor: i64, limit: usize, origin: Option<&str>, ) -> Result<ChangesPage>
The change feed (spec/sync §6): the repo’s commits with seq > cursor, optionally of one origin, limit + 1 fetched to set
truncated.
Sourcepub fn load_old_match_blocks(&self, doc_id: &str) -> Result<Vec<MatchBlock>>
pub fn load_old_match_blocks(&self, doc_id: &str) -> Result<Vec<MatchBlock>>
§5.2: the matcher’s old side for a doc, from the live blocks rows.
Sourcepub fn load_pool(&self, repo_id: &str, ts: &str) -> Result<Vec<PoolEntry>>
pub fn load_pool(&self, repo_id: &str, ts: &str) -> Result<Vec<PoolEntry>>
§5.1: the repo’s unexpired pool at ts.
Sourcepub fn properties(&self, doc_id: &str) -> Result<Vec<PropertyRow>>
pub fn properties(&self, doc_id: &str) -> Result<Vec<PropertyRow>>
The document’s live properties rows (spec/properties §1), in
write order.
Sourcepub fn properties_grouped(&self, doc_id: &str) -> Result<Value>
pub fn properties_grouped(&self, doc_id: &str) -> Result<Value>
spec/properties §5 grouped: {frontmatter, inline, computed}
(the docs_read.properties shape).
Sourcepub fn properties_merged(&self, doc_id: &str) -> Result<Value>
pub fn properties_merged(&self, doc_id: &str) -> Result<Value>
spec/properties §5 merged: {key: shape} over every row.
Sourcepub fn rebuild_doc_edges(&self, doc_id: &str) -> Result<()>
pub fn rebuild_doc_edges(&self, doc_id: &str) -> Result<()>
spec/graph §3.4: recompute one document’s doc_edges from its open
edges.
Sourcepub fn rebuild_sections(&self, doc_id: &str) -> Result<()>
pub fn rebuild_sections(&self, doc_id: &str) -> Result<()>
§4.5: rebuild sections for one document.
Sourcepub fn rebuild_index(&self, target: RebuildTarget) -> Result<()>
pub fn rebuild_index(&self, target: RebuildTarget) -> Result<()>
§7: recompute derived tables.
Sourcepub fn gc(&self, enabled: bool) -> Result<GcResult>
pub fn gc(&self, enabled: bool) -> Result<GcResult>
§7: mark-and-sweep garbage collection, flag-gated (off → no-op).
Sourcepub fn gc_dry_run(&self) -> Result<GcResult>
pub fn gc_dry_run(&self) -> Result<GcResult>
What Store::gc would sweep, without deleting (§8 I5).
Sourcepub fn sweep_pool(&self, ts: &str) -> Result<usize>
pub fn sweep_pool(&self, ts: &str) -> Result<usize>
§5.5: delete expired pool rows; returns how many.