Skip to main content

openlark_docs/
lib.rs

1#![warn(clippy::all)]
2#![allow(clippy::manual_range_contains)]
3#![allow(clippy::needless_borrows_for_generic_args)]
4#![allow(missing_docs)]
5
6//! # OpenLark 文档服务模块
7//!
8//! 飞书开放平台云文档服务模块,提供文档、表格、知识库等 API 访问能力。
9//!
10//! ## 文档模块业务域结构 (严格按照 bizTag/project/version/resource 组织)
11//!
12//! ### CCM - 云文档协同 (174 APIs)
13//! - **docx**: 新版文档块与群公告(19 APIs)
14//! - **drive**: 云空间文件管理(59 APIs)
15//! - **sheets**: 电子表格(27 APIs)
16//! - **wiki**: 知识库(16 APIs)
17//! - **doc**: 文档基础服务
18//! - **docs**: 云文档管理
19//!
20//! ### BASE - 基础服务 (49 APIs)
21//! - **base**: 基础应用服务
22//! - **bitable**: 多维表格(46 APIs)
23//!
24//! ### BAIKE - 企业知识库 (27 APIs)
25//! - **baike**: 知识库空间和节点
26//! - **lingo**: 知识库分类和实体
27//!
28//! ### MINUTES - 会议纪要 (4 APIs)
29//! - **minutes**: 会议转录和纪要管理
30//!
31//! ## 快速开始
32//!
33//! ```rust,ignore
34//! use openlark_core::config::Config;
35//! use openlark_docs::DocsClient;
36//!
37//! #[tokio::main]
38//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
39//!     let config = Config::builder()
40//!         .app_id("app_id")
41//!         .app_secret("app_secret")
42//!         .build();
43//!     let client = DocsClient::new(config);
44//!
45//!     // 获取配置后构建 Request
46//!     let config = client.ccm.config().clone();
47//!     // 使用 openlark_docs::ccm::drive::v1::file::UploadAllRequest
48//!
49//!     // 高频读取场景也可以直接使用 helper
50//!     let _records = client.search_bitable_records_all("app_token", "table_id").await?;
51//!     let _sheet = client.find_sheet_by_title("spreadsheet_token", "2026").await?;
52//!
53//!     Ok(())
54//! }
55//! ```
56//!
57//! ## 特性
58//!
59//! - ✅ **202 APIs 全覆盖** - 飞书云文档服务完整实现(不含旧版本)
60//! - ✅ **类型安全** - 强类型请求/响应结构
61//! - ✅ **异步支持** - 基于 tokio 的异步 API
62//! - ✅ **版本化 API** - 支持 v1/v2/v3/v4 多版本 API
63//! - ✅ **构建器模式** - 流畅的 API 调用体验
64//! - ✅ **标准架构** - 严格按照 bizTag/project/version/resource/name.rs 模式组织
65
66// Include macros first - 对所有功能都启用宏
67#[macro_use]
68mod macros;
69
70// Core modules
71pub mod models;
72
73// 功能模块按业务域组织
74#[cfg(feature = "ccm-core")]
75pub mod ccm;
76
77#[cfg(any(feature = "base", feature = "bitable"))]
78pub mod base;
79
80#[cfg(any(feature = "baike", feature = "lingo"))]
81pub mod baike;
82
83#[cfg(feature = "minutes")]
84pub mod minutes;
85
86// API版本模块
87#[cfg(any(feature = "v1", feature = "v2", feature = "v3"))]
88pub mod versions;
89
90// 通用模块 - 工具宏和类型
91pub mod common;
92
93// Prelude模块 - 常用导入
94pub mod prelude;
95
96// 重新导出主要类型
97pub use common::chain::DocsClient;
98
99// === 入口设计说明 ===
100//
101// openlark-docs 采用简化的入口设计:
102//
103// 1. **DocsClient** (公开入口)
104//    - 唯一推荐的公开入口
105//    - 提供配置获取:`docs.ccm.config()`, `docs.base.bitable.config()`
106//    - 按业务域分组:`docs.ccm`, `docs.base`, `docs.baike`, `docs.minutes`
107//    - 自动根据 feature 裁剪编译
108//
109// 2. **使用方式**
110//    - 通过 DocsClient 获取配置
111//    - 使用 `*Request::new(config, ...)` 构建请求
112//    - 调用 `.execute().await?` 执行
113//
114// === 示例代码 ===
115//
116// ```rust
117// use openlark_docs::DocsClient;
118// use openlark_docs::ccm::drive::v1::file::UploadAllRequest;
119//
120// let docs = DocsClient::new(config);
121//
122// // 访问云盘服务
123// let config = docs.ccm.config().clone();
124// let request = UploadAllRequest::new(config, ...);
125// let file = request.execute().await?;
126//
127// // 访问多维表格
128// let config = docs.base.bitable.config().clone();
129// let request = CreateTableRequest::new(config, ...);
130// let table = request.execute().await?;
131//
132// // 高频 helper
133// let records = docs.search_bitable_records_all("app_token", "table_id").await?;
134// let sheet = docs.find_sheet_by_title("spreadsheet_token", "2026").await?;
135// ```
136//
137// === 导出说明 ===
138//
139// 已移除所有 Service 类型,统一使用 Request 模式
140// 用户应通过以下方式使用 API:
141// 1. 从 `openlark_docs::*` 模块导入 Request 类型
142// 2. 使用 `DocsClient` 获取配置
143// 3. 构建并执行 Request
144
145#[cfg(test)]
146mod client_tests {
147    use super::*;
148    use openlark_core::config::Config;
149
150    fn create_test_config() -> Config {
151        Config::builder()
152            .app_id("test_app")
153            .app_secret("test_secret")
154            .build()
155    }
156
157    #[test]
158    fn test_docs_client_creation() {
159        let config = create_test_config();
160        let client = DocsClient::new(config);
161        assert_eq!(client.config().app_id(), "test_app");
162    }
163
164    #[test]
165    fn test_docs_client_clone() {
166        let config = create_test_config();
167        let client = DocsClient::new(config);
168        let cloned = client.clone();
169        assert_eq!(cloned.config().app_id(), "test_app");
170    }
171
172    #[cfg(feature = "ccm-core")]
173    #[test]
174    fn test_docs_client_ccm() {
175        let config = create_test_config();
176        let client = DocsClient::new(config);
177        assert_eq!(client.ccm.config().app_id(), "test_app");
178    }
179
180    #[cfg(any(feature = "base", feature = "bitable"))]
181    #[test]
182    fn test_docs_client_base() {
183        let config = create_test_config();
184        let client = DocsClient::new(config);
185        let _base = &client.base;
186    }
187}