store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applied

type Applied struct {
	Old Snapshot
	New Snapshot
}

Applied is the result of an op-batch application: the state folded from and the state produced.

type DocPath

type DocPath string

DocPath is a document's path relative to the store root. It must be clean, relative, and free of "!" (reserved by the HTTP binding's reference suffix).

type Expect

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

Expect is a mutation's precondition: a revision the document must currently have, or the requirement that it not exist.

func ExpectAbsent

func ExpectAbsent() Expect

ExpectAbsent requires the document to not exist (create).

func ExpectRev

func ExpectRev(rev tsvsheet.RevisionHex) Expect

ExpectRev requires the document to currently have revision rev.

type RootDir

type RootDir string

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

type Snapshot

type Snapshot struct {
	Doc  tsvsheet.Document
	Rev  tsvsheet.RevisionHex
	Text []byte
}

Snapshot is one document state: the parsed document, its canonical bytes, and their content address. Carrying the Document means no consumer ever reparses served text.

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(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(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(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(p DocPath, body []byte, expect Expect) (Snapshot, bool, 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