befly 3.10.0 → 3.10.2

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 (79) hide show
  1. package/.gitignore +0 -0
  2. package/README.md +10 -13
  3. package/configs/presetFields.ts +10 -0
  4. package/configs/presetRegexp.ts +225 -0
  5. package/docs/README.md +17 -11
  6. package/docs/api/api.md +15 -1
  7. package/docs/guide/quickstart.md +19 -5
  8. package/docs/infra/redis.md +23 -11
  9. package/docs/quickstart.md +5 -335
  10. package/docs/reference/addon.md +0 -15
  11. package/docs/reference/config.md +1 -1
  12. package/docs/reference/logger.md +3 -3
  13. package/docs/reference/sync.md +99 -73
  14. package/docs/reference/table.md +1 -1
  15. package/package.json +15 -16
  16. package/docs/cipher.md +0 -582
  17. package/docs/database.md +0 -1176
  18. package/tests/_mocks/mockSqliteDb.ts +0 -204
  19. package/tests/addonHelper-cache.test.ts +0 -32
  20. package/tests/api-integration-array-number.test.ts +0 -282
  21. package/tests/apiHandler-routePath-only.test.ts +0 -32
  22. package/tests/befly-config-env.test.ts +0 -78
  23. package/tests/cacheHelper.test.ts +0 -323
  24. package/tests/cacheKeys.test.ts +0 -41
  25. package/tests/checkApi-routePath-strict.test.ts +0 -166
  26. package/tests/checkMenu.test.ts +0 -346
  27. package/tests/checkTable-smoke.test.ts +0 -157
  28. package/tests/cipher.test.ts +0 -249
  29. package/tests/dbDialect-cache.test.ts +0 -23
  30. package/tests/dbDialect.test.ts +0 -46
  31. package/tests/dbHelper-advanced.test.ts +0 -723
  32. package/tests/dbHelper-all-array-types.test.ts +0 -316
  33. package/tests/dbHelper-array-serialization.test.ts +0 -258
  34. package/tests/dbHelper-batch-write.test.ts +0 -90
  35. package/tests/dbHelper-columns.test.ts +0 -234
  36. package/tests/dbHelper-execute.test.ts +0 -187
  37. package/tests/dbHelper-joins.test.ts +0 -221
  38. package/tests/fields-redis-cache.test.ts +0 -127
  39. package/tests/fields-validate.test.ts +0 -99
  40. package/tests/fixtures/scanFilesAddon/node_modules/@befly-addon/demo/apis/sub/b.ts +0 -3
  41. package/tests/fixtures/scanFilesApis/a.ts +0 -3
  42. package/tests/fixtures/scanFilesApis/sub/b.ts +0 -3
  43. package/tests/getClientIp.test.ts +0 -54
  44. package/tests/integration.test.ts +0 -189
  45. package/tests/jwt.test.ts +0 -65
  46. package/tests/loadPlugins-order-smoke.test.ts +0 -75
  47. package/tests/logger.test.ts +0 -325
  48. package/tests/redisHelper.test.ts +0 -495
  49. package/tests/redisKeys.test.ts +0 -9
  50. package/tests/scanConfig.test.ts +0 -144
  51. package/tests/scanFiles-routePath.test.ts +0 -46
  52. package/tests/smoke-sql.test.ts +0 -24
  53. package/tests/sqlBuilder-advanced.test.ts +0 -608
  54. package/tests/sqlBuilder.test.ts +0 -209
  55. package/tests/sync-connection.test.ts +0 -183
  56. package/tests/sync-init-guard.test.ts +0 -105
  57. package/tests/syncApi-insBatch-fields-consistent.test.ts +0 -61
  58. package/tests/syncApi-obsolete-records.test.ts +0 -69
  59. package/tests/syncApi-type-compat.test.ts +0 -72
  60. package/tests/syncDev-permissions.test.ts +0 -81
  61. package/tests/syncMenu-disableMenus-hard-delete.test.ts +0 -88
  62. package/tests/syncMenu-duplicate-path.test.ts +0 -122
  63. package/tests/syncMenu-obsolete-records.test.ts +0 -161
  64. package/tests/syncMenu-parentPath-from-tree.test.ts +0 -75
  65. package/tests/syncMenu-paths.test.ts +0 -59
  66. package/tests/syncTable-apply.test.ts +0 -279
  67. package/tests/syncTable-array-number.test.ts +0 -160
  68. package/tests/syncTable-constants.test.ts +0 -101
  69. package/tests/syncTable-db-integration.test.ts +0 -237
  70. package/tests/syncTable-ddl.test.ts +0 -245
  71. package/tests/syncTable-helpers.test.ts +0 -99
  72. package/tests/syncTable-schema.test.ts +0 -99
  73. package/tests/syncTable-testkit.test.ts +0 -25
  74. package/tests/syncTable-types.test.ts +0 -122
  75. package/tests/tableRef-and-deserialize.test.ts +0 -67
  76. package/tests/util.test.ts +0 -100
  77. package/tests/validator-array-number.test.ts +0 -310
  78. package/tests/validator-default.test.ts +0 -373
  79. package/tests/validator.test.ts +0 -679
@@ -1,373 +0,0 @@
1
- /**
2
- * 测试 Validator 的默认值处理逻辑
3
- */
4
-
5
- import type { FieldDefinition } from "befly/types/validate";
6
-
7
- import { describe, expect, test } from "bun:test";
8
-
9
- import { Validator } from "../lib/validator.js";
10
-
11
- describe("Validator - 默认值处理逻辑", () => {
12
- // ==================== number 类型默认值 ====================
13
-
14
- test("number: 无 default 时返回 0", () => {
15
- const field: FieldDefinition = {
16
- name: "数字",
17
- type: "number",
18
- min: null,
19
- max: null,
20
- default: null,
21
- regexp: null
22
- };
23
-
24
- const result = Validator.single(undefined, field);
25
- expect(result.error).toBeNull();
26
- expect(result.value).toBe(0);
27
- });
28
-
29
- test("number: 有 default 时返回自定义值", () => {
30
- const field: FieldDefinition = {
31
- name: "数字",
32
- type: "number",
33
- min: null,
34
- max: null,
35
- default: 100,
36
- regexp: null
37
- };
38
-
39
- const result = Validator.single(undefined, field);
40
- expect(result.error).toBeNull();
41
- expect(result.value).toBe(100);
42
- });
43
-
44
- test("number: default 为字符串时自动转换", () => {
45
- const field: FieldDefinition = {
46
- name: "数字",
47
- type: "number",
48
- min: null,
49
- max: null,
50
- default: "999",
51
- regexp: null
52
- };
53
-
54
- const result = Validator.single(null, field);
55
- expect(result.error).toBeNull();
56
- expect(result.value).toBe(999);
57
- });
58
-
59
- test("number: default 为无效字符串时返回 0", () => {
60
- const field: FieldDefinition = {
61
- name: "数字",
62
- type: "number",
63
- min: null,
64
- max: null,
65
- default: "invalid",
66
- regexp: null
67
- };
68
-
69
- const result = Validator.single(undefined, field);
70
- expect(result.error).toBeNull();
71
- expect(result.value).toBe(0);
72
- });
73
-
74
- // ==================== string 类型默认值 ====================
75
-
76
- test("string: 无 default 时返回空字符串", () => {
77
- const field: FieldDefinition = {
78
- name: "字符串",
79
- type: "string",
80
- min: null,
81
- max: null,
82
- default: null,
83
- regexp: null
84
- };
85
-
86
- const result = Validator.single(undefined, field);
87
- expect(result.error).toBeNull();
88
- expect(result.value).toBe("");
89
- });
90
-
91
- test("string: 有 default 时返回自定义值", () => {
92
- const field: FieldDefinition = {
93
- name: "字符串",
94
- type: "string",
95
- min: null,
96
- max: null,
97
- default: "admin",
98
- regexp: null
99
- };
100
-
101
- const result = Validator.single(undefined, field);
102
- expect(result.error).toBeNull();
103
- expect(result.value).toBe("admin");
104
- });
105
-
106
- // ==================== text 类型默认值 ====================
107
-
108
- test("text: 无 default 时返回空字符串", () => {
109
- const field: FieldDefinition = {
110
- name: "文本",
111
- type: "text",
112
- min: null,
113
- max: null,
114
- default: null,
115
- regexp: null
116
- };
117
-
118
- const result = Validator.single(undefined, field);
119
- expect(result.error).toBeNull();
120
- expect(result.value).toBe("");
121
- });
122
-
123
- test("text: 有 default 时返回自定义值", () => {
124
- const field: FieldDefinition = {
125
- name: "文本",
126
- type: "text",
127
- min: null,
128
- max: null,
129
- default: "这是长文本内容",
130
- regexp: null
131
- };
132
-
133
- const result = Validator.single(null, field);
134
- expect(result.error).toBeNull();
135
- expect(result.value).toBe("这是长文本内容");
136
- });
137
-
138
- // ==================== array_string 类型默认值 ====================
139
-
140
- test("array_string: 无 default 时返回空数组", () => {
141
- const field: FieldDefinition = {
142
- name: "字符串数组",
143
- type: "array_string",
144
- min: null,
145
- max: null,
146
- default: null,
147
- regexp: null
148
- };
149
-
150
- const result = Validator.single(undefined, field);
151
- expect(result.error).toBeNull();
152
- expect(result.value).toEqual([]);
153
- });
154
-
155
- test("array_string: 有 default 时返回自定义数组", () => {
156
- const field: FieldDefinition = {
157
- name: "字符串数组",
158
- type: "array_string",
159
- min: null,
160
- max: null,
161
- default: ["a", "b", "c"],
162
- regexp: null
163
- };
164
-
165
- const result = Validator.single(undefined, field);
166
- expect(result.error).toBeNull();
167
- expect(result.value).toEqual(["a", "b", "c"]);
168
- });
169
-
170
- test('array_string: default 为字符串 "[]" 时返回空数组', () => {
171
- const field: FieldDefinition = {
172
- name: "字符串数组",
173
- type: "array_string",
174
- min: null,
175
- max: null,
176
- default: "[]",
177
- regexp: null
178
- };
179
-
180
- const result = Validator.single(null, field);
181
- expect(result.error).toBeNull();
182
- expect(result.value).toEqual([]);
183
- });
184
-
185
- test("array_string: default 为 JSON 字符串时解析为数组", () => {
186
- const field: FieldDefinition = {
187
- name: "字符串数组",
188
- type: "array_string",
189
- min: null,
190
- max: null,
191
- default: '["x", "y", "z"]',
192
- regexp: null
193
- };
194
-
195
- const result = Validator.single(undefined, field);
196
- expect(result.error).toBeNull();
197
- expect(result.value).toEqual(["x", "y", "z"]);
198
- });
199
-
200
- test("array_string: default 为无效 JSON 时返回空数组", () => {
201
- const field: FieldDefinition = {
202
- name: "字符串数组",
203
- type: "array_string",
204
- min: null,
205
- max: null,
206
- default: "invalid-json",
207
- regexp: null
208
- };
209
-
210
- const result = Validator.single(null, field);
211
- expect(result.error).toBeNull();
212
- expect(result.value).toEqual([]);
213
- });
214
-
215
- // ==================== array_text 类型默认值 ====================
216
-
217
- test("array_text: 无 default 时返回空数组", () => {
218
- const field: FieldDefinition = {
219
- name: "文本数组",
220
- type: "array_text",
221
- min: null,
222
- max: null,
223
- default: null,
224
- regexp: null
225
- };
226
-
227
- const result = Validator.single(undefined, field);
228
- expect(result.error).toBeNull();
229
- expect(result.value).toEqual([]);
230
- });
231
-
232
- test("array_text: 有 default 时返回自定义数组", () => {
233
- const field: FieldDefinition = {
234
- name: "文本数组",
235
- type: "array_text",
236
- min: null,
237
- max: null,
238
- default: ["长文本1", "长文本2"],
239
- regexp: null
240
- };
241
-
242
- const result = Validator.single(null, field);
243
- expect(result.error).toBeNull();
244
- expect(result.value).toEqual(["长文本1", "长文本2"]);
245
- });
246
-
247
- // ==================== 空值处理测试 ====================
248
-
249
- test("undefined 应使用默认值", () => {
250
- const field: FieldDefinition = {
251
- name: "测试",
252
- type: "string",
253
- min: null,
254
- max: null,
255
- default: "test",
256
- regexp: null
257
- };
258
-
259
- const result = Validator.single(undefined, field);
260
- expect(result.error).toBeNull();
261
- expect(result.value).toBe("test");
262
- });
263
-
264
- test("null 应使用默认值", () => {
265
- const field: FieldDefinition = {
266
- name: "测试",
267
- type: "number",
268
- min: null,
269
- max: null,
270
- default: 999,
271
- regexp: null
272
- };
273
-
274
- const result = Validator.single(null, field);
275
- expect(result.error).toBeNull();
276
- expect(result.value).toBe(999);
277
- });
278
-
279
- test("空字符串应使用默认值", () => {
280
- const field: FieldDefinition = {
281
- name: "测试",
282
- type: "string",
283
- min: null,
284
- max: null,
285
- default: "fallback",
286
- regexp: null
287
- };
288
-
289
- const result = Validator.single("", field);
290
- expect(result.error).toBeNull();
291
- expect(result.value).toBe("fallback");
292
- });
293
-
294
- // ==================== 默认值优先级测试 ====================
295
-
296
- test("字段 default 应覆盖类型默认值(number)", () => {
297
- const fieldWithDefault: FieldDefinition = {
298
- name: "数字",
299
- type: "number",
300
- min: null,
301
- max: null,
302
- default: 888,
303
- regexp: null
304
- };
305
-
306
- const fieldWithoutDefault: FieldDefinition = {
307
- name: "数字",
308
- type: "number",
309
- min: null,
310
- max: null,
311
- default: null,
312
- regexp: null
313
- };
314
-
315
- const result1 = Validator.single(undefined, fieldWithDefault);
316
- expect(result1.value).toBe(888); // 使用字段 default
317
-
318
- const result2 = Validator.single(undefined, fieldWithoutDefault);
319
- expect(result2.value).toBe(0); // 使用类型默认值
320
- });
321
-
322
- test("字段 default 应覆盖类型默认值(string)", () => {
323
- const fieldWithDefault: FieldDefinition = {
324
- name: "字符串",
325
- type: "string",
326
- min: null,
327
- max: null,
328
- default: "custom",
329
- regexp: null
330
- };
331
-
332
- const fieldWithoutDefault: FieldDefinition = {
333
- name: "字符串",
334
- type: "string",
335
- min: null,
336
- max: null,
337
- default: null,
338
- regexp: null
339
- };
340
-
341
- const result1 = Validator.single(undefined, fieldWithDefault);
342
- expect(result1.value).toBe("custom"); // 使用字段 default
343
-
344
- const result2 = Validator.single(undefined, fieldWithoutDefault);
345
- expect(result2.value).toBe(""); // 使用类型默认值
346
- });
347
-
348
- test("字段 default 应覆盖类型默认值(array)", () => {
349
- const fieldWithDefault: FieldDefinition = {
350
- name: "数组",
351
- type: "array_number_string",
352
- min: null,
353
- max: null,
354
- default: [1, 2, 3],
355
- regexp: null
356
- };
357
-
358
- const fieldWithoutDefault: FieldDefinition = {
359
- name: "数组",
360
- type: "array_number_string",
361
- min: null,
362
- max: null,
363
- default: null,
364
- regexp: null
365
- };
366
-
367
- const result1 = Validator.single(undefined, fieldWithDefault);
368
- expect(result1.value).toEqual([1, 2, 3]); // 使用字段 default
369
-
370
- const result2 = Validator.single(undefined, fieldWithoutDefault);
371
- expect(result2.value).toEqual([]); // 使用类型默认值
372
- });
373
- });