befly 3.9.32 → 3.9.34

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/docs/table.md CHANGED
@@ -126,17 +126,17 @@ interface FieldDefinition {
126
126
 
127
127
  ### 可选属性
128
128
 
129
- | 属性 | 类型 | 默认值 | 说明 |
130
- | ---------- | ---------------- | ---------------------------------------------- | ----------------------------------------------------------------------- |
131
- | `detail` | `string` | `''` | 字段详细说明 |
132
- | `min` | `number \| null` | `0` | 最小值(number)或最小长度(string) |
133
- | `max` | `number \| null` | `100` (string) <br> `999999999999999` (number) | 最大值(number)或最大长度(string),number 类型默认为 999999999999999 |
134
- | `default` | `any` | `null` | 默认值 |
135
- | `index` | `boolean` | `false` | 是否创建普通索引 |
136
- | `unique` | `boolean` | `false` | 是否唯一约束 |
137
- | `nullable` | `boolean` | `false` | 是否允许 NULL |
138
- | `unsigned` | `boolean` | `true` | 是否无符号(仅 number 类型有效) |
139
- | `regexp` | `string \| null` | `null` | 正则验证规则(内置或自定义) |
129
+ | 属性 | 类型 | 默认值 | 说明 |
130
+ | ---------- | ---------------- | ----------------------------------------------- | ------------------------------------------------------------------------ |
131
+ | `detail` | `string` | `''` | 字段详细说明 |
132
+ | `min` | `number \| null` | `0` | 最小值(number)或最小长度(string) |
133
+ | `max` | `number \| null` | `100` (string) <br> `9999999999999999` (number) | 最大值(number)或最大长度(string),number 类型默认为 9999999999999999 |
134
+ | `default` | `any` | `null` | 默认值 |
135
+ | `index` | `boolean` | `false` | 是否创建普通索引 |
136
+ | `unique` | `boolean` | `false` | 是否唯一约束 |
137
+ | `nullable` | `boolean` | `false` | 是否允许 NULL |
138
+ | `unsigned` | `boolean` | `true` | 是否无符号(仅 number 类型有效) |
139
+ | `regexp` | `string \| null` | `null` | 正则验证规则(内置或自定义) |
140
140
 
141
141
  ---
142
142
 
@@ -196,7 +196,7 @@ interface FieldDefinition {
196
196
  **约束规则:**
197
197
 
198
198
  - `min` 和 `max` 用于输入验证
199
- - `max` 默认为 `999999999999999`(如未指定或为 null)
199
+ - `max` 默认为 `9999999999999999`(如未指定或为 null)
200
200
  - `unsigned` 默认为 `true`(无符号,仅 MySQL 有效)
201
201
  - 默认值为 `0`
202
202
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.9.32",
3
+ "version": "3.9.34",
4
4
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
5
5
  "type": "module",
6
6
  "private": false,
@@ -74,7 +74,7 @@
74
74
  "pino": "^10.1.0",
75
75
  "pino-roll": "^4.0.0"
76
76
  },
77
- "gitHead": "7287680c89b51f165086410727cd4e769e87cd46",
77
+ "gitHead": "5330df9482c8a640194e7e3dd8f36f2924d0b120",
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(
@@ -77,7 +77,7 @@ export function formatFieldList(fields: string[]): string {
77
77
  export function applyFieldDefaults(fieldDef: any): void {
78
78
  fieldDef.detail = fieldDef.detail ?? '';
79
79
  fieldDef.min = fieldDef.min ?? 0;
80
- fieldDef.max = fieldDef.max ?? (fieldDef.type === 'number' ? 999999999999999 : 100);
80
+ fieldDef.max = fieldDef.max ?? (fieldDef.type === 'number' ? 9999999999999999 : 100);
81
81
  fieldDef.default = fieldDef.default ?? null;
82
82
  fieldDef.index = fieldDef.index ?? false;
83
83
  fieldDef.unique = fieldDef.unique ?? false;
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