Skip to main content

Store

Struct Store 

Source
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

Source

pub fn dry_run(&mut self) -> DryRun<'_>

The document operations as previews: see DryRun.

Source

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>").

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn sections_append(heading: &str, markdown: &str) -> Vec<Op>

§5 sections_append.

Source

pub fn docs_append(doc: &str, markdown: &str) -> Vec<Op>

§5 docs_append.

Source

pub fn sections_rename(&self, heading: &str, title: &str) -> Result<Vec<Op>>

§5 sections_rename: the level from the live raw’s leading # run.

Source

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.

Source

pub fn lists_insert_item(anchor: &str, at: At, markdown: &str) -> Vec<Op>

§5 lists_insert_item.

Source

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.

§5 links_retarget: the one-pair form of Store::links_repair.

§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

Source

pub fn load_mut_doc(&self, doc_id: &str) -> Result<Option<MutDoc>>

§1: load_mut_doc on this store.

Source

pub fn find_doc_by_ref(&self, repo_id: &str, r: &str) -> Result<Option<DocInfo>>

A live doc by id or path.

Source

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

Source

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).

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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

spec/search §1.3.

Source

pub fn build_embed_tasks(&self, repo_id: &str) -> Result<Vec<EmbedTask>>

spec/search §2.2: the embeddable blocks’ tasks, (path, ordinal) order.

Source

pub fn build_doc_embed_tasks(&self, repo_id: &str) -> Result<Vec<DocEmbedTask>>

spec/search §2.4: the live documents’ tasks, path order.

Source

pub fn embed_process( &self, tasks: &[EmbedTask], provider: &dyn EmbeddingProvider, ) -> Result<EmbedStats>

spec/search §2.3: embed the cache misses among tasks.

Source

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.

Source

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.

Source

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.

Source

pub fn cached_doc_vector( &self, task: &DocEmbedTask, model: &str, ) -> Result<Option<DocVectorRow>>

The fresh cached document vector for a task under model.

Source

pub fn stale_blocks( &self, tasks: &[EmbedTask], model: &str, ) -> Result<Vec<String>>

Block ids among tasks with no cached vector under model.

Source

pub fn stale_docs( &self, tasks: &[DocEmbedTask], model: &str, ) -> Result<Vec<String>>

Doc ids among tasks with no fresh cached vector under model.

Source

pub fn foreign_vector_count(&self, model: &str) -> Result<ForeignVectors>

spec/search §2.6: vectors under another model.

Source

pub fn prune_foreign_vectors(&self, model: &str) -> Result<ForeignVectors>

spec/search §2.6: delete vectors under another model.

Source

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).

spec/search §3 over blocks.

spec/search §3 over documents.

spec/search §4.

Source

pub fn resolve( &self, repo_id: &str, query: &str, vector: Option<QueryVector>, limit: Option<usize>, ) -> Result<Vec<ResolveHit>>

spec/search §4 resolve.

Source§

impl Store

Source

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.

Source

pub fn open_with_minter( path: impl AsRef<Path>, minter: Box<dyn IdMinter>, ) -> Result<Self>

Store::open with a replaceable minter (§2.2).

Source

pub fn open_in_memory() -> Result<Self>

A fresh in-memory store (tests, fixtures).

Source

pub fn open_in_memory_with_minter(minter: Box<dyn IdMinter>) -> Result<Self>

A fresh in-memory store with a replaceable minter.

Source

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).

Source

pub fn conn(&self) -> &Connection

The underlying connection.

Source

pub fn minter(&mut self) -> Mint<'_>

The store’s checking minter (§2.1) over its connection.

Source

pub fn mint(&mut self, prefix: &str) -> Result<String>

Mint an id with prefix (§2.1): never one in use.

Source

pub fn transaction(&self) -> Result<Transaction<'_>>

Begin a write transaction (one per commit, §1); rolls back on drop.

Source

pub fn create_repo(&mut self, slug: &str) -> Result<String>

Create a repo with slug (mints rp); returns its id.

Source

pub fn repo_by_slug(&self, slug: &str) -> Result<Option<String>>

The repo id for slug, if any.

Source

pub fn user_version(&self) -> Result<i64>

PRAGMA user_version.

Source

pub fn put_blob(&self, text: &str) -> Result<String>

Source

pub fn put_tree_node(&self, entries: &[TreeEntry]) -> Result<String>

Source

pub fn write_block_tree(&self, blocks: &[TreeInputBlock]) -> Result<String>

Source

pub fn new_commit(&mut self, input: &NewCommit<'_>) -> Result<(String, i64)>

writers::new_commit; returns (commit_id, seq).

Source

pub fn write_revision( &mut self, input: &NewRevision<'_>, ) -> Result<(String, i64)>

writers::write_revision; returns (rev_id, seq).

Source

pub fn reconstruct(&self, doc_id: &str) -> Result<Option<String>>

§6.1: the current bytes of a live doc; None when tombstoned or unknown.

Source

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.

Source

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.

Source

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.

Source

pub fn load_pool(&self, repo_id: &str, ts: &str) -> Result<Vec<PoolEntry>>

§5.1: the repo’s unexpired pool at ts.

Source

pub fn properties(&self, doc_id: &str) -> Result<Vec<PropertyRow>>

The document’s live properties rows (spec/properties §1), in write order.

Source

pub fn properties_grouped(&self, doc_id: &str) -> Result<Value>

spec/properties §5 grouped: {frontmatter, inline, computed} (the docs_read.properties shape).

Source

pub fn properties_merged(&self, doc_id: &str) -> Result<Value>

spec/properties §5 merged: {key: shape} over every row.

Source

pub fn rebuild_doc_edges(&self, doc_id: &str) -> Result<()>

spec/graph §3.4: recompute one document’s doc_edges from its open edges.

Source

pub fn rebuild_sections(&self, doc_id: &str) -> Result<()>

§4.5: rebuild sections for one document.

Source

pub fn rebuild_index(&self, target: RebuildTarget) -> Result<()>

§7: recompute derived tables.

Source

pub fn gc(&self, enabled: bool) -> Result<GcResult>

§7: mark-and-sweep garbage collection, flag-gated (off → no-op).

Source

pub fn gc_dry_run(&self) -> Result<GcResult>

What Store::gc would sweep, without deleting (§8 I5).

Source

pub fn sweep_pool(&self, ts: &str) -> Result<usize>

§5.5: delete expired pool rows; returns how many.

Source

pub fn close(self) -> Result<()>

Close the connection.

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !Send for Store

§

impl !Sync for Store

§

impl !UnwindSafe for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.