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 service::{DataService, LinkService},
72 };
73
74 // === Macros ===
75 pub use crate::{data_fields, entity_fields, impl_data_entity, impl_link_entity, link_fields};
76
77 // === Link Handlers ===
78 pub use crate::links::{
79 handlers::{
80 AppState, create_link, delete_link, get_link, list_available_links, list_links,
81 update_link,
82 },
83 registry::{LinkDirection, LinkRouteRegistry, RouteInfo},
84 };
85
86 // === Storage ===
87 pub use crate::storage::InMemoryLinkService;
88 #[cfg(feature = "dynamodb")]
89 pub use crate::storage::{DynamoDBDataService, DynamoDBLinkService};
90
91 // === Config ===
92 pub use crate::config::{EntityAuthConfig, EntityConfig, LinksConfig, ValidationRule};
93
94 // === Server ===
95 pub use crate::server::{EntityDescriptor, EntityRegistry, ServerBuilder};
96
97 // === External dependencies ===
98 pub use anyhow::Result;
99 pub use async_trait::async_trait;
100 pub use chrono::{DateTime, Utc};
101 pub use serde::{Deserialize, Serialize};
102 pub use uuid::Uuid;
103
104 // === Axum ===
105 pub use axum::{
106 Router,
107 extract::{Path, State},
108 http::HeaderMap,
109 routing::{delete, get, post, put},
110 };
111}