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 vector;
33
34// Rust guideline compliant
35
36/// Construct a fresh [`uni_plugin::PluginRegistry`] pre-loaded with every
37/// host-coupled built-in procedure (uni.schema.*, uni.algo.*).
38///
39/// Useful for low-level test setups that bypass `Uni::build` and would
40/// otherwise see "Procedure not supported" errors for `uni.algo.*` /
41/// `uni.schema.*` calls now that those match arms in `procedure_call.rs`
42/// have been deleted in favor of plugin-path dispatch.
43///
44/// Panics on registration failure (only possible on duplicate qname,
45/// which the static built-in set never produces).
46#[must_use]
47pub fn default_host_plugin_registry() -> Arc<uni_plugin::PluginRegistry> {
48 use uni_plugin::{Capability, CapabilitySet, PluginId, PluginRegistrar};
49 let registry = Arc::new(uni_plugin::PluginRegistry::default());
50 let plugin_id = PluginId::new("uni");
51 let caps = CapabilitySet::from_iter_of([Capability::Procedure, Capability::ProcedureSchema]);
52 let mut r = PluginRegistrar::new(plugin_id, &caps, ®istry);
53 let algo_registry: Arc<AlgorithmRegistry> = Arc::new(AlgorithmRegistry::new());
54 register_into(&mut r, Some(&algo_registry))
55 .expect("default host plugin registration must succeed");
56 r.commit_to_registry()
57 .expect("default host plugin commit must succeed");
58 registry
59}
60
61/// Register every host-coupled built-in procedure into `r`.
62///
63/// `algo_registry` is the same `Arc<AlgorithmRegistry>` that the host
64/// wires into `GraphExecutionContext::with_algo_registry()`; pass `None`
65/// in test setups that do not need the `uni.algo.*` namespace.
66///
67/// # Errors
68///
69/// Returns [`PluginError::DuplicateRegistration`] if a procedure qname
70/// is already taken in the underlying registry.
71pub fn register_into(
72 r: &mut PluginRegistrar<'_>,
73 algo_registry: Option<&Arc<AlgorithmRegistry>>,
74) -> Result<(), PluginError> {
75 schema::register_into(r)?;
76 vector::register_into(r)?;
77 fts::register_into(r)?;
78 search::register_into(r)?;
79 graph::register_into(r)?;
80 create::register_into(r)?;
81 if let Some(algo) = algo_registry {
82 algo::register_into(r, algo)?;
83 }
84 Ok(())
85}