Documentation
¶
Index ¶
- Constants
- func DefaultSerializers() map[string]Serializer
- func IsGitInstalled() bool
- func MarshalCSVValue(v interface{}) string
- func ParseDocument(r io.Reader, ext, metadataKey string) (*core.Document, error)
- func SerializeDocument(doc core.Document, ext, metadataKey string) ([]byte, error)
- func UnmarshalCSVValue(val string) interface{}
- type CSVSerializer
- type Config
- type JSONSerializer
- type MarkdownSerializer
- 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) Reconcile(ctx context.Context) ([]core.Event, error)
- func (r *Repository) RegisterSerializer(ext string, s Serializer)
- func (r *Repository) Save(ctx context.Context, doc core.Document) error
- func (r *Repository) Sync(ctx context.Context) error
- func (r *Repository) Watch(ctx context.Context, pattern string) (<-chan core.Event, error)
- type Serializer
- 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
- type YAMLSerializer
Constants ¶
const (
// TempFilePrefix is the prefix used for temporary atomic write files.
TempFilePrefix = "loam-tmp-"
)
Variables ¶
This section is empty.
Functions ¶
func DefaultSerializers ¶ added in v0.10.0
func DefaultSerializers() map[string]Serializer
DefaultSerializers returns the standard set of serializers.
func IsGitInstalled ¶
func IsGitInstalled() bool
IsGitInstalled checks if git is available in the system path.
func MarshalCSVValue ¶ added in v0.10.0
func MarshalCSVValue(v interface{}) string
MarshalCSVValue converts a value to a string, using JSON for complex types (Map, Slice).
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". DEPRECATED: Use Serializer interface instead. This is kept briefly or should be removed if no external consumers. Refactoring: We will bridge this to use DefaultSerializers to maintain signature compat if needed, OR just remove it if it's internal package. It is Exported. To be safe, let's reimplement it using the new registry.
func SerializeDocument ¶ added in v0.8.4
SerializeDocument converts a Document to bytes based on extension. Exposed for reuse if needed. DEPRECATED: Use Serializer interface instead.
func UnmarshalCSVValue ¶ added in v0.10.0
func UnmarshalCSVValue(val string) interface{}
UnmarshalCSVValue attempts to parse a string as JSON if it looks like a Map or Slice. Otherwise returns the string as is.
CAVEAT: This uses a heuristic (starts/ends with {} or []). It is possible for a raw string that happens to be valid JSON (e.g. "{foo}") to be interpreted as an object. Use with caution if your domain allows strings that mimic JSON structure.
Types ¶
type CSVSerializer ¶ added in v0.10.0
type CSVSerializer struct{}
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 JSONSerializer ¶ added in v0.10.0
type JSONSerializer struct {
// Strict enables strict number parsing (as json.Number) to avoid precision loss.
Strict bool
}
JSONSerializer handles reading and writing JSON files.
func NewJSONSerializer ¶ added in v0.10.2
func NewJSONSerializer(strict bool) *JSONSerializer
NewJSONSerializer creates a new JSON serializer. Optional strict mode prevents float64 conversion for large integers.
type MarkdownSerializer ¶ added in v0.10.0
type MarkdownSerializer struct{}
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. It uses Reconcile to ensure the cache is up-to-date and then returns the cached state.
func (*Repository) Reconcile ¶ added in v0.9.0
Reconcile implements core.Reconcilable. It detects changes made while the service was offline by comparing the current state with the persistent cache/index.
func (*Repository) RegisterSerializer ¶ added in v0.10.0
func (r *Repository) RegisterSerializer(ext string, s Serializer)
RegisterSerializer adds or overrides a serializer for a specific extension.
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.
func (*Repository) Sync ¶
func (r *Repository) Sync(ctx context.Context) error
Sync synchronizes the repository with its remote.
func (*Repository) Watch ¶ added in v0.9.0
Watch implements core.Watchable.
Caveats:
- Recursive Monitoring on Linux (inotify): New directories created AFTER the watch starts might NOT be monitored automatically depending on the fsnotify implementation and OS limits. Loam currently does not implement dynamic hierarchical watching for inotify.
- OS Limits: Large repositories may hit file descriptor limits (inotify limits).
- Debouncing: Events are debounced by 50ms. Rapid atomic writes (Create+Modify) are merged.
type Serializer ¶ added in v0.10.0
type Serializer interface {
// Parse reads from r and returns a Document.
Parse(r io.Reader, metadataKey string) (*core.Document, error)
// Serialize converts the Document to bytes.
Serialize(doc core.Document, metadataKey string) ([]byte, error)
}
Serializer defines how to read and write a specific file format.
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.
type YAMLSerializer ¶ added in v0.10.0
type YAMLSerializer struct{}