diff --git a/go/buscalls/buscalls.go b/go/buscalls/buscalls.go index 45a818b..3282903 100644 --- a/go/buscalls/buscalls.go +++ b/go/buscalls/buscalls.go @@ -10,6 +10,7 @@ package buscalls import ( "encoding/json" + "strings" "time" ) @@ -286,10 +287,18 @@ type QueryRequest struct { Limit int `json:"limit,omitempty"` } -// IndexEntry is one entry of an index. +// IndexEntry is the value of one key of a declared index (IndexKey): the instance it points at, and the sequence of +// the operation it was written from. The owner's watcher and the tool runner's reindex both write it so. type IndexEntry struct { - Key string `json:"key"` - Value json.RawMessage `json:"value"` + Instance string `json:"instance"` + Sequence uint64 `json:"sequence"` +} + +// IndexKey is the key of an instance in a declared index: the values of the index's fields, in its order, joined by +// ".", then the instance's path with each "/" written "." (`17950.listing.a17`). The owner's watcher and the tool +// runner's reindex both write it, so a reindex leaves the index as the watcher keeps it. +func IndexKey(fields []string, instance string) string { + return strings.Join(append(append([]string{}, fields...), strings.ReplaceAll(instance, "/", ".")), ".") } // QueryAnswer is query's answer. diff --git a/go/packages_list_test.go b/go/packages_list_test.go index 4912c0a..ee965ae 100644 --- a/go/packages_list_test.go +++ b/go/packages_list_test.go @@ -110,6 +110,15 @@ func TestMeshSDKHoldsOnlyWhatEveryModuleShares(t *testing.T) { if buscalls.MetaCall != "mesh/call" { t.Errorf("the tool call's id is handed under %q, not mesh/call", buscalls.MetaCall) } + // 1966/AC5: an index's key is its fields' values, then the instance's path, joined by "."; its entry names the + // instance and the sequence. + if k := buscalls.IndexKey([]string{"17950", "volvo"}, "listing/a17"); k != "17950.volvo.listing.a17" { + t.Errorf("an index key is %q", k) + } + entry, _ := json.Marshal(buscalls.IndexEntry{Instance: "listing/a17", Sequence: 3}) + if string(entry) != `{"instance":"listing/a17","sequence":3}` { + t.Errorf("an index entry is %s", entry) + } // 1966/AC5: an apply naming the tool call it serves, and its answer with the state behind, round-trip. for _, c := range []struct { name string