Skip to main content

drasi_lib/
lib.rs

1// Copyright 2025 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// ============================================================================
16// Core Public Modules
17// ============================================================================
18
19/// Fluent builders for DrasiLib and components
20pub mod builder;
21
22/// Runtime context types for plugin service injection
23pub mod context;
24
25/// State store provider for persistent plugin state
26pub mod state_store;
27
28/// Error types for drasi-lib
29pub mod error;
30
31/// Identity providers for authentication credentials
32pub mod identity;
33
34// ============================================================================
35// Internal Modules (crate-private, but visible to integration tests)
36// ============================================================================
37
38// These modules are internal but need to be accessible to integration tests
39// that test platform-specific components
40#[cfg_attr(not(test), doc(hidden))]
41pub mod bootstrap;
42#[cfg_attr(not(test), doc(hidden))]
43pub mod channels;
44#[cfg_attr(not(test), doc(hidden))]
45pub mod component_ops;
46#[cfg_attr(not(test), doc(hidden))]
47pub mod inspection;
48#[cfg_attr(not(test), doc(hidden))]
49pub mod lib_core;
50#[cfg_attr(not(test), doc(hidden))]
51pub mod lifecycle;
52#[cfg_attr(not(test), doc(hidden))]
53pub mod queries;
54#[cfg_attr(not(test), doc(hidden))]
55pub mod reactions;
56#[cfg_attr(not(test), doc(hidden))]
57pub mod sources;
58
59// Sub-modules for lib_core operations (split for maintainability)
60mod lib_core_ops;
61#[cfg_attr(not(test), doc(hidden))]
62pub mod managers;
63#[cfg_attr(not(test), doc(hidden))]
64pub mod state_guard;
65
66// Config module needs to be public for configuration types
67pub mod config;
68
69// Indexes module for storage backend configuration
70pub mod indexes;
71
72// Profiling module for performance monitoring
73#[cfg_attr(not(test), doc(hidden))]
74pub mod profiling;
75
76// ============================================================================
77// Clean Public API - Everything Users Need
78// ============================================================================
79
80/// Main server type - use `DrasiLib::builder()` to create instances
81///
82/// # Examples
83///
84/// ```no_run
85/// use drasi_lib::DrasiLib;
86///
87/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
88/// let core = DrasiLib::builder()
89///     .with_id("my-server")
90///     .build()
91///     .await?;
92/// core.start().await?;
93/// # Ok(())
94/// # }
95/// ```
96pub use lib_core::DrasiLib;
97
98/// Error types for drasi-lib
99pub use error::{DrasiError, Result};
100
101/// Component status type for monitoring component states
102pub use channels::ComponentStatus;
103
104/// Component event for tracking lifecycle changes
105pub use channels::{ComponentEvent, ComponentType};
106
107/// Subscription response for source subscriptions
108pub use channels::SubscriptionResponse;
109
110/// Dispatch mode for configuring event routing (Broadcast or Channel)
111pub use channels::DispatchMode;
112
113/// Log level and log message types for component log streaming
114pub use managers::{LogLevel, LogMessage};
115
116/// Tracing initialization function - call to set up component log routing
117pub use managers::{get_or_init_global_registry, init_tracing, try_init_tracing};
118
119// ============================================================================
120// Configuration Types
121// ============================================================================
122
123/// Configuration types
124pub use config::{
125    DrasiLibConfig, QueryConfig, QueryLanguage, QueryRuntime, ReactionRuntime, RuntimeConfig,
126    SourceRuntime, SourceSubscriptionSettings,
127};
128
129/// Storage backend configuration types
130pub use indexes::{StorageBackendConfig, StorageBackendRef, StorageBackendSpec};
131
132// ============================================================================
133// Plugin Traits (for plugin development)
134// ============================================================================
135
136/// Source trait for implementing source plugins
137pub use sources::Source;
138
139/// Reaction traits for implementing reaction plugins
140pub use reactions::{QueryProvider, Reaction};
141
142/// Bootstrap provider trait for implementing bootstrap plugins
143pub use bootstrap::BootstrapProvider;
144
145/// Index backend plugin trait for implementing storage backends
146pub use indexes::IndexBackendPlugin;
147
148/// State store provider traits and default implementation
149pub use state_store::{
150    MemoryStateStoreProvider, StateStoreError, StateStoreProvider, StateStoreResult,
151};
152
153/// Runtime context types for plugin initialization
154pub use context::{ReactionRuntimeContext, SourceRuntimeContext};
155
156pub use reactions::{ReactionBase, ReactionBaseParams};
157/// Base implementations for source and reaction plugins
158/// These are used by plugin developers, not by drasi-lib itself
159pub use sources::{SourceBase, SourceBaseParams};
160
161// ============================================================================
162// Builder Types (for fluent configuration)
163// ============================================================================
164
165/// Fluent builder for DrasiLib instances
166pub use builder::DrasiLibBuilder;
167
168/// Fluent builder for query configurations
169pub use builder::Query;
170
171// ============================================================================
172// API Module (backward compatibility alias)
173// ============================================================================
174
175/// Re-export builders as `api` module for backward compatibility with tests.
176/// This allows `use crate::api::{Query};` to work.
177pub mod api {
178    pub use crate::builder::Query;
179}