store

package
v0.66.16 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append added in v0.36.0

func Append(storePath, key, line string) error

Append appends a line to the file at key and commits it to the git history. A trailing newline is added if line does not already end with one. The file is created if it does not exist.

func CommitMessage

func CommitMessage(action, key string) string

CommitMessage builds a commit message for a store operation. The first line is "store: <action> <key>". If GRAITH_SESSION_ID is set, trailers are appended after a blank line.

func Get

func Get(storePath, key string) (string, error)

Get retrieves the body stored under key.

func Init

func Init(storePath string) error

Init initialises the document store at storePath. It creates the directory if it does not exist and sets up a bare git repository for versioning. Calling Init on an already-initialised store is a no-op.

func Put

func Put(storePath, key, body string) error

Put writes body to the store under key and commits it to the git history.

func Remove

func Remove(storePath, key string) error

Remove deletes the document at key from the store and commits the deletion. Empty parent directories up to the store root are cleaned up after removal.

func SharedStorePath added in v0.40.0

func SharedStorePath(dataDir string) string

SharedStorePath returns the on-disk directory for the shared document store. The shared store is not scoped to any repo.

func StorePath

func StorePath(dataDir, repoRoot string) string

StorePath returns the on-disk directory for the document store for a given repo. The path is <dataDir>/store/<reponame>-<hash> where reponame is the base name of repoRoot and hash is a 12-character deterministic hex string derived from repoRoot.

func ValidateKey

func ValidateKey(key string) error

ValidateKey returns an error if key is not a valid store key.

A valid key must:

  • be non-empty
  • not start with '/' or '-'
  • not contain "..", ".git", or "." path components
  • not contain control characters, NUL bytes, or backslashes
  • not contain git pathspec characters (*, ?, [, :)
  • not be "store.lock"

Types

type Entry

type Entry struct {
	Key       string    `json:"key"`
	UpdatedAt time.Time `json:"updated_at"`
}

Entry represents a document in the store.

func List

func List(storePath, prefix string) ([]Entry, error)

List returns all entries in the store, optionally filtered by prefix. If the prefix directory does not exist, an empty slice is returned (not an error). No locking is required for listing.

type StoreInfo

type StoreInfo struct {
	Name    string  `json:"name"`
	Path    string  `json:"path"`
	Entries []Entry `json:"entries,omitempty"`
}

StoreInfo describes a discovered store directory.

func ListStores

func ListStores(dataDir string) ([]StoreInfo, error)

ListStores enumerates all store directories under dataDir/store/. Each directory is named <reponame>-<hash>.

Jump to

Keyboard shortcuts

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