befly 3.9.33 → 3.9.35

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/docs/api.md CHANGED
@@ -139,7 +139,6 @@ export default {
139
139
  fields: {}, // 字段定义(验证规则)
140
140
  required: [], // 必填字段列表
141
141
  rawBody: false, // 是否保留原始请求体
142
- preprocess: undefined, // 预处理函数
143
142
  cache: undefined, // 缓存时间(秒)
144
143
  rateLimit: undefined // 限流配置
145
144
  } as ApiRoute;
@@ -176,12 +175,6 @@ interface ApiRoute<T = any, R = any> {
176
175
  */
177
176
  rawBody?: boolean;
178
177
 
179
- /** 请求预处理函数(可选,在 handler 之前执行)
180
- * 用于解密、转换请求数据等场景
181
- * 可以修改 ctx.body
182
- */
183
- preprocess?: ApiHandler<T, void>;
184
-
185
178
  /** 缓存配置(可选,单位:秒) */
186
179
  cache?: number;
187
180
 
@@ -878,30 +871,6 @@ export default {
878
871
  };
879
872
  ```
880
873
 
881
- ### 案例九:预处理函数
882
-
883
- ```typescript
884
- // apis/data/import.ts
885
- export default {
886
- name: '导入数据',
887
- preprocess: async (befly, ctx) => {
888
- // 在 handler 之前执行
889
- // 可以解密、转换数据
890
- if (ctx.body.encryptedData) {
891
- ctx.body.data = await befly.cipher.decrypt(ctx.body.encryptedData);
892
- }
893
- },
894
- handler: async (befly, ctx) => {
895
- // 使用预处理后的数据
896
- const data = ctx.body.data;
897
-
898
- // 处理导入逻辑...
899
-
900
- return befly.tool.Yes('导入成功');
901
- }
902
- };
903
- ```
904
-
905
874
  ---
906
875
 
907
876
  ## 请求处理流程
@@ -937,14 +906,11 @@ export default {
937
906
  │ - 验证用户登录状态 │
938
907
  │ - 检查角色权限 │
939
908
  ├─────────────────────────────────────────────┤
940
- │ 6. preprocess (如果定义)
941
- │ - 执行 API 预处理函数 │
942
- ├─────────────────────────────────────────────┤
943
- │ 7. handler │
909
+ │ 6. handler
944
910
  │ - 执行 API 处理函数 │
945
911
  │ - 返回结果 │
946
912
  ├─────────────────────────────────────────────┤
947
- 8. FinalResponse │
913
+ 7. FinalResponse │
948
914
  │ - 格式化响应 │
949
915
  │ - 记录请求日志 │
950
916
  └─────────────────────────────────────────────┘
@@ -954,7 +920,7 @@ export default {
954
920
 
955
921
  ### 中断请求
956
922
 
957
- 在任何 Hook 或 preprocess 中设置 `ctx.response` 可以中断请求处理:
923
+ 在任何 Hook 中设置 `ctx.response` 可以中断请求处理:
958
924
 
959
925
  ```typescript
960
926
  // 在 Hook 中中断
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.9.33",
3
+ "version": "3.9.35",
4
4
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
5
5
  "type": "module",
6
6
  "private": false,
@@ -69,12 +69,12 @@
69
69
  "chalk": "^5.6.2",
70
70
  "es-toolkit": "^1.42.0",
71
71
  "fast-jwt": "^6.1.0",
72
- "fast-xml-parser": "^5.3.2",
72
+ "fast-xml-parser": "^5.3.3",
73
73
  "pathe": "^2.0.3",
74
74
  "pino": "^10.1.0",
75
75
  "pino-roll": "^4.0.0"
76
76
  },
77
- "gitHead": "24f461a1d551e85683b0fa52c34ac06a08e8a057",
77
+ "gitHead": "4b7ea2e7f6d7b5c7454f34c30794473d8bb021de",
78
78
  "devDependencies": {
79
79
  "typescript": "^5.9.3"
80
80
  }
package/router/api.ts CHANGED
@@ -61,16 +61,7 @@ export function apiHandler(apis: Map<string, ApiRoute>, hooks: Hook[], context:
61
61
  }
62
62
  }
63
63
 
64
- // 5. 执行 preprocess 预处理(如果有)
65
- if (ctx.api?.preprocess) {
66
- await ctx.api.preprocess(context, ctx);
67
- // 如果 preprocess 设置了 response,停止执行
68
- if (ctx.response) {
69
- return ctx.response;
70
- }
71
- }
72
-
73
- // 6. 执行 API handler
64
+ // 5. 执行 API handler
74
65
  if (!ctx.api) {
75
66
  if (req.method !== 'OPTIONS') {
76
67
  ctx.response = Response.json(
package/types/api.d.ts CHANGED
@@ -91,12 +91,6 @@ export interface ApiRoute<T = any, R = any> {
91
91
  */
92
92
  rawBody?: boolean;
93
93
 
94
- /** 请求预处理函数(可选,在 handler 之前执行)
95
- * 用于解密、转换请求数据等场景
96
- * 可以修改 ctx.body
97
- */
98
- preprocess?: ApiHandler<T, void>;
99
-
100
94
  /** 缓存配置(可选,单位:秒) */
101
95
  cache?: number;
102
96