[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/store/RFC.md fully. Find features d... #35
6 changed files with 1 additions and 102 deletions
37
events.go
37
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.
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
17
scope.go
17
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))
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
5
store.go
5
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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue