The numbering from before G goes (design 47 H §756, G §372): the builder keeps no state versions, marks no numbered entry on a registry seat's word and arms no numbered version's publish bound; the publishes' findings and the reservations still hear the same events (DQ-11), and a reserved version's bound is the reservation's (DQ-10). builder_versions keeps answering, from the reservations alone (DMC-5): what the seat mesh-builds' reserved answers for a name and, with a version and a digest, whether that version is reserved or released with that digest. Builds: design 47 H §756, G §372, G §381, H2 H-A-532 (DMC-5, DQ-10, DQ-11), spec 29, 41, 48
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
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)
|
|
}
|