store

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

The store's own failures — the mechanical ones a filesystem can produce. The document plane's contract errors (missing, precondition, exists, path, syntax) belong to the document package, because a client port must be able to return the same ones.

The filesystem mechanics behind the embedded port: reading and parsing a stored document, checking a write's precondition, and landing bytes atomically inside the confined root.

Package store is the confined document store of the sheet API's document plane: .tsvt files under one operator-fixed root, read and replaced through os.Root so no path can escape, every write atomic (temp + rename), every mutation revision-checked, and every stored byte the engine's canonical serialization. The store never evaluates an expression — parsing for canonicalization and reference rewriting only.

Index

Constants

View Source
const (
	// ErrParse is a stored document that no longer parses — corruption or an
	// out-of-band edit, never something a request did.
	ErrParse errs.Const = "stored document does not parse"
	// ErrRead is a document that exists but could not be read.
	ErrRead errs.Const = "failed to read document"
	// ErrRootOpen is a document root that cannot be opened for confinement.
	ErrRootOpen errs.Const = "document root cannot be opened"
	// ErrWrite is a write that did not land; the previous document survives.
	ErrWrite errs.Const = "failed to write document"
)

Keep these constants sorted alphabetically.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applied

type Applied = document.Applied

The document vocabulary this store speaks; the contract lives in the document package so a caller matches one set of types and errors whether it holds this embedded store or a client over HTTP.

type Created

type Created = document.Created

The document vocabulary this store speaks; the contract lives in the document package so a caller matches one set of types and errors whether it holds this embedded store or a client over HTTP.

type DocPath

type DocPath = document.DocPath

The document vocabulary this store speaks; the contract lives in the document package so a caller matches one set of types and errors whether it holds this embedded store or a client over HTTP.

type Expect

type Expect = document.Expect

The document vocabulary this store speaks; the contract lives in the document package so a caller matches one set of types and errors whether it holds this embedded store or a client over HTTP.

type RootDir

type RootDir string

RootDir is the operator-fixed directory a store confines itself to.

type Snapshot

type Snapshot = document.Snapshot

The document vocabulary this store speaks; the contract lives in the document package so a caller matches one set of types and errors whether it holds this embedded store or a client over HTTP.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store serves and mutates the documents under one root directory.

Pointer receivers are necessary here: the store wraps an os.Root handle and a mutex serializing check-and-set mutations, neither of which may be copied.

func Open

func Open(dir RootDir, limits tsvsheet.Limits) (*Store, error)

Open confines a store to the directory at dir.

func (*Store) Apply

func (s *Store) Apply(
	_ context.Context,
	p DocPath,
	batch tsvsheet.Edits,
	expect tsvsheet.RevisionHex,
) (Applied, error)

Apply folds the op batch over the document at p, which must currently have revision expect; the result is persisted atomically and both states returned. Any refusal — stale revision, in-band base conflict, refused op — leaves the file untouched.

func (*Store) Delete

func (s *Store) Delete(_ context.Context, p DocPath, expect tsvsheet.RevisionHex) error

Delete removes the document at p, which must currently have revision expect.

func (*Store) Get

func (s *Store) Get(_ context.Context, p DocPath) (Snapshot, error)

Get reads the document at p, canonicalized: the returned text is the engine's serialization of the stored file, and the revision addresses those canonical bytes.

func (*Store) Put

func (s *Store) Put(_ context.Context, p DocPath, body []byte, expect Expect) (Snapshot, Created, error)

Put replaces (or, with ExpectAbsent, creates) the document at p from body, storing the canonical serialization. It reports whether the document was created.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL