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 links;
58pub mod server;
59pub mod storage;
60
61/// Re-exports of commonly used types and traits
62pub mod prelude {
63 // === Core Traits ===
64 pub use crate::core::{
65 auth::{AuthContext, AuthPolicy, AuthProvider, NoAuthProvider},
66 entity::{Data, Entity, Link},
67 field::{FieldFormat, FieldValue},
68 link::{LinkAuthConfig, LinkDefinition, LinkEntity},
69 module::{EntityCreator, EntityFetcher, Module},
70 pluralize::Pluralizer,
71 query::{PaginatedResponse, PaginationMeta, QueryParams},
72 service::{DataService, LinkService},
73 store::QueryableStore,
74 validation::{EntityValidationConfig, Validated},
75 };
76
77 // === Macros ===
78 pub use crate::{
79 add_filters_for_field, add_validators_for_field, data_fields, entity_fields,
80 impl_data_entity, impl_data_entity_validated, impl_link_entity, link_fields,
81 };
82
83 // === Link Handlers ===
84 pub use crate::links::{
85 handlers::{
86 AppState, create_link, delete_link, get_link, list_available_links, list_links,
87 update_link,
88 },
89 registry::{LinkDirection, LinkRouteRegistry, RouteInfo},
90 };
91
92 // === Storage ===
93 pub use crate::storage::InMemoryLinkService;
94 #[cfg(feature = "dynamodb")]
95 pub use crate::storage::{DynamoDBDataService, DynamoDBLinkService};
96
97 // === Config ===
98 pub use crate::config::{EntityAuthConfig, EntityConfig, LinksConfig, ValidationRule};
99
100 // === Server ===
101 pub use crate::server::{EntityDescriptor, EntityRegistry, ServerBuilder};
102
103 // === External dependencies ===
104 pub use anyhow::Result;
105 pub use async_trait::async_trait;
106 pub use chrono::{DateTime, Utc};
107 pub use serde::{Deserialize, Serialize};
108 pub use uuid::Uuid;
109
110 // === Axum ===
111 pub use axum::{
112 Router,
113 extract::{Path, State},
114 http::HeaderMap,
115 routing::{delete, get, post, put},
116 };
117}