package buscompose import ( "slices" "strings" "git.novox.be/novox/mesh-sdk/go/keys" "git.novox.be/novox/mesh-sdk/go/seatdef" ) // **A held call's end is heard by its caller alone** (design 47 G ยง677; lead answer A-264): a holder says the end of a call of // a marked verb on its seat's event `gated-ended`, subject `mesh.seat..event.gated-ended..`, `` the // account the bus proved escaped as a key's name is, kept last per subject for a day in the stream SEAT__gated-ended // (KeptEventsOf, from the definition seatdef.Resolve gives). The caller is granted hearing `gated-ended..>` and no other // caller's, from its invokes of the marked verb by name; it reads the stream through an ordered consumer filtered to its own // subjects (mesh-sdk process awaitGated), made for the read. A process that answers a marked verb says the event to any caller. // gatedEndedGrants are the grants of the principal user from the marked verbs (`seat:.`) it invokes by name and // those it answers. func gatedEndedGrants(user string, marked, invokes, answers []string) (pub, sub []string) { caller := keys.EscapeName(user) if user == "" { return nil, nil } var heard, said []string for _, v := range marked { seat, _, ok := strings.Cut(strings.TrimPrefix(v, "seat:"), ".") if !ok || !safeSubject.MatchString(seat) { continue } if slices.Contains(invokes, v) { heard = append(heard, seat) } if slices.Contains(answers, v) { said = append(said, seat) } } for _, seat := range unique(heard) { stream := seatdef.KeptStream(seat, seatdef.Message{Name: seatdef.GatedEndedEvent}) own := GatedEndedSubject(seat, caller) + ".>" sub = append(sub, own) pub = append(pub, "$JS.API.STREAM.INFO."+stream, "$JS.API.CONSUMER.CREATE."+stream+".*."+own, "$JS.API.CONSUMER.MSG.NEXT."+stream+".*", "$JS.API.CONSUMER.INFO."+stream+".*", "$JS.API.CONSUMER.DELETE."+stream+".*") } for _, seat := range unique(said) { pub = append(pub, GatedEndedSubject(seat, "*")+".*") } return pub, sub } // GatedEndedSubject is the subject of the seat's gated-ended for one caller, its escaped name (keys.EscapeName) or `*`. func GatedEndedSubject(seat, caller string) string { return seatdef.EventSubject(seat, seatdef.GatedEndedEvent) + "." + caller }