Documentation
¶
Index ¶
- Constants
- func AppendFooter(msg string) string
- 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 DocumentModel
- type Option
- func WithAdapter(name string) Option
- func WithAutoInit(auto bool) Option
- func WithForceTemp(force bool) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMustExist(must bool) Option
- func WithRepository(repo core.Repository) Option
- func WithSystemDir(name string) Option
- func WithVersioning(enabled bool) Option
- type TypedRepository
- func (r *TypedRepository[T]) Delete(ctx context.Context, id string) error
- func (r *TypedRepository[T]) Get(ctx context.Context, id string) (*DocumentModel[T], error)
- func (r *TypedRepository[T]) List(ctx context.Context) ([]*DocumentModel[T], error)
- func (r *TypedRepository[T]) Save(ctx context.Context, doc *DocumentModel[T]) error
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 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 DocumentModel ¶ added in v0.6.0
DocumentModel wraps the raw core.Document with a typed Metadata field. It is the generic equivalent of core.Document.
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 (git init).
func WithForceTemp ¶
WithForceTemp forces the use of a temporary directory (useful for testing).
func WithLogger ¶
WithLogger sets the logger for the service.
func WithMustExist ¶
WithMustExist ensures the vault directory must already exist.
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 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 (gitless = false). Passing false will enable gitless mode (gitless = true).
type TypedRepository ¶ added in v0.6.0
type TypedRepository[T any] struct { // contains filtered or unexported fields }
TypedRepository wraps a core.Repository to provide type-safe access. It acts as an Application Layer adapter, converting between raw maps and typed structs.
func NewTyped ¶ added in v0.6.0
func NewTyped[T any](repo core.Repository) *TypedRepository[T]
NewTyped creates a new type-safe repository wrapper. T is the type of the struct you want to store in the document metadata.
func (*TypedRepository[T]) Delete ¶ added in v0.6.0
func (r *TypedRepository[T]) Delete(ctx context.Context, id string) error
Delete removes a document by ID.
func (*TypedRepository[T]) Get ¶ added in v0.6.0
func (r *TypedRepository[T]) Get(ctx context.Context, id string) (*DocumentModel[T], error)
Get retrieves a document and unmarshals it into the typed struct.
func (*TypedRepository[T]) List ¶ added in v0.6.0
func (r *TypedRepository[T]) List(ctx context.Context) ([]*DocumentModel[T], error)
List returns all documents converted to the typed model.
func (*TypedRepository[T]) Save ¶ added in v0.6.0
func (r *TypedRepository[T]) Save(ctx context.Context, doc *DocumentModel[T]) error
Save persists a typed document. It marshals the generic Data field into the core.Document Metadata map.