Skip to main content

openlark_docs/common/
mod.rs

1/// 文档服务 API 端点定义。
2pub mod api_endpoints;
3/// 文档服务 API 通用辅助函数。
4pub mod api_utils;
5/// 文档服务请求构建辅助模块。
6pub mod builders;
7/// 文档服务链式调用入口模块。
8pub mod chain;
9/// 文档服务通用请求构建器模块。
10pub mod request_builder;
11
12/// 重新导出常用 API 端点枚举。
13pub use api_endpoints::{BaseApiV2, BitableApiV1, MinutesApiV1, SheetsApiV3};
14
15/// 通用常量定义。
16pub mod constants {
17    /// 默认分页大小。
18    pub const DEFAULT_PAGE_SIZE: i32 = 20;
19    /// 最大分页大小。
20    pub const MAX_PAGE_SIZE: i32 = 100;
21    /// 默认超时时间(秒)。
22    pub const DEFAULT_TIMEOUT_SECS: u64 = 30;
23}
24
25/// 通用类型别名。
26pub mod types {
27    /// 多维表格应用 Token。
28    pub type AppToken = String;
29    /// 数据表 ID。
30    pub type TableId = String;
31    /// 记录 ID。
32    pub type RecordId = String;
33    /// 表单 ID。
34    pub type FormId = String;
35    /// 视图 ID。
36    pub type ViewId = String;
37    /// 字段 ID。
38    pub type FieldId = String;
39    /// 角色 ID。
40    pub type RoleId = String;
41    /// 用户 ID。
42    pub type UserId = String;
43}
44
45/// 批量操作相关类型。
46pub mod batch {
47    use serde::{Deserialize, Serialize};
48
49    /// 通用批量操作参数。
50    #[derive(Debug, Clone, Default, Serialize, Deserialize)]
51    pub struct BatchCommonParams {
52        /// 用户 ID 类型。
53        pub user_id_type: Option<String>,
54        /// 客户端幂等令牌。
55        pub client_token: Option<String>,
56    }
57
58    impl BatchCommonParams {
59        /// 创建默认批量操作参数。
60        pub fn new() -> Self {
61            Self::default()
62        }
63
64        /// 设置用户 ID 类型。
65        pub fn with_user_id_type(mut self, user_id_type: impl ToString) -> Self {
66            self.user_id_type = Some(user_id_type.to_string());
67            self
68        }
69
70        /// 设置客户端幂等令牌。
71        pub fn with_client_token(mut self, client_token: impl ToString) -> Self {
72            self.client_token = Some(client_token.to_string());
73            self
74        }
75    }
76
77    /// 通用批量请求体。
78    #[derive(Debug, Clone, Default, Serialize, Deserialize)]
79    pub struct BatchCommonBody {
80        /// 请求列表。
81        pub requests: Vec<serde_json::Value>,
82    }
83
84    /// 通用批量操作结果。
85    #[derive(Debug, Clone, Default, Serialize, Deserialize)]
86    pub struct BatchOperationResult {
87        /// 成功标识。
88        pub success: bool,
89        /// 结果列表。
90        pub results: Vec<BatchItemResult>,
91        /// 错误信息(如果有)。
92        pub error: Option<String>,
93    }
94
95    impl BatchOperationResult {
96        /// 创建成功结果。
97        pub fn success() -> Self {
98            Self {
99                success: true,
100                results: Vec::new(),
101                error: None,
102            }
103        }
104
105        /// 创建失败结果。
106        pub fn failure(error: impl ToString) -> Self {
107            Self {
108                success: false,
109                results: Vec::new(),
110                error: Some(error.to_string()),
111            }
112        }
113    }
114
115    /// 批量操作中的单项结果。
116    #[derive(Debug, Clone, Default, Serialize, Deserialize)]
117    pub struct BatchItemResult {
118        /// 成功标识。
119        pub success: bool,
120        /// 数据(如果有)。
121        pub data: Option<serde_json::Value>,
122        /// 错误信息(如果有)。
123        pub error: Option<String>,
124    }
125}
126
127/// 通用特征定义。
128pub mod traits {
129    /// API 请求基础特征。
130    pub trait ApiRequest {
131        /// 请求对应的响应类型。
132        type Response;
133
134        /// 校验请求参数。
135        fn validate(&self) -> openlark_core::SDKResult<()>;
136        /// 构建请求路径。
137        fn build_path(&self) -> String;
138    }
139
140    /// 可分页请求特征。
141    pub trait PaginatedRequest {
142        /// 设置分页游标。
143        fn page_token(self, token: impl Into<String>) -> Self;
144        /// 设置分页大小。
145        fn page_size(self, size: i32) -> Self;
146    }
147
148    /// 可筛选请求特征。
149    pub trait FilterableRequest {
150        /// 添加一个筛选条件。
151        fn add_filter(self, filter: serde_json::Value) -> Self;
152    }
153}