pub struct RegistryStore { /* private fields */ }Expand description
The live set, and the only way to change it.
§Examples
use protocol_droid::domain::registry::{Primitive, PrimitiveKind, Tool};
use protocol_droid::application::registry::RegistryStore;
let store = RegistryStore::new();
assert!(store.snapshot().is_blank());
let published = store.register(Primitive::from(
Tool::new("echo", r#"{"type":"object"}"#)?,
));
assert_eq!(published.changed(), [PrimitiveKind::Tool]);
assert_eq!(store.snapshot().len(PrimitiveKind::Tool), 1);Implementations§
Source§impl RegistryStore
impl RegistryStore
Sourcepub fn list_visible(
&self,
session: &AuthContext,
profile: &FeatureProfile,
kind: PrimitiveKind,
) -> Listing
pub fn list_visible( &self, session: &AuthContext, profile: &FeatureProfile, kind: PrimitiveKind, ) -> Listing
Every primitive of kind that session may see.
Takes an owned Arc<Snapshot> rather than a guard, so a caller that
goes on to build a response, or hand the primitives to a tool, is not
holding the store against a publish for the duration.
Sourcepub fn get_visible(
&self,
session: &AuthContext,
profile: &FeatureProfile,
kind: PrimitiveKind,
id: &str,
) -> Option<Arc<Registered>>
pub fn get_visible( &self, session: &AuthContext, profile: &FeatureProfile, kind: PrimitiveKind, id: &str, ) -> Option<Arc<Registered>>
One primitive, if session may see it.
A miss is None whether the primitive is absent or merely hidden, and
that is deliberate: telling a caller which would let a session probe
for the existence of a tool it cannot see by reading the difference
between a 404 and a 403. The server still logs the difference.
Source§impl RegistryStore
impl RegistryStore
Sourcepub fn with(snapshot: Snapshot) -> Self
pub fn with(snapshot: Snapshot) -> Self
A store seeded with a snapshot, at that snapshot’s generation.
Sourcepub fn snapshot(&self) -> Arc<Snapshot> ⓘ
pub fn snapshot(&self) -> Arc<Snapshot> ⓘ
The current snapshot, owned.
An Arc clone, not a borrow. The caller may hold it for as long as it
likes — across a publish, across a long-running tool — and no publish
waits on it.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
The current publish number.
Sourcepub fn register(&self, primitive: impl Into<Registered>) -> Published
pub fn register(&self, primitive: impl Into<Registered>) -> Published
Adds a primitive, replacing any primitive already filed under its id.
A replacement is one publish and one generation, not a removal followed by an add: a subscriber that hears about it twice has been told the tool went away and came back, which is a lie that costs a re-list.
The primitive is captured behind an Arc because Self::publish may
run its closure more than once, and a retry must be able to install the
same primitive without taking the first attempt’s copy of it. The
alternative is a clone per attempt, which on a contended registry means
deep-copying a tool’s schema on every retry.
Sourcepub fn unregister(&self, kind: PrimitiveKind, id: &PrimitiveId) -> Published
pub fn unregister(&self, kind: PrimitiveKind, id: &PrimitiveId) -> Published
Takes a primitive out of the set.
Removing something that is not there is not an error: the observable
state afterwards is the same either way, and a caller tearing down a
tool it may never have registered should not have to check first. The
returned Published reports is_noop, so a notification is still
suppressed.
Sourcepub fn apply(
&self,
primitives: impl IntoIterator<Item = Registered>,
) -> Published
pub fn apply( &self, primitives: impl IntoIterator<Item = Registered>, ) -> Published
Publishes several changes as one generation.
A batch is one publish rather than a sequence of them so that a
subscriber told about the result never observes a half-applied set.
That is the only reason this takes a slice: the alternative is a caller
looping over Self::register, and a reader racing the loop sees
generation N with the first change and N+2 with the last.