@chatbi-v/mocks 2.0.0 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,54 @@
1
- # @chatbi/mocks
1
+ # @chatbi-v/mocks
2
2
 
3
3
  ChatBI Mock 数据模块,提供灵活的 JSON 和 SSE (Server-Sent Events) 数据模拟功能。
4
4
 
5
+ ## 模块功能说明
6
+
7
+ - **响应策略管理**: 支持 JSON、SSE (流式) 和 SSE-Page (分页流) 等多种响应模式。
8
+ - **数据生成器**: 集成 Mock.js,支持丰富的模板语法和动态数据生成。
9
+ - **拦截器适配**: 轻松接入 Axios 或其他请求库,实现无缝的本地模拟开发。
10
+ - **参数动态插值**: 支持在模板中引用请求 Query 或 Body 参数。
11
+
12
+ ## 安装和使用方法
13
+
14
+ ### 安装
15
+
16
+ ```bash
17
+ pnpm add @chatbi-v/mocks
18
+ ```
19
+
20
+ ### 使用示例
21
+
22
+ ```typescript
23
+ import { MockInterceptor } from '@chatbi-v/mocks';
24
+
25
+ const interceptor = new MockInterceptor();
26
+
27
+ // 注册 mock 规则
28
+ interceptor.register('GET /api/user', {
29
+ type: 'json',
30
+ responseSchema: {
31
+ code: 200,
32
+ data: { id: 1, name: '@cname' }
33
+ }
34
+ });
35
+
36
+ // 在请求库中使用拦截器
37
+ // axios.interceptors.request.use(interceptor.getRequestInterceptor());
38
+ ```
39
+
40
+ ## API 文档链接
41
+
42
+ 请参考 [Mock 模块详细文档](https://github.com/your-repo/docs/mocks/index.md)。
43
+
44
+ ## 开发注意事项
45
+
46
+ - **命名规范**: 建议 Mock 文件以 `.mock.ts` 结尾。
47
+ - **数据一致性**: 确保 Mock 返回的数据结构与后端 API 定义一致。
48
+ - **性能**: SSE 模式下的 `delay` 参数不宜设置过大,以免影响开发体验。
49
+
50
+ ---
51
+
5
52
  ## 特性
6
53
 
7
54
  - **多种响应策略**:支持 `json` (普通接口)、`sse` (流式接口)、`sse-page` (带分页的流式接口)。