Skip to main content

this/
lib.rs

1//! # this-rs Framework
2//!
3//! A generic entity and relationship management framework for building RESTful APIs in Rust.
4//!
5//! ## Features
6//!
7//! - **Entity/Data/Link Architecture**: Clean hierarchy with macro-based implementation
8//! - **Flexible Relationships**: Support multiple link types between entities
9//! - **Bidirectional Navigation**: Query relationships from both directions
10//! - **Auto-Pluralization**: Intelligent plural forms (company → companies)
11//! - **Configuration-Based**: Define relationships via YAML configuration
12//! - **Type-Safe**: Leverage Rust's type system for compile-time guarantees
13//! - **Soft Delete Support**: Built-in soft deletion with deleted_at
14//! - **Automatic Timestamps**: created_at and updated_at managed automatically
15//!
16//! ## Quick Start
17//!
18//! ```rust,ignore
19//! use this::prelude::*;
20//!
21//! // Define a Data entity (extends Entity base)
22//! impl_data_entity!(
23//!     User,
24//!     "user",
25//!     ["name", "email"],
26//!     {
27//!         email: String,
28//!         password_hash: String,
29//!     }
30//! );
31//!
32//! // Define a Link entity (extends Entity base)
33//! impl_link_entity!(
34//!     UserCompanyLink,
35//!     "user_company_link",
36//!     {
37//!         role: String,
38//!         start_date: DateTime<Utc>,
39//!     }
40//! );
41//!
42//! // Usage
43//! let user = User::new(
44//!     "John Doe".to_string(),
45//!     "active".to_string(),
46//!     "john@example.com".to_string(),
47//!     "$argon2$...".to_string(),
48//! );
49//!
50//! user.soft_delete(); // Soft delete support
51//! user.restore();     // Restore support
52//! ```
53
54pub mod config;
55pub mod core;
56pub mod entities;
57pub mod events;
58pub mod links;
59pub mod server;
60pub mod storage;
61
62/// Re-exports of commonly used types and traits
63pub mod prelude {
64    // === Core Traits ===
65    pub use crate::core::{
66        auth::{AuthContext, AuthPolicy, AuthProvider, NoAuthProvider},
67        entity::{Data, Entity, Link},
68        field::{FieldFormat, FieldValue},
69        link::{LinkAuthConfig, LinkDefinition, LinkEntity},
70        module::{EntityCreator, EntityFetcher, Module},
71        pluralize::Pluralizer,
72        query::{PaginatedResponse, PaginationMeta, QueryParams},
73        service::{DataService, LinkService},
74        store::QueryableStore,
75        validation::{EntityValidationConfig, Validated},
76    };
77
78    // === Macros ===
79    pub use crate::{
80        add_filters_for_field, add_validators_for_field, data_fields, entity_fields,
81        impl_data_entity, impl_data_entity_validated, impl_link_entity, link_fields,
82    };
83
84    // === Link Handlers ===
85    pub use crate::links::{
86        handlers::{
87            AppState, create_link, delete_link, get_link, list_available_links, list_links,
88            update_link,
89        },
90        registry::{LinkDirection, LinkRouteRegistry, RouteInfo},
91    };
92
93    // === Storage ===
94    #[cfg(feature = "dynamodb")]
95    pub use crate::storage::{DynamoDBDataService, DynamoDBLinkService};
96    pub use crate::storage::{InMemoryDataService, InMemoryLinkService};
97    #[cfg(feature = "lmdb")]
98    pub use crate::storage::{LmdbDataService, LmdbLinkService};
99    #[cfg(feature = "mongodb_backend")]
100    pub use crate::storage::{MongoDataService, MongoLinkService};
101    #[cfg(feature = "mysql")]
102    pub use crate::storage::{MysqlDataService, MysqlLinkService};
103    #[cfg(feature = "neo4j")]
104    pub use crate::storage::{Neo4jDataService, Neo4jLinkService};
105    #[cfg(feature = "postgres")]
106    pub use crate::storage::{PostgresDataService, PostgresLinkService};
107    #[cfg(feature = "scylladb")]
108    pub use crate::storage::{ScyllaDataService, ScyllaLinkService};
109
110    // === Config ===
111    pub use crate::config::{
112        EntityAuthConfig, EntityConfig, EventsConfig, LinksConfig, SinkConfig, SinkType,
113        ValidationRule,
114    };
115
116    // === Server ===
117    pub use crate::server::{EntityDescriptor, EntityRegistry, ServerBuilder};
118
119    // === External dependencies ===
120    pub use anyhow::Result;
121    pub use async_trait::async_trait;
122    pub use chrono::{DateTime, Utc};
123    pub use serde::{Deserialize, Serialize};
124    pub use uuid::Uuid;
125
126    // === Axum ===
127    pub use axum::{
128        Router,
129        extract::{Path, State},
130        http::HeaderMap,
131        routing::{delete, get, post, put},
132    };
133}