uni_query/procedures_plugin/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2026 Dragonscale Team
3
4//! Host-coupled built-in procedure plugins.
5//!
6//! These procedures depend on `uni-store` / `uni-algo` types that
7//! `uni-plugin-builtin` cannot reach without a layering inversion
8//! (it depends only on `uni-plugin`). They live here in `uni-query`
9//! because that's where the host dependencies converge.
10//!
11//! Registered alongside `BuiltinPlugin` and `ApocCorePlugin` from
12//! `uni::api::register_builtin_plugins`.
13//!
14//! Each submodule covers one namespace:
15//!
16//! - [`schema`] — `uni.schema.{labels, edgeTypes, relationshipTypes, indexes, constraints, labelInfo}`
17//! - [`vector`] / [`fts`] / [`search`] — `uni.vector.query`, `uni.fts.query`, `uni.search`
18//! - [`algo`] — `uni.algo.*` (32 algorithms via a single `AlgorithmProcedureAdapter`)
19
20use std::sync::Arc;
21
22use uni_algo::algo::AlgorithmRegistry;
23use uni_plugin::{PluginError, PluginRegistrar};
24
25pub mod algo;
26pub mod create;
27pub mod fts;
28pub mod graph;
29mod host_args;
30pub mod schema;
31pub mod search;
32pub mod sparse;
33pub mod vector;
34
35// Rust guideline compliant
36
37/// Construct a fresh [`uni_plugin::PluginRegistry`] pre-loaded with every
38/// host-coupled built-in procedure (uni.schema.*, uni.algo.*).
39///
40/// Useful for low-level test setups that bypass `Uni::build` and would
41/// otherwise see "Procedure not supported" errors for `uni.algo.*` /
42/// `uni.schema.*` calls now that those match arms in `procedure_call.rs`
43/// have been deleted in favor of plugin-path dispatch.
44///
45/// Panics on registration failure (only possible on duplicate qname,
46/// which the static built-in set never produces).
47#[must_use]
48pub fn default_host_plugin_registry() -> Arc<uni_plugin::PluginRegistry> {
49 use uni_plugin::{Capability, CapabilitySet, PluginId, PluginRegistrar};
50 let registry = Arc::new(uni_plugin::PluginRegistry::default());
51 let plugin_id = PluginId::new("uni");
52 let caps = CapabilitySet::from_iter_of([Capability::Procedure, Capability::ProcedureSchema]);
53 let mut r = PluginRegistrar::new(plugin_id, &caps, ®istry);
54 let algo_registry: Arc<AlgorithmRegistry> = Arc::new(AlgorithmRegistry::new());
55 register_into(&mut r, Some(&algo_registry))
56 .expect("default host plugin registration must succeed");
57 r.commit_to_registry()
58 .expect("default host plugin commit must succeed");
59 registry
60}
61
62/// Register every host-coupled built-in procedure into `r`.
63///
64/// `algo_registry` is the same `Arc<AlgorithmRegistry>` that the host
65/// wires into `GraphExecutionContext::with_algo_registry()`; pass `None`
66/// in test setups that do not need the `uni.algo.*` namespace.
67///
68/// # Errors
69///
70/// Returns [`PluginError::DuplicateRegistration`] if a procedure qname
71/// is already taken in the underlying registry.
72pub fn register_into(
73 r: &mut PluginRegistrar<'_>,
74 algo_registry: Option<&Arc<AlgorithmRegistry>>,
75) -> Result<(), PluginError> {
76 schema::register_into(r)?;
77 vector::register_into(r)?;
78 fts::register_into(r)?;
79 sparse::register_into(r)?;
80 search::register_into(r)?;
81 graph::register_into(r)?;
82 create::register_into(r)?;
83 if let Some(algo) = algo_registry {
84 algo::register_into(r, algo)?;
85 }
86 Ok(())
87}