package index import ( "context" "errors" "slices" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "git.novox.be/novox/mesh-sdk/go/keys" ) // ErrAskClosed is what a kept call answers when its ask was closed while it was made again (design 47 G §351, §460, A-190): // what the ask served no longer stands, so the call stopped and is not said unanswered. var ErrAskClosed = errors.New("the ask is closed: what it served no longer stands") // SeedEntryHeld says the newest trunk revision still holds the entry of module at the fingerprint fp, the candidate the // seed asks steps for (A-190). func (ix *Indexer) SeedEntryHeld(ctx context.Context, module, fp string) (bool, error) { if ctx.Err() != nil || ix.Revisions == nil { return false, ctx.Err() } _, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch) if err != nil || !found { return false, err } return slices.ContainsFunc(entries, func(e meshcatalog.CatalogEntry) bool { return e.Module == module && e.Fp == fp }), nil } // ModuleInNewestView says module is among the entries of the newest trunk revision, the view the versions are filled for (A-190). func (ix *Indexer) ModuleInNewestView(ctx context.Context, module string) (bool, error) { if ctx.Err() != nil || ix.Revisions == nil { return false, ctx.Err() } _, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch) if err != nil || !found { return false, err } return slices.ContainsFunc(entries, func(e meshcatalog.CatalogEntry) bool { return e.Module == module }), nil } // BranchWatched says branch (as the source's key names it, escaped; empty asks the list of every branch) is watched: the // trunk always, another branch while a registration names it (A-190). With no registry, every branch is. func (ix *Indexer) BranchWatched(ctx context.Context, branch string) (bool, error) { if ctx.Err() != nil { return false, nil } if isTrunkBranch(branch) || ix.Registry == nil || ix.Registry.Registrations == nil { return true, nil } name, err := keys.UnescapeName(branch) if err != nil { return false, nil } regs, err := ix.Registry.RegistrationsAnswer(ctx, meshcatalog.RegistrationsInput{}) if err != nil { return false, err } for _, r := range regs.Registrations { if slices.Contains(r.Branches, name) { return true, nil } } return false, nil }