Skip to content

SourceStore

The port that keeps a document's source as it was asked, so it can be read again.

Port: SourceStore, declared in indx_interfaces.protocols over StoredSource in indx_interfaces.store (ADR-0081).

A StoredSource is a digest, the Source a request named, and an optional expiry. An inline source carries its bytes as base64. A URI source is the URI with its checksum set to the digest. Reading a document again is an ordinary request built from the stored value.

class SourceStore(Protocol):
def put(self, owner: OwnerId, source: StoredSource) -> None: ...
def get(self, owner: OwnerId, digest: SourceDigest) -> StoredSource | None: ...
def list(self, owner: OwnerId) -> tuple[SourceDigest, ...]: ...
def delete(self, owner: OwnerId, digest: SourceDigest) -> bool: ...
def purge(self, now: datetime) -> int: ...

A port of its own rather than a field on StoredDocument, because every Use screen reads that record and none wants the bytes back. Two owners use it. A visitor’s source expires with the kept document. The installation’s copy, taken when a document joins a dataset, has no expiry and goes when no dataset holds the digest. Three backends ship: memory, sqlite and postgres, named by INDX_SOURCE_STORE. Unset, nothing is retained.

  • Owner. Every method but purge takes an OwnerId first, and nothing crosses owners.
  • Identity. Within an owner, a source is its digest; put replaces the one with the same digest.
  • Expiry. get and list never return a source past its expires_at. One with no expires_at never expires, and purge leaves it.
  • Idempotence. delete of a digest that is not there is False.
  • Order. list returns the owner’s digests in order, without loading a source.

tests/unit/test_store_conformance.py holds every installed backend to these rules.