diff --git a/events.go b/events.go index 6877f22..b054c3f 100644 --- a/events.go +++ b/events.go @@ -117,9 +117,7 @@ func (storeInstance *Store) Unwatch(group string, events <-chan Event) { // OnChange registers a synchronous mutation callback. // Usage example: `events := make(chan store.Event, 1); unregister := storeInstance.OnChange(func(event store.Event) { events <- event }); defer unregister()` -// Usage example: `unregister := storeInstance.OnChange("config", func(key, value string) { fmt.Println(key, value) })` -func (storeInstance *Store) OnChange(arguments ...any) func() { - callback := onChangeCallback(arguments) +func (storeInstance *Store) OnChange(callback func(Event)) func() { if callback == nil { return func() {} } @@ -147,39 +145,6 @@ func (storeInstance *Store) OnChange(arguments ...any) func() { } } -func onChangeCallback(arguments []any) func(Event) { - switch len(arguments) { - case 0: - return nil - case 1: - if arguments[0] == nil { - return nil - } - callback, ok := arguments[0].(func(Event)) - if !ok { - return nil - } - return callback - case 2: - group, ok := arguments[0].(string) - if !ok { - return nil - } - callback, ok := arguments[1].(func(string, string)) - if !ok || callback == nil { - return nil - } - return func(event Event) { - if event.Group != group { - return - } - callback(event.Key, event.Value) - } - default: - return nil - } -} - // notify(Event{Type: EventSet, Group: "config", Key: "colour", Value: "blue"}) // dispatches matching watchers and callbacks after a successful write. If a // watcher buffer is full, the event is dropped instead of blocking the writer. diff --git a/events_test.go b/events_test.go index add265e..b1f491c 100644 --- a/events_test.go +++ b/events_test.go @@ -148,22 +148,6 @@ func TestEvents_OnChange_Good_Fires(t *testing.T) { assert.Equal(t, EventDelete, events[1].Type) } -func TestEvents_OnChange_Good_GroupFilter(t *testing.T) { - storeInstance, _ := New(":memory:") - defer storeInstance.Close() - - var calls []string - unregister := storeInstance.OnChange("config", func(key, value string) { - calls = append(calls, key+"="+value) - }) - defer unregister() - - require.NoError(t, storeInstance.Set("config", "theme", "dark")) - require.NoError(t, storeInstance.Set("other", "theme", "light")) - - assert.Equal(t, []string{"theme=dark"}, calls) -} - func TestEvents_Watch_Good_BufferDrops(t *testing.T) { storeInstance, _ := New(":memory:") defer storeInstance.Close() diff --git a/scope.go b/scope.go index 664350f..5ef1e30 100644 --- a/scope.go +++ b/scope.go @@ -98,12 +98,6 @@ func (scopedStore *ScopedStore) Get(arguments ...string) (string, error) { return scopedStore.storeInstance.Get(scopedStore.namespacedGroup(group), key) } -// GetFrom reads a key from an explicit namespaced group. -// Usage example: `colourValue, err := scopedStore.GetFrom("config", "colour")` -func (scopedStore *ScopedStore) GetFrom(group, key string) (string, error) { - return scopedStore.Get(group, key) -} - // Usage example: `if err := scopedStore.Set("colour", "blue"); err != nil { return }` // Usage example: `if err := scopedStore.Set("config", "colour", "blue"); err != nil { return }` func (scopedStore *ScopedStore) Set(arguments ...string) error { @@ -117,12 +111,6 @@ func (scopedStore *ScopedStore) Set(arguments ...string) error { return scopedStore.storeInstance.Set(scopedStore.namespacedGroup(group), key, value) } -// SetIn writes a key to an explicit namespaced group. -// Usage example: `if err := scopedStore.SetIn("config", "colour", "blue"); err != nil { return }` -func (scopedStore *ScopedStore) SetIn(group, key, value string) error { - return scopedStore.Set(group, key, value) -} - // Usage example: `if err := scopedStore.SetWithTTL("sessions", "token", "abc123", time.Hour); err != nil { return }` func (scopedStore *ScopedStore) SetWithTTL(group, key, value string, timeToLive time.Duration) error { if err := scopedStore.checkQuota("store.ScopedStore.SetWithTTL", group, key); err != nil { @@ -151,11 +139,6 @@ func (scopedStore *ScopedStore) All(group string) iter.Seq2[KeyValue, error] { return scopedStore.storeInstance.All(scopedStore.namespacedGroup(group)) } -// Usage example: `for entry, err := range scopedStore.AllSeq("config") { if err != nil { break }; fmt.Println(entry.Key, entry.Value) }` -func (scopedStore *ScopedStore) AllSeq(group string) iter.Seq2[KeyValue, error] { - return scopedStore.All(group) -} - // Usage example: `keyCount, err := scopedStore.Count("config")` func (scopedStore *ScopedStore) Count(group string) (int, error) { return scopedStore.storeInstance.Count(scopedStore.namespacedGroup(group)) diff --git a/scope_test.go b/scope_test.go index 8cbebcc..e3a8bfc 100644 --- a/scope_test.go +++ b/scope_test.go @@ -134,18 +134,6 @@ func TestScope_ScopedStore_Good_DefaultGroupHelpers(t *testing.T) { assert.Equal(t, "dark", rawValue) } -func TestScope_ScopedStore_Good_SetInGetFrom(t *testing.T) { - storeInstance, _ := New(":memory:") - defer storeInstance.Close() - - scopedStore := mustScoped(t, storeInstance, "tenant-a") - require.NoError(t, scopedStore.SetIn("config", "theme", "dark")) - - value, err := scopedStore.GetFrom("config", "theme") - require.NoError(t, err) - assert.Equal(t, "dark", value) -} - func TestScope_ScopedStore_Good_PrefixedInUnderlyingStore(t *testing.T) { storeInstance, _ := New(":memory:") defer storeInstance.Close() diff --git a/store.go b/store.go index 3dbf59d..9a57f73 100644 --- a/store.go +++ b/store.go @@ -276,11 +276,6 @@ func (storeInstance *Store) All(group string) iter.Seq2[KeyValue, error] { } } -// Usage example: `for entry, err := range storeInstance.AllSeq("config") { if err != nil { break }; fmt.Println(entry.Key, entry.Value) }` -func (storeInstance *Store) AllSeq(group string) iter.Seq2[KeyValue, error] { - return storeInstance.All(group) -} - // Usage example: `parts, err := storeInstance.GetSplit("config", "hosts", ","); if err != nil { return }; for part := range parts { fmt.Println(part) }` func (storeInstance *Store) GetSplit(group, key, separator string) (iter.Seq[string], error) { value, err := storeInstance.Get(group, key) diff --git a/store_test.go b/store_test.go index 88c48c7..03b0c9f 100644 --- a/store_test.go +++ b/store_test.go @@ -382,22 +382,6 @@ func TestStore_All_Good_SortedByKey(t *testing.T) { assert.Equal(t, []string{"alpha", "bravo", "charlie"}, keys) } -func TestStore_AllSeq_Good_Alias(t *testing.T) { - storeInstance, _ := New(":memory:") - defer storeInstance.Close() - - require.NoError(t, storeInstance.Set("g", "alpha", "1")) - require.NoError(t, storeInstance.Set("g", "bravo", "2")) - - var keys []string - for entry, err := range storeInstance.AllSeq("g") { - require.NoError(t, err) - keys = append(keys, entry.Key) - } - - assert.Equal(t, []string{"alpha", "bravo"}, keys) -} - func TestStore_All_Bad_ClosedStore(t *testing.T) { storeInstance, _ := New(":memory:") storeInstance.Close()