Documentation
¶
Index ¶
- func IsGitInstalled() bool
- func ParseDocument(r io.Reader, ext, metadataKey string) (*core.Document, error)
- func SerializeDocument(doc core.Document, ext, metadataKey string) ([]byte, error)
- type Config
- type Repository
- func (r *Repository) Begin(ctx context.Context) (core.Transaction, error)
- func (r *Repository) Delete(ctx context.Context, id string) error
- func (r *Repository) Get(ctx context.Context, id string) (core.Document, error)
- func (r *Repository) Initialize(ctx context.Context) error
- func (r *Repository) List(ctx context.Context) ([]core.Document, error)
- func (r *Repository) Save(ctx context.Context, doc core.Document) error
- func (r *Repository) Sync(ctx context.Context) error
- type Transaction
- func (t *Transaction) Commit(ctx context.Context, changeReason string) error
- func (t *Transaction) Delete(ctx context.Context, id string) error
- func (t *Transaction) Get(ctx context.Context, id string) (core.Document, error)
- func (t *Transaction) Rollback(ctx context.Context) error
- func (t *Transaction) Save(ctx context.Context, doc core.Document) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGitInstalled ¶
func IsGitInstalled() bool
IsGitInstalled checks if git is available in the system path.
func ParseDocument ¶ added in v0.8.4
ParseDocument parses raw content into a Core Document based on extension. Exposed for use by CLI "raw mode".
Types ¶
type Config ¶
type Config struct {
Path string
AutoInit bool
Gitless bool
MustExist bool
Logger *slog.Logger
SystemDir string // e.g. ".loam"
IDMap map[string]string // Map filename -> ID column name (e.g. "users.csv": "email"). User must ensure uniqueness of values in this column.
MetadataKey string // If set, metadata will be nested under this key in JSON/YAML (e.g. "meta" or "frontmatter"). Contents will be in "content" (unless empty).
}
Config holds the configuration for the filesystem repository.
type Repository ¶
type Repository struct {
Path string
// contains filtered or unexported fields
}
Repository implements core.Repository using the filesystem and Git.
func NewRepository ¶
func NewRepository(config Config) *Repository
NewRepository creates a new filesystem-backed repository.
func (*Repository) Begin ¶
func (r *Repository) Begin(ctx context.Context) (core.Transaction, error)
Begin starts a new transaction.
func (*Repository) Delete ¶
func (r *Repository) Delete(ctx context.Context, id string) error
Delete removes a document.
func (*Repository) Get ¶
Get retrieves a document from the filesystem.
Workflow:
- Try to open the file directly (handling extension logic).
- If file not found, check if it's a sub-document inside a Collection (e.g. row in CSV).
- Parse content based on file extension.
func (*Repository) Initialize ¶
func (r *Repository) Initialize(ctx context.Context) error
Initialize performs the necessary setup for the repository (mkdir, git init).
func (*Repository) List ¶
List scans the directory for all documents.
Strategy:
- Load existing Cache (metadata index) from disk.
- Walk the directory tree (skipping .git and system dirs).
- For each supported file: a. Check Cache Hit (based on mtime). If hit, use cached metadata (FAST). b. Cache Miss: Full Parse (Get). Update Cache.
- Save Cache back to disk.
func (*Repository) Save ¶
Save persists a document to the filesystem and commits it to Git. If the document belongs to a collection (e.g. CSV), it updates the specific row.
Workflow:
- Validate ID and determine extension strategy.
- Check if it's a "Collection Item" (e.g. inside a CSV) -> special handling.
- Create parent directories.
- Serialize content (Markdown/JSON/YAML) and write atomically to disk.
- (If Git enabled) 'git add' and 'git commit' with context metadata.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction implements core.Transaction for the filesystem.
func NewTransaction ¶
func NewTransaction(repo *Repository) *Transaction
NewTransaction creates a new transaction.
func (*Transaction) Commit ¶
func (t *Transaction) Commit(ctx context.Context, changeReason string) error
Commit applies all staged changes.
func (*Transaction) Delete ¶
func (t *Transaction) Delete(ctx context.Context, id string) error
Delete stages a document for deletion.