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 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    #[cfg(feature = "dynamodb")]
94    pub use crate::storage::{DynamoDBDataService, DynamoDBLinkService};
95    pub use crate::storage::{InMemoryDataService, InMemoryLinkService};
96    #[cfg(feature = "lmdb")]
97    pub use crate::storage::{LmdbDataService, LmdbLinkService};
98    #[cfg(feature = "mongodb_backend")]
99    pub use crate::storage::{MongoDataService, MongoLinkService};
100    #[cfg(feature = "mysql")]
101    pub use crate::storage::{MysqlDataService, MysqlLinkService};
102    #[cfg(feature = "neo4j")]
103    pub use crate::storage::{Neo4jDataService, Neo4jLinkService};
104    #[cfg(feature = "postgres")]
105    pub use crate::storage::{PostgresDataService, PostgresLinkService};
106    #[cfg(feature = "scylladb")]
107    pub use crate::storage::{ScyllaDataService, ScyllaLinkService};
108
109    // === Config ===
110    pub use crate::config::{EntityAuthConfig, EntityConfig, LinksConfig, ValidationRule};
111
112    // === Server ===
113    pub use crate::server::{EntityDescriptor, EntityRegistry, ServerBuilder};
114
115    // === External dependencies ===
116    pub use anyhow::Result;
117    pub use async_trait::async_trait;
118    pub use chrono::{DateTime, Utc};
119    pub use serde::{Deserialize, Serialize};
120    pub use uuid::Uuid;
121
122    // === Axum ===
123    pub use axum::{
124        Router,
125        extract::{Path, State},
126        http::HeaderMap,
127        routing::{delete, get, post, put},
128    };
129}