package versions import ( "context" "errors" "strings" ) // AllFilter is the key filter of every version of every name: two tokens. const AllFilter = "*.*" // FilterMatches says whether key is under filter as the bus reads a key filter: token by token, a `*` any one token, so AllFilter // lists the two-token keys alone and never the index's three-token keys (H-A-269 (1)). func FilterMatches(filter, key string) bool { ft, kt := strings.Split(filter, "."), strings.Split(key, ".") if len(ft) != len(kt) { return false } for i := range ft { if ft[i] != "*" && ft[i] != kt[i] { return false } } return true } // ErrConflict is what a Store answers when a Create finds the key or an Update finds another revision. var ErrConflict = errors.New("the key exists or changed") // Store is the bucket: create and compare-and-set, as the builder's builds bucket (internal/build.Store). type Store interface { Get(ctx context.Context, key string) (value []byte, revision uint64, found bool, err error) Create(ctx context.Context, key string, value []byte) (uint64, error) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) // KeysOf are the keys under a filter (NameFilter, or AllFilter for every key). KeysOf(ctx context.Context, filter string) ([]string, error) }