Documentation
¶
Index ¶
- Constants
- func AppendFooter(msg string) string
- func FindRoot(startDir string) (string, error)
- func FormatChangeReason(ctype, scope, subject, body string) string
- func Init(uri string, opts ...Option) (core.Repository, error)
- func IsDevRun() bool
- func New(uri string, opts ...Option) (*core.Service, error)
- func ResolveVaultPath(userPath string, forceTemp bool) string
- func Sync(uri string, opts ...Option) error
- type Option
- func WithAdapter(name string) Option
- func WithAutoInit(auto bool) Option
- func WithContentExtraction(enabled bool) Option
- func WithDevSafety(enabled bool) Option
- func WithEventBuffer(size int) Option
- func WithForceTemp(force bool) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMarkdownBodyKey(key string) Option
- func WithMustExist(must bool) Option
- func WithReadOnly(enabled bool) Option
- func WithRepository(repo core.Repository) Option
- func WithSerializer(ext string, s any) Option
- func WithStrict(strict bool) Option
- func WithSystemDir(name string) Option
- func WithVersioning(enabled bool) Option
- func WithWatcherErrorHandler(fn func(error)) Option
Constants ¶
const ( CommitTypeFeat = "feat" CommitTypeFix = "fix" CommitTypeDocs = "docs" CommitTypeStyle = "style" CommitTypeRefactor = "refactor" CommitTypePerf = "perf" CommitTypeTest = "test" CommitTypeChore = "chore" )
CommitType constants for semantic commits
Variables ¶
This section is empty.
Functions ¶
func AppendFooter ¶
AppendFooter appends the Loam footer to an arbitrary message if not present. Used for free-form -m "msg" commits.
func FindRoot ¶ added in v0.8.1
FindRoot recursively looks upwards for a vault root indicator. Indicators are: .loam directory, .git directory, or loam.json file. If found, returns the absolute path to the root. If not found (reached root of FS), returns the startDir (or error?). For now, if not found, we return an empty string to indicate "no specific root found".
func FormatChangeReason ¶
FormatChangeReason builds a Conventional Commit message (used as Change Reason). logic:
<type>(<scope>): <subject> <body> Powered-by: Loam
func Init ¶
func Init(uri string, opts ...Option) (core.Repository, error)
Init initializes a new Loam vault based on the provided configuration. The 'uri' argument is adapter-specific (e.g., file path for 'fs', connection string for others).
It returns the configured core.Repository.
func IsDevRun ¶
func IsDevRun() bool
IsDevRun checks if the current process is running via `go run` or `go test`. It relies on the fact that these commands build binaries in temporary directories.
func New ¶
svc, err := loam.New("./path/to/vault", loam.WithVersioning(false)) The URI argument is adapter-specific (e.g., file path for 'fs', connection string for others).
func ResolveVaultPath ¶
ResolveVaultPath determines the actual path for the vault based on safety rules. If isDev is true (or forced), it re-roots the path into a temporary directory to avoid polluting the user's workspace/host repo.
Types ¶
type Option ¶
type Option func(*options)
Option defines a functional option for configuring Loam.
func WithAdapter ¶
WithAdapter allows specifying the storage adapter to use by name (e.g. "fs"). Defaults to "fs".
func WithAutoInit ¶
WithAutoInit enables automatic initialization of the vault (creates directory and git init).
func WithContentExtraction ¶ added in v0.10.8
WithContentExtraction controls whether JSON/YAML/CSV content fields are extracted into Document.Content. When disabled, the file payload is preserved 1:1 in Metadata.
func WithDevSafety ¶ added in v0.10.6
WithDevSafety controls the "Sandbox" safety mechanism when running via `go run`. By default (true), Loam forces a temporary directory to prevent accidental data loss. Setting this to false allows operating on the real filesystem even during `go run`.
CAUTION: Only disable this if you are sure your code is safe.
func WithEventBuffer ¶ added in v0.9.0
WithEventBuffer allows specifying the size of the event broker buffer. Zero means default (100).
func WithForceTemp ¶
WithForceTemp forces the use of a temporary directory (useful for testing).
func WithLogger ¶
WithLogger sets the logger for the service.
func WithMarkdownBodyKey ¶ added in v0.10.8
WithMarkdownBodyKey sets the metadata key used to store Markdown body when content extraction is disabled. Defaults to "body".
func WithMustExist ¶
WithMustExist ensures the vault directory must already exist.
func WithReadOnly ¶ added in v0.10.6
WithReadOnly enables read-only mode. In this mode: 1. Write operations (Save, Delete, Sync) return ErrReadOnly. 2. Initialization (Mkdir, Git Init) is skipped. 3. Cache updates are not persisted to disk. 4. Dev Safety Lock (go run temp dir) is BYPASSED (uses real path).
func WithRepository ¶
func WithRepository(repo core.Repository) Option
WithRepository allows injecting a custom storage adapter (e.g. mock, s3). If provided, the default filesystem adapter will be skipped.
func WithSerializer ¶ added in v0.10.2
WithSerializer registers a custom serializer for a specific extension. The serializer 's' must implement the adapter's Serializer interface (e.g. fs.Serializer). Using 'any' keeps the public API clean, but validation happens at runtime during Init.
func WithStrict ¶ added in v0.10.4
WithStrict enables strict mode for all default serializers. When enabled, numbers in JSON/YAML/Markdown will be parsed as json.Number (string based) to preserve precision of large integers.
func WithSystemDir ¶ added in v0.6.0
WithSystemDir allows specifying the hidden directory name (e.g. ".loam"). Defaults to ".loam" if not set (handled by adapter).
func WithVersioning ¶
WithVersioning enables or disables version control (e.g. Git). By default, versioning is enabled. Passing false will disable versioning (no-versioning mode).
func WithWatcherErrorHandler ¶ added in v0.10.5
WithWatcherErrorHandler registers a callback to handle errors occurring during the Watch loop. This allows applications to log or react to runtime watcher failures (e.g. permission denied) which are otherwise only logged.