From 828b55960b15ee15f4de11346fb6667ca66a7344 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 08:54:19 +0000 Subject: [PATCH] refactor(store): clarify constructor naming and docs Prefer struct-literal configuration in package docs and rename internal constructor helpers for clarity. Co-Authored-By: Virgil --- doc.go | 3 +++ store.go | 12 +++++++----- workspace.go | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/doc.go b/doc.go index c1d18f4..b02d930 100644 --- a/doc.go +++ b/doc.go @@ -2,6 +2,9 @@ // namespace isolation, quota enforcement, reactive change notifications, // workspace journalling, and explicit orphan recovery. // +// Prefer `store.NewConfigured(store.StoreConfig{...})` when constructing a +// store from an agent-written configuration literal. +// // Usage example: // // func main() { diff --git a/store.go b/store.go index 93b1d35..cc5dfa2 100644 --- a/store.go +++ b/store.go @@ -30,6 +30,8 @@ const ( ) // Usage example: `storeOptions := []store.StoreOption{store.WithJournal("http://127.0.0.1:8086", "core", "events")}` +// Prefer `store.NewConfigured(store.StoreConfig{...})` when the configuration +// is already known as a struct literal. type StoreOption func(*StoreConfig) type journalConfiguration struct { @@ -148,11 +150,11 @@ func WithPurgeInterval(interval time.Duration) StoreOption { // Usage example: `storeInstance, err := store.NewConfigured(store.StoreConfig{DatabasePath: ":memory:", Journal: store.JournalConfiguration{EndpointURL: "http://127.0.0.1:8086", Organisation: "core", BucketName: "events"}, PurgeInterval: 20 * time.Millisecond})` func NewConfigured(config StoreConfig) (*Store, error) { - return newStoreFromConfig("store.NewConfigured", config) + return openConfiguredStore("store.NewConfigured", config) } -func newStoreFromConfig(operation string, config StoreConfig) (*Store, error) { - storeInstance, err := openStore(operation, config.DatabasePath) +func openConfiguredStore(operation string, config StoreConfig) (*Store, error) { + storeInstance, err := openSQLiteStore(operation, config.DatabasePath) if err != nil { return nil, err } @@ -183,10 +185,10 @@ func New(databasePath string, options ...StoreOption) (*Store, error) { option(&config) } } - return newStoreFromConfig("store.New", config) + return openConfiguredStore("store.New", config) } -func openStore(operation, databasePath string) (*Store, error) { +func openSQLiteStore(operation, databasePath string) (*Store, error) { sqliteDatabase, err := sql.Open("sqlite", databasePath) if err != nil { return nil, core.E(operation, "open database", err) diff --git a/workspace.go b/workspace.go index e6b46b6..0e0d2f5 100644 --- a/workspace.go +++ b/workspace.go @@ -90,8 +90,8 @@ func (workspace *Workspace) ensureReady(operation string) error { } // Usage example: `workspace, err := storeInstance.NewWorkspace("scroll-session-2026-03-30")` -// The backing file lives at `.core/state/scroll-session-2026-03-30.duckdb` and -// is removed when the workspace is committed or discarded. +// The workspace file lives at `.core/state/scroll-session-2026-03-30.duckdb` +// and is removed when the workspace is committed or discarded. func (storeInstance *Store) NewWorkspace(name string) (*Workspace, error) { if err := storeInstance.ensureReady("store.NewWorkspace"); err != nil { return nil, err -- 2.45.3