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
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.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// Core modules
85/// 通用文档数据模型。
86pub mod models;
87
88// 功能模块按业务域组织
89#[cfg(feature = "ccm-core")]
90/// 云文档协同能力模块。
91pub mod ccm;
92
93#[cfg(any(feature = "base", feature = "bitable"))]
94/// 多维表格与基础服务模块。
95pub mod base;
96
97#[cfg(any(feature = "baike", feature = "lingo"))]
98/// 企业知识库模块。
99pub mod baike;
100
101#[cfg(feature = "minutes")]
102/// 会议纪要模块。
103pub mod minutes;
104
105// 通用模块 - 工具宏和类型
106/// 通用工具、链式 helper 与端点定义。
107pub mod common;
108
109// Prelude模块 - 常用导入
110/// 常用类型预导出模块。
111pub mod prelude;
112
113// 重新导出主要类型
114#[cfg(feature = "bitable")]
115pub use common::chain::BitableRecordQuery;
116pub use common::chain::DocsClient;
117pub use common::chain::TypedPage;
118#[cfg(feature = "ccm-core")]
119pub use common::chain::WikiNodePath;
120#[cfg(feature = "ccm-core")]
121pub use common::chain::{DriveDownloadRange, DriveUploadFile};
122#[cfg(feature = "ccm-core")]
123pub use common::chain::{FolderChildrenPage, FolderChildrenPager, SheetRange, SheetWriteRange};
124
125// === 入口设计说明 ===
126//
127// openlark-docs 采用简化的入口设计:
128//
129// 1. **DocsClient** (公开入口)
130//    - 唯一推荐的公开入口
131//    - 提供配置获取:`docs.config()`(直路径,ADR 0001 扁平收口)
132//    - 业务域 config-holder 子客户端(CcmClient/BaseClient/BitableClient/BaikeClient/MinutesClient)已移除
133//    - 自动根据 feature 裁剪编译
134//
135// 2. **使用方式**
136//    - 通过 DocsClient 获取配置
137//    - 使用 `*Request::new(config, ...)` 构建请求
138//    - 调用 `.execute().await?` 执行
139//
140// === 示例代码 ===
141//
142// ```rust
143// use openlark_docs::DocsClient;
144// use openlark_docs::ccm::drive::v1::file::UploadAllRequest;
145//
146// let docs = DocsClient::new(config);
147//
148// // 访问云盘服务
149// let config = docs.config().clone();
150// let request = UploadAllRequest::new(config, ...);
151// let file = request.execute().await?;
152//
153// // 访问多维表格
154// let config = docs.config().clone();
155// let request = CreateTableRequest::new(config, ...);
156// let table = request.execute().await?;
157//
158// // 高频 helper
159// let records = docs.search_bitable_records_all("app_token", "table_id").await?;
160// let sheet = docs.find_sheet_by_title("spreadsheet_token", "2026").await?;
161// ```
162//
163// === 导出说明 ===
164//
165// 已移除所有 Service 类型,统一使用 Request 模式
166// 用户应通过以下方式使用 API:
167// 1. 从 `openlark_docs::*` 模块导入 Request 类型
168// 2. 使用 `DocsClient` 获取配置
169// 3. 构建并执行 Request
170
171#[cfg(test)]
172mod client_tests {
173    use super::*;
174    use openlark_core::config::Config;
175
176    fn create_test_config() -> Config {
177        Config::builder()
178            .app_id("test_app")
179            .app_secret("test_secret")
180            .build()
181    }
182
183    #[test]
184    fn test_docs_client_creation() {
185        let config = create_test_config();
186        let client = DocsClient::new(config);
187        assert_eq!(client.config().app_id(), "test_app");
188    }
189
190    #[test]
191    fn test_docs_client_clone() {
192        let config = create_test_config();
193        let client = DocsClient::new(config);
194        let cloned = client.clone();
195        assert_eq!(cloned.config().app_id(), "test_app");
196    }
197}