befly 3.8.6 → 3.8.8

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.
Files changed (2) hide show
  1. package/check.ts +29 -33
  2. package/package.json +2 -2
package/check.ts CHANGED
@@ -5,10 +5,10 @@
5
5
 
6
6
  import { basename, relative } from 'pathe';
7
7
  import { join } from 'node:path';
8
- import { existsSync } from 'node:fs';
8
+ import { existsSync, mkdirSync } from 'node:fs';
9
9
  import { isPlainObject } from 'es-toolkit/compat';
10
10
  import { Logger } from './lib/logger.js';
11
- import { projectTableDir, projectApiDir } from './paths.js';
11
+ import { projectTableDir, projectApiDir, projectDir } from './paths.js';
12
12
  import { scanAddons, getAddonDir, addonDirExists } from './util.js';
13
13
  import type { FieldDefinition } from './types/common.d.ts';
14
14
 
@@ -127,7 +127,7 @@ export const checkTable = async function (): Promise<boolean> {
127
127
  // 直接使用字段对象
128
128
  const field = fieldDef as FieldDefinition;
129
129
 
130
- // 检查必填字段:name, type, min, max
130
+ // 检查必填字段:name, type
131
131
  if (!field.name || typeof field.name !== 'string') {
132
132
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 缺少必填字段 name 或类型错误`);
133
133
  continue;
@@ -136,16 +136,14 @@ export const checkTable = async function (): Promise<boolean> {
136
136
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 缺少必填字段 type 或类型错误`);
137
137
  continue;
138
138
  }
139
- if (field.min === undefined) {
140
- Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 缺少必填字段 min`);
141
- continue;
142
- }
143
- if (field.max === undefined) {
144
- Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 缺少必填字段 max`);
145
- continue;
146
- }
147
139
 
148
140
  // 检查可选字段的类型
141
+ if (field.min !== undefined && !(field.min === null || typeof field.min === 'number')) {
142
+ Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 字段 min 类型错误,必须为 null 或数字`);
143
+ }
144
+ if (field.max !== undefined && !(field.max === null || typeof field.max === 'number')) {
145
+ Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 字段 max 类型错误,必须为 null 或数字`);
146
+ }
149
147
  if (field.detail !== undefined && typeof field.detail !== 'string') {
150
148
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 字段 detail 类型错误,必须为字符串`);
151
149
  }
@@ -165,49 +163,41 @@ export const checkTable = async function (): Promise<boolean> {
165
163
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 字段 regexp 类型错误,必须为 null 或字符串`);
166
164
  }
167
165
 
168
- const { name: fieldName, type: fieldType, min: fieldMin, max: fieldMax, default: fieldDefault, index: fieldIndex, regexp: fieldRegexp } = field;
166
+ const { name: fieldName, type: fieldType, min: fieldMin, max: fieldMax, default: fieldDefault } = field;
169
167
 
170
- // 第1个值:名称必须为中文、数字、字母、下划线、短横线、空格
168
+ // 字段名称必须为中文、数字、字母、下划线、短横线、空格
171
169
  if (!FIELD_NAME_REGEX.test(fieldName)) {
172
170
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 字段名称 "${fieldName}" 格式错误,` + `必须为中文、数字、字母、下划线、短横线、空格`);
173
171
  }
174
172
 
175
- // 第2个值:字段类型必须为string,number,text,array_string,array_text之一
173
+ // 字段类型必须为string,number,text,array_string,array_text之一
176
174
  if (!FIELD_TYPES.includes(fieldType as any)) {
177
175
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 字段类型 "${fieldType}" 格式错误,` + `必须为${FIELD_TYPES.join('、')}之一`);
178
176
  }
179
177
 
180
- // 第3/4个值:需要是 null 或 数字
181
- if (!(fieldMin === null || typeof fieldMin === 'number')) {
182
- Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 最小值 "${fieldMin}" 格式错误,必须为null或数字`);
183
- }
184
- if (!(fieldMax === null || typeof fieldMax === 'number')) {
185
- Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 最大值 "${fieldMax}" 格式错误,必须为null或数字`);
186
- }
187
-
188
178
  // 约束:当最小值与最大值均为数字时,要求最小值 <= 最大值
189
- if (fieldMin !== null && fieldMax !== null) {
179
+ if (fieldMin !== undefined && fieldMax !== undefined && fieldMin !== null && fieldMax !== null) {
190
180
  if (fieldMin > fieldMax) {
191
181
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 最小值 "${fieldMin}" 不能大于最大值 "${fieldMax}"`);
192
182
  }
193
183
  }
194
184
 
195
- // 第4个值与类型联动校验 + 默认值规则
185
+ // 类型联动校验 + 默认值规则
196
186
  if (fieldType === 'text') {
197
- // text:min/max 必须为 null,默认值必须为 null
198
- if (fieldMin !== null) {
199
- Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 的 text 类型最小值必须为 null,当前为 "${fieldMin}"`);
187
+ // text:min/max 应该为 null,默认值必须为 null
188
+ if (fieldMin !== undefined && fieldMin !== null) {
189
+ Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 的 text 类型最小值应为 null,当前为 "${fieldMin}"`);
200
190
  }
201
- if (fieldMax !== null) {
202
- Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 的 text 类型最大长度必须为 null,当前为 "${fieldMax}"`);
191
+ if (fieldMax !== undefined && fieldMax !== null) {
192
+ Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 的 text 类型最大长度应为 null,当前为 "${fieldMax}"`);
203
193
  }
204
- if (fieldDefault !== null) {
194
+ if (fieldDefault !== undefined && fieldDefault !== null) {
205
195
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 为 text 类型,默认值必须为 null,当前为 "${fieldDefault}"`);
206
196
  }
207
- } else if (fieldType === 'string' || fieldType === 'array') {
208
- if (fieldMax === null || typeof fieldMax !== 'number') {
197
+ } else if (fieldType === 'string' || fieldType === 'array_string') {
198
+ if (fieldMax !== undefined && (fieldMax === null || typeof fieldMax !== 'number')) {
209
199
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 为 ${fieldType} 类型,` + `最大长度必须为数字,当前为 "${fieldMax}"`);
210
- } else if (fieldMax > MAX_VARCHAR_LENGTH) {
200
+ } else if (fieldMax !== undefined && fieldMax > MAX_VARCHAR_LENGTH) {
211
201
  Logger.warn(`${item.typeName}表 ${fileName} 文件 ${colKey} 最大长度 ${fieldMax} 越界,` + `${fieldType} 类型长度必须在 1..${MAX_VARCHAR_LENGTH} 范围内`);
212
202
  }
213
203
  } else if (fieldType === 'number') {
@@ -337,6 +327,12 @@ export const checkApp = async function (): Promise<boolean> {
337
327
  }
338
328
  }
339
329
 
330
+ // 检查并创建 logs 目录
331
+ const logsDir = join(projectDir, 'logs');
332
+ if (!existsSync(logsDir)) {
333
+ mkdirSync(logsDir, { recursive: true });
334
+ }
335
+
340
336
  return true;
341
337
  } catch (error: any) {
342
338
  Logger.error('项目结构检查过程中出错', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.8.6",
3
+ "version": "3.8.8",
4
4
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
5
5
  "type": "module",
6
6
  "private": false,
@@ -69,5 +69,5 @@
69
69
  "es-toolkit": "^1.41.0",
70
70
  "pathe": "^2.0.3"
71
71
  },
72
- "gitHead": "42f9c0610527778b7d25678762360e1782cbec7f"
72
+ "gitHead": "c8c0c2b5e7905cf3a01b77fd3d87b8f225fa9254"
73
73
  }