Skip to main content

openlark_core/
lib.rs

1//! OpenLark Core Infrastructure
2//!
3//! This crate provides the core infrastructure for the OpenLark SDK including
4//! HTTP client configuration, error handling, authentication, and common utilities.
5
6// 对外稳定导出:尽量保持"少而清晰"的公共 API(KISS)
7pub mod api;
8pub mod auth;
9/// 客户端配置模块(Config、ConfigBuilder 等)
10pub mod config;
11/// 全局常量定义(URL、错误码前缀、超时配置等)
12pub mod constants;
13/// 统一错误处理模块(CoreError、错误码、错误上下文等)
14pub mod error;
15/// HTTP 客户端模块(Transport、请求构建等)
16pub mod http;
17pub(crate) mod observability;
18pub(crate) mod query_params;
19/// 请求选项模块(RequestOption、自定义头部、租户键等)
20pub mod req_option;
21pub(crate) mod request_builder;
22#[cfg(feature = "testing")]
23pub mod testing;
24pub mod trait_system;
25pub mod validation;
26
27// crate 内部实现细节:不对外暴露(避免把 core 变成"全家桶")
28// 已移动到 auth::app_ticket
29mod content_disposition;
30mod performance;
31mod req_translator;
32mod response_handler;
33mod utils;
34
35// Re-export commonly used types from crate root
36pub use error::{validation_error, CoreError, SDKResult};
37pub use validation::Validatable;
38
39// Re-export validate_required macro for docs module
40/// 验证必填字段(检查非空白字符串)
41///
42/// # 参数
43/// - `$field`: 要验证的字段
44/// - `$error_msg`: 错误消息
45///
46/// # 使用示例
47/// ```rust,ignore
48/// validate_required!(self.user_id, "用户 ID 不能为空");
49/// ```
50#[macro_export]
51macro_rules! validate_required {
52    ($field:expr, $error_msg:expr) => {
53        if $crate::Validatable::is_empty_trimmed(&$field) {
54            return Err($crate::error::CoreError::validation_msg($error_msg));
55        }
56    };
57}
58
59/// 验证必填列表字段(检查非空和最大长度)
60///
61/// # 参数
62/// - `$field`: 要验证的列表字段
63/// - `$max_len`: 最大长度限制
64/// - `$error_msg`: 错误消息
65///
66/// # 使用示例
67/// ```rust,ignore
68/// validate_required_list!(self.user_ids, 50, "用户 ID 列表不能为空且不能超过 50 个");
69/// ```
70#[macro_export]
71macro_rules! validate_required_list {
72    ($field:expr, $max_len:expr, $error_msg:expr) => {
73        if $field.is_empty() {
74            return Err($crate::error::CoreError::validation_msg($error_msg));
75        }
76        if $field.len() > $max_len {
77            return Err($crate::error::CoreError::validation_msg($error_msg));
78        }
79    };
80}
81
82/// Prelude module for convenient imports.
83pub mod prelude {
84    // Re-export new API module(请求/响应基础类型)
85    pub use crate::api::prelude::*;
86
87    // Re-export commonly used core modules directly(最小集合)
88    pub use crate::config::Config;
89    pub use crate::constants::*;
90    pub use crate::error::{validation_error, CoreError, SDKResult};
91    pub use crate::http::Transport;
92    pub use crate::req_option::*;
93    pub use crate::validate_required;
94    pub use crate::validate_required_list;
95}