openlark_docs/lib.rs
1#![warn(clippy::all)]
2#![allow(clippy::manual_range_contains)]
3#![allow(clippy::needless_borrows_for_generic_args)]
4
5//! # OpenLark 文档服务模块
6//!
7//! 飞书开放平台云文档服务模块,提供文档、表格、知识库等 API 访问能力。
8//! Docs helper 的设计与命名规范见 `docs/docs-helper-guidelines.md`。
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//! let _range = client
53//! .resolve_sheet_range_by_title("spreadsheet_token", "2026", "A1:C5")
54//! .await?;
55//! let _ranges = client
56//! .read_sheet_ranges("spreadsheet_token", vec![_range.clone()])
57//! .await?;
58//! let _bytes = client.download_drive_file("file_token").await?;
59//! let _records = client
60//! .query_bitable_records(
61//! openlark_docs::BitableRecordQuery::new("app_token", "table_id")
62//! .where_equals("状态", "进行中"),
63//! )
64//! .await?;
65//! let _wiki_node = client
66//! .find_wiki_node_by_path("space_id", "产品文档/发布计划")
67//! .await?;
68//! let mut pager = client.folder_children_pager("folder_token").page_size(50);
69//! let _first_page = pager.fetch_next_page().await?;
70//!
71//! Ok(())
72//! }
73//! ```
74//!
75//! ## 特性
76//!
77//! - ✅ **202 APIs 全覆盖** - 飞书云文档服务完整实现(不含旧版本)
78//! - ✅ **类型安全** - 强类型请求/响应结构
79//! - ✅ **异步支持** - 基于 tokio 的异步 API
80//! - ✅ **版本化 API** - 支持 v1/v2/v3/v4 多版本 API
81//! - ✅ **构建器模式** - 流畅的 API 调用体验
82//! - ✅ **标准架构** - 严格按照 bizTag/project/version/resource/name.rs 模式组织
83
84// Include macros first - 对所有功能都启用宏
85#[macro_use]
86mod macros;
87
88// Core modules
89/// 通用文档数据模型。
90pub mod models;
91
92// 功能模块按业务域组织
93#[cfg(feature = "ccm-core")]
94/// 云文档协同能力模块。
95pub mod ccm;
96
97#[cfg(any(feature = "base", feature = "bitable"))]
98/// 多维表格与基础服务模块。
99pub mod base;
100
101#[cfg(any(feature = "baike", feature = "lingo"))]
102/// 企业知识库模块。
103pub mod baike;
104
105#[cfg(feature = "minutes")]
106/// 会议纪要模块。
107pub mod minutes;
108
109// API版本模块
110#[cfg(any(feature = "v1", feature = "v2", feature = "v3"))]
111/// 版本兼容入口模块。
112pub mod versions;
113
114// 通用模块 - 工具宏和类型
115/// 通用工具、链式 helper 与端点定义。
116pub mod common;
117
118// Prelude模块 - 常用导入
119/// 常用类型预导出模块。
120pub mod prelude;
121
122// 重新导出主要类型
123#[cfg(feature = "bitable")]
124pub use common::chain::BitableRecordQuery;
125pub use common::chain::DocsClient;
126pub use common::chain::TypedPage;
127#[cfg(feature = "ccm-core")]
128pub use common::chain::WikiNodePath;
129#[cfg(feature = "ccm-core")]
130pub use common::chain::{DriveDownloadRange, DriveUploadFile};
131#[cfg(feature = "ccm-core")]
132pub use common::chain::{FolderChildrenPage, FolderChildrenPager, SheetRange, SheetWriteRange};
133
134// === 入口设计说明 ===
135//
136// openlark-docs 采用简化的入口设计:
137//
138// 1. **DocsClient** (公开入口)
139// - 唯一推荐的公开入口
140// - 提供配置获取:`docs.ccm.config()`, `docs.base.bitable.config()`
141// - 按业务域分组:`docs.ccm`, `docs.base`, `docs.baike`, `docs.minutes`
142// - 自动根据 feature 裁剪编译
143//
144// 2. **使用方式**
145// - 通过 DocsClient 获取配置
146// - 使用 `*Request::new(config, ...)` 构建请求
147// - 调用 `.execute().await?` 执行
148//
149// === 示例代码 ===
150//
151// ```rust
152// use openlark_docs::DocsClient;
153// use openlark_docs::ccm::drive::v1::file::UploadAllRequest;
154//
155// let docs = DocsClient::new(config);
156//
157// // 访问云盘服务
158// let config = docs.ccm.config().clone();
159// let request = UploadAllRequest::new(config, ...);
160// let file = request.execute().await?;
161//
162// // 访问多维表格
163// let config = docs.base.bitable.config().clone();
164// let request = CreateTableRequest::new(config, ...);
165// let table = request.execute().await?;
166//
167// // 高频 helper
168// let records = docs.search_bitable_records_all("app_token", "table_id").await?;
169// let sheet = docs.find_sheet_by_title("spreadsheet_token", "2026").await?;
170// ```
171//
172// === 导出说明 ===
173//
174// 已移除所有 Service 类型,统一使用 Request 模式
175// 用户应通过以下方式使用 API:
176// 1. 从 `openlark_docs::*` 模块导入 Request 类型
177// 2. 使用 `DocsClient` 获取配置
178// 3. 构建并执行 Request
179
180#[cfg(test)]
181mod client_tests {
182 use super::*;
183 use openlark_core::config::Config;
184
185 fn create_test_config() -> Config {
186 Config::builder()
187 .app_id("test_app")
188 .app_secret("test_secret")
189 .build()
190 }
191
192 #[test]
193 fn test_docs_client_creation() {
194 let config = create_test_config();
195 let client = DocsClient::new(config);
196 assert_eq!(client.config().app_id(), "test_app");
197 }
198
199 #[test]
200 fn test_docs_client_clone() {
201 let config = create_test_config();
202 let client = DocsClient::new(config);
203 let cloned = client.clone();
204 assert_eq!(cloned.config().app_id(), "test_app");
205 }
206
207 #[cfg(feature = "ccm-core")]
208 #[test]
209 fn test_docs_client_ccm() {
210 let config = create_test_config();
211 let client = DocsClient::new(config);
212 assert_eq!(client.ccm.config().app_id(), "test_app");
213 }
214
215 #[cfg(any(feature = "base", feature = "bitable"))]
216 #[test]
217 fn test_docs_client_base() {
218 let config = create_test_config();
219 let client = DocsClient::new(config);
220 let _base = &client.base;
221 }
222}