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// ============================================================================
32// Internal Modules (crate-private, but visible to integration tests)
33// ============================================================================
34
35// These modules are internal but need to be accessible to integration tests
36// that test platform-specific components
37#[cfg_attr(not(test), doc(hidden))]
38pub mod bootstrap;
39#[cfg_attr(not(test), doc(hidden))]
40pub mod channels;
41#[cfg_attr(not(test), doc(hidden))]
42pub mod component_ops;
43#[cfg_attr(not(test), doc(hidden))]
44pub mod inspection;
45#[cfg_attr(not(test), doc(hidden))]
46pub mod lib_core;
47#[cfg_attr(not(test), doc(hidden))]
48pub mod lifecycle;
49#[cfg_attr(not(test), doc(hidden))]
50pub mod queries;
51#[cfg_attr(not(test), doc(hidden))]
52pub mod reactions;
53#[cfg_attr(not(test), doc(hidden))]
54pub mod sources;
55
56// Sub-modules for lib_core operations (split for maintainability)
57mod lib_core_ops;
58#[cfg_attr(not(test), doc(hidden))]
59pub mod managers;
60#[cfg_attr(not(test), doc(hidden))]
61pub mod state_guard;
62
63// Config module needs to be public for configuration types
64pub mod config;
65
66// Indexes module for storage backend configuration
67pub mod indexes;
68
69// Profiling module for performance monitoring
70#[cfg_attr(not(test), doc(hidden))]
71pub mod profiling;
72
73// ============================================================================
74// Clean Public API - Everything Users Need
75// ============================================================================
76
77/// Main server type - use `DrasiLib::builder()` to create instances
78///
79/// # Examples
80///
81/// ```no_run
82/// use drasi_lib::DrasiLib;
83///
84/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
85/// let core = DrasiLib::builder()
86///     .with_id("my-server")
87///     .build()
88///     .await?;
89/// core.start().await?;
90/// # Ok(())
91/// # }
92/// ```
93pub use lib_core::DrasiLib;
94
95/// Error types for drasi-lib
96pub use error::{DrasiError, Result};
97
98/// Component status type for monitoring component states
99pub use channels::ComponentStatus;
100
101/// Dispatch mode for configuring event routing (Broadcast or Channel)
102pub use channels::DispatchMode;
103
104// ============================================================================
105// Configuration Types
106// ============================================================================
107
108/// Configuration types
109pub use config::{
110    DrasiLibConfig, QueryConfig, QueryLanguage, QueryRuntime, ReactionRuntime, RuntimeConfig,
111    SourceRuntime,
112};
113
114/// Storage backend configuration types
115pub use indexes::{StorageBackendConfig, StorageBackendRef, StorageBackendSpec};
116
117// ============================================================================
118// Plugin Traits (for plugin development)
119// ============================================================================
120
121/// Source trait for implementing source plugins
122pub use sources::Source;
123
124/// Reaction traits for implementing reaction plugins
125pub use reactions::{QueryProvider, Reaction};
126
127/// Bootstrap provider trait for implementing bootstrap plugins
128pub use bootstrap::BootstrapProvider;
129
130/// Index backend plugin trait for implementing storage backends
131pub use indexes::IndexBackendPlugin;
132
133/// State store provider traits and default implementation
134pub use state_store::{
135    MemoryStateStoreProvider, StateStoreError, StateStoreProvider, StateStoreResult,
136};
137
138/// Runtime context types for plugin initialization
139pub use context::{ReactionRuntimeContext, SourceRuntimeContext};
140
141pub use reactions::{ReactionBase, ReactionBaseParams};
142/// Base implementations for source and reaction plugins
143/// These are used by plugin developers, not by drasi-lib itself
144pub use sources::{SourceBase, SourceBaseParams};
145
146// ============================================================================
147// Builder Types (for fluent configuration)
148// ============================================================================
149
150/// Fluent builder for DrasiLib instances
151pub use builder::DrasiLibBuilder;
152
153/// Fluent builder for query configurations
154pub use builder::Query;
155
156// ============================================================================
157// API Module (backward compatibility alias)
158// ============================================================================
159
160/// Re-export builders as `api` module for backward compatibility with tests.
161/// This allows `use crate::api::{Query};` to work.
162pub mod api {
163    pub use crate::builder::Query;
164}