soma_provider_core/registry/
snapshot.rs1use crate::{ProviderCatalog, ProviderValidationError};
2
3use super::{ProviderIndexes, RegisteredTool, RegistryFingerprint};
4
5#[derive(Clone)]
6pub struct RegistrySnapshot {
7 fingerprint: RegistryFingerprint,
8 catalogs: Vec<ProviderCatalog>,
9 indexes: ProviderIndexes,
10}
11
12impl RegistrySnapshot {
13 pub(super) fn build(
14 mut catalogs: Vec<ProviderCatalog>,
15 ) -> Result<Self, ProviderValidationError> {
16 catalogs.sort_by(|left, right| left.provider.name.cmp(&right.provider.name));
17 let indexes = ProviderIndexes::build(&catalogs)?;
18 let fingerprint = RegistryFingerprint::from_catalogs(&catalogs);
19 Ok(Self {
20 fingerprint,
21 catalogs,
22 indexes,
23 })
24 }
25
26 pub fn fingerprint(&self) -> &RegistryFingerprint {
27 &self.fingerprint
28 }
29
30 pub fn provider_count(&self) -> usize {
31 self.catalogs.len()
32 }
33
34 pub fn catalogs(&self) -> &[ProviderCatalog] {
35 &self.catalogs
36 }
37
38 pub fn tool(&self, action: &str) -> Option<&RegisteredTool> {
39 self.indexes.tool(action)
40 }
41
42 pub fn action_names(&self) -> impl Iterator<Item = &str> {
43 self.indexes.action_names()
44 }
45
46 pub fn route_action(&self, method: &str, path: &str) -> Option<&str> {
47 self.indexes.route_action(method, path)
48 }
49
50 pub fn cli_action(&self, command: &str) -> Option<&str> {
51 self.indexes.cli_action(command)
52 }
53
54 pub fn primitive_kind(&self, name: &str) -> Option<&str> {
55 self.indexes.primitive_kind(name)
56 }
57
58 pub fn rest_routes(&self) -> impl Iterator<Item = (&str, &str, &str)> {
59 self.indexes.rest_routes()
60 }
61
62 pub fn compiled_validator_count(&self) -> usize {
63 self.indexes.compiled_validator_count()
64 }
65}