Skip to main content

ontocore_plugin/
traits.rs

1use ontocore_catalog::OntologyCatalog;
2use ontocore_core::Diagnostic;
3use ontocore_docs::{ExportError, ExportOptions};
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6use std::path::{Path, PathBuf};
7
8pub trait ValidatorPlugin: Send + Sync {
9    fn id(&self) -> &str;
10    fn validate(&self, catalog: &OntologyCatalog, workspace: &Path) -> Vec<Diagnostic>;
11}
12
13pub trait ExporterPlugin: Send + Sync {
14    fn id(&self) -> &str;
15    fn export(
16        &self,
17        catalog: &OntologyCatalog,
18        workspace: &Path,
19        options: ExportOptions,
20    ) -> Result<Vec<PathBuf>, ExportError>;
21}
22
23#[derive(Debug, Clone)]
24pub struct WorkflowRequest {
25    pub step: String,
26    pub dry_run: bool,
27}
28
29#[derive(Debug, Clone)]
30pub struct WorkflowResult {
31    pub success: bool,
32    pub logs: String,
33    pub diagnostics: Vec<Diagnostic>,
34}
35
36pub trait WorkflowPlugin: Send + Sync {
37    fn id(&self) -> &str;
38    fn run(&self, workspace: &Path, request: WorkflowRequest) -> WorkflowResult;
39}
40
41/// Thin reasoner adapter (SDK 1.0) — emits unsatisfiable IRIs compatible with reasoner UIs.
42#[derive(Debug, Clone, Default, Serialize, Deserialize)]
43pub struct ReasonerProviderResult {
44    pub profile: String,
45    pub unsatisfiable: Vec<String>,
46    #[serde(default)]
47    pub logs: Option<String>,
48}
49
50pub trait ReasonerPlugin: Send + Sync {
51    fn id(&self) -> &str;
52    fn classify(&self, catalog: &OntologyCatalog, workspace: &Path) -> ReasonerProviderResult;
53}
54
55/// Thin query adapter — tabular rows for Query Workbench / CLI.
56#[derive(Debug, Clone, Default, Serialize, Deserialize)]
57pub struct QueryProviderResult {
58    pub columns: Vec<String>,
59    pub rows: Vec<Vec<String>>,
60    #[serde(default)]
61    pub truncated: bool,
62}
63
64pub trait QueryPlugin: Send + Sync {
65    fn id(&self) -> &str;
66    fn run(&self, catalog: &OntologyCatalog, workspace: &Path, query: &str) -> QueryProviderResult;
67}
68
69/// Thin refactor preview tip (does not apply edits).
70#[derive(Debug, Clone, Default, Serialize, Deserialize)]
71pub struct RefactorProviderResult {
72    pub affected_iris: Vec<String>,
73    pub hints: Vec<String>,
74}
75
76pub trait RefactorPlugin: Send + Sync {
77    fn id(&self) -> &str;
78    fn preview(
79        &self,
80        catalog: &OntologyCatalog,
81        workspace: &Path,
82        focus_iri: Option<&str>,
83    ) -> RefactorProviderResult;
84}
85
86/// Thin graph provider — optional graph_kind + IRI seeds / overlay payload.
87#[derive(Debug, Clone, Default, Serialize, Deserialize)]
88pub struct GraphProviderResult {
89    pub graph_kind: String,
90    pub root_iris: Vec<String>,
91    #[serde(default)]
92    pub result: Option<Value>,
93}
94
95pub trait GraphPlugin: Send + Sync {
96    fn id(&self) -> &str;
97    fn build(
98        &self,
99        catalog: &OntologyCatalog,
100        workspace: &Path,
101        root_iri: Option<&str>,
102    ) -> GraphProviderResult;
103}