befly-shared 1.2.8 → 1.3.1

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 (98) hide show
  1. package/package.json +13 -30
  2. package/utils/arrayToTree.ts +135 -0
  3. package/utils/buildTreeByParentPath.ts +127 -0
  4. package/utils/scanViewsDir.ts +148 -0
  5. package/README.md +0 -439
  6. package/dist/addonHelper.js +0 -83
  7. package/dist/arrayKeysToCamel.js +0 -18
  8. package/dist/arrayToTree.js +0 -23
  9. package/dist/calcPerfTime.js +0 -13
  10. package/dist/configTypes.js +0 -1
  11. package/dist/constants.js +0 -46
  12. package/dist/deepTransformKeys.js +0 -139
  13. package/dist/fieldClear.js +0 -57
  14. package/dist/genShortId.js +0 -12
  15. package/dist/hashPassword.js +0 -22
  16. package/dist/index.js +0 -26
  17. package/dist/keysToCamel.js +0 -21
  18. package/dist/keysToSnake.js +0 -21
  19. package/dist/layouts.js +0 -59
  20. package/dist/pickFields.js +0 -16
  21. package/dist/redisKeys.js +0 -34
  22. package/dist/regex.js +0 -202
  23. package/dist/scanConfig.js +0 -83
  24. package/dist/scanFiles.js +0 -39
  25. package/dist/scanViews.js +0 -48
  26. package/dist/withDefaultColumns.js +0 -32
  27. package/src/addonHelper.ts +0 -88
  28. package/src/arrayKeysToCamel.ts +0 -18
  29. package/src/arrayToTree.ts +0 -31
  30. package/src/calcPerfTime.ts +0 -13
  31. package/src/configTypes.ts +0 -29
  32. package/src/constants.ts +0 -60
  33. package/src/deepTransformKeys.ts +0 -172
  34. package/src/fieldClear.ts +0 -75
  35. package/src/genShortId.ts +0 -12
  36. package/src/hashPassword.ts +0 -27
  37. package/src/index.ts +0 -29
  38. package/src/keysToCamel.ts +0 -22
  39. package/src/keysToSnake.ts +0 -22
  40. package/src/layouts.ts +0 -90
  41. package/src/pickFields.ts +0 -19
  42. package/src/redisKeys.ts +0 -44
  43. package/src/regex.ts +0 -225
  44. package/src/scanConfig.ts +0 -106
  45. package/src/scanFiles.ts +0 -49
  46. package/src/scanViews.ts +0 -55
  47. package/src/withDefaultColumns.ts +0 -36
  48. package/tests/addonHelper.test.ts +0 -55
  49. package/tests/arrayKeysToCamel.test.ts +0 -21
  50. package/tests/arrayToTree.test.ts +0 -98
  51. package/tests/calcPerfTime.test.ts +0 -19
  52. package/tests/deepTransformKeys.test.ts +0 -466
  53. package/tests/fieldClear.test.ts +0 -39
  54. package/tests/keysToCamel.test.ts +0 -22
  55. package/tests/keysToSnake.test.ts +0 -22
  56. package/tests/layouts.test.ts +0 -93
  57. package/tests/pickFields.test.ts +0 -22
  58. package/tests/regex.test.ts +0 -308
  59. package/tests/scanFiles.test.ts +0 -58
  60. package/tests/types.test.ts +0 -289
  61. package/types/addon.d.ts +0 -50
  62. package/types/addonConfigMerge.d.ts +0 -17
  63. package/types/addonHelper.d.ts +0 -24
  64. package/types/api.d.ts +0 -63
  65. package/types/arrayKeysToCamel.d.ts +0 -13
  66. package/types/arrayToTree.d.ts +0 -8
  67. package/types/calcPerfTime.d.ts +0 -4
  68. package/types/common.d.ts +0 -8
  69. package/types/configMerge.d.ts +0 -49
  70. package/types/configTypes.d.ts +0 -28
  71. package/types/constants.d.ts +0 -48
  72. package/types/context.d.ts +0 -38
  73. package/types/crypto.d.ts +0 -23
  74. package/types/database.d.ts +0 -55
  75. package/types/deepTransformKeys.d.ts +0 -84
  76. package/types/fieldClear.d.ts +0 -16
  77. package/types/genShortId.d.ts +0 -10
  78. package/types/hashPassword.d.ts +0 -11
  79. package/types/index.d.ts +0 -23
  80. package/types/jwt.d.ts +0 -99
  81. package/types/keysToCamel.d.ts +0 -10
  82. package/types/keysToSnake.d.ts +0 -10
  83. package/types/layouts.d.ts +0 -29
  84. package/types/loadAndMergeConfig.d.ts +0 -7
  85. package/types/logger.d.ts +0 -22
  86. package/types/menu.d.ts +0 -49
  87. package/types/mergeConfig.d.ts +0 -7
  88. package/types/pickFields.d.ts +0 -4
  89. package/types/redisKeys.d.ts +0 -34
  90. package/types/regex.d.ts +0 -145
  91. package/types/scanConfig.d.ts +0 -7
  92. package/types/scanFiles.d.ts +0 -12
  93. package/types/scanViews.d.ts +0 -11
  94. package/types/table.d.ts +0 -49
  95. package/types/tool.d.ts +0 -67
  96. package/types/types.d.ts +0 -44
  97. package/types/validate.d.ts +0 -69
  98. package/types/withDefaultColumns.d.ts +0 -7
@@ -1,466 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { deepTransformKeys } from '../src/deepTransformKeys';
3
-
4
- describe('deepTransformKeys', () => {
5
- describe('预设转换 - camel', () => {
6
- it('应该转换简单对象的键名为小驼峰', () => {
7
- const input = { user_id: 123, user_name: 'John' };
8
- const expected = { userId: 123, userName: 'John' };
9
- expect(deepTransformKeys(input, 'camel')).toEqual(expected);
10
- });
11
-
12
- it('应该转换嵌套对象的键名为小驼峰', () => {
13
- const input = {
14
- user_id: 123,
15
- user_info: {
16
- first_name: 'John',
17
- last_name: 'Doe'
18
- }
19
- };
20
- const expected = {
21
- userId: 123,
22
- userInfo: {
23
- firstName: 'John',
24
- lastName: 'Doe'
25
- }
26
- };
27
- expect(deepTransformKeys(input, 'camel')).toEqual(expected);
28
- });
29
- });
30
-
31
- describe('预设转换 - snake', () => {
32
- it('应该转换简单对象的键名为下划线', () => {
33
- const input = { userId: 123, userName: 'John' };
34
- const expected = { user_id: 123, user_name: 'John' };
35
- expect(deepTransformKeys(input, 'snake')).toEqual(expected);
36
- });
37
-
38
- it('应该转换嵌套对象的键名为下划线', () => {
39
- const input = {
40
- userId: 123,
41
- userInfo: {
42
- firstName: 'John',
43
- lastName: 'Doe'
44
- }
45
- };
46
- const expected = {
47
- user_id: 123,
48
- user_info: {
49
- first_name: 'John',
50
- last_name: 'Doe'
51
- }
52
- };
53
- expect(deepTransformKeys(input, 'snake')).toEqual(expected);
54
- });
55
- });
56
-
57
- describe('预设转换 - kebab', () => {
58
- it('应该转换简单对象的键名为短横线', () => {
59
- const input = { userId: 123, userName: 'John' };
60
- const expected = { 'user-id': 123, 'user-name': 'John' };
61
- expect(deepTransformKeys(input, 'kebab')).toEqual(expected);
62
- });
63
-
64
- it('应该转换嵌套对象的键名为短横线', () => {
65
- const input = {
66
- userId: 123,
67
- userInfo: {
68
- firstName: 'John',
69
- lastName: 'Doe'
70
- }
71
- };
72
- const expected = {
73
- 'user-id': 123,
74
- 'user-info': {
75
- 'first-name': 'John',
76
- 'last-name': 'Doe'
77
- }
78
- };
79
- expect(deepTransformKeys(input, 'kebab')).toEqual(expected);
80
- });
81
- });
82
-
83
- describe('预设转换 - pascal', () => {
84
- it('应该转换简单对象的键名为大驼峰', () => {
85
- const input = { user_id: 123, user_name: 'John' };
86
- const expected = { UserId: 123, UserName: 'John' };
87
- expect(deepTransformKeys(input, 'pascal')).toEqual(expected);
88
- });
89
-
90
- it('应该转换嵌套对象的键名为大驼峰', () => {
91
- const input = {
92
- user_id: 123,
93
- user_info: {
94
- first_name: 'John'
95
- }
96
- };
97
- const expected = {
98
- UserId: 123,
99
- UserInfo: {
100
- FirstName: 'John'
101
- }
102
- };
103
- expect(deepTransformKeys(input, 'pascal')).toEqual(expected);
104
- });
105
- });
106
-
107
- describe('预设转换 - upper', () => {
108
- it('应该转换简单对象的键名为大写', () => {
109
- const input = { userId: 123, userName: 'John' };
110
- const expected = { USERID: 123, USERNAME: 'John' };
111
- expect(deepTransformKeys(input, 'upper')).toEqual(expected);
112
- });
113
-
114
- it('应该转换嵌套对象的键名为大写', () => {
115
- const input = {
116
- userId: 123,
117
- userInfo: {
118
- firstName: 'John'
119
- }
120
- };
121
- const expected = {
122
- USERID: 123,
123
- USERINFO: {
124
- FIRSTNAME: 'John'
125
- }
126
- };
127
- expect(deepTransformKeys(input, 'upper')).toEqual(expected);
128
- });
129
- });
130
-
131
- describe('预设转换 - lower', () => {
132
- it('应该转换简单对象的键名为小写', () => {
133
- const input = { UserId: 123, UserName: 'John' };
134
- const expected = { userid: 123, username: 'John' };
135
- expect(deepTransformKeys(input, 'lower')).toEqual(expected);
136
- });
137
-
138
- it('应该转换嵌套对象的键名为小写', () => {
139
- const input = {
140
- UserId: 123,
141
- UserInfo: {
142
- FirstName: 'John'
143
- }
144
- };
145
- const expected = {
146
- userid: 123,
147
- userinfo: {
148
- firstname: 'John'
149
- }
150
- };
151
- expect(deepTransformKeys(input, 'lower')).toEqual(expected);
152
- });
153
- });
154
-
155
- describe('自定义转换函数', () => {
156
- it('应该使用自定义函数转换键名为大写', () => {
157
- const input = { user_id: 123, user_name: 'John' };
158
- const expected = { USER_ID: 123, USER_NAME: 'John' };
159
- expect(deepTransformKeys(input, (key) => key.toUpperCase())).toEqual(expected);
160
- });
161
-
162
- it('应该使用自定义函数转换嵌套对象', () => {
163
- const input = {
164
- user_id: 123,
165
- user_info: {
166
- first_name: 'John'
167
- }
168
- };
169
- const expected = {
170
- USER_ID: 123,
171
- USER_INFO: {
172
- FIRST_NAME: 'John'
173
- }
174
- };
175
- expect(deepTransformKeys(input, (key) => key.toUpperCase())).toEqual(expected);
176
- });
177
-
178
- it('应该支持自定义前缀添加', () => {
179
- const input = { id: 1, name: 'test' };
180
- const expected = { prefix_id: 1, prefix_name: 'test' };
181
- expect(deepTransformKeys(input, (key) => `prefix_${key}`)).toEqual(expected);
182
- });
183
- });
184
-
185
- describe('数组处理', () => {
186
- it('应该转换数组中对象的键名', () => {
187
- const input = [
188
- { user_id: 1, user_name: 'Alice' },
189
- { user_id: 2, user_name: 'Bob' }
190
- ];
191
- const expected = [
192
- { userId: 1, userName: 'Alice' },
193
- { userId: 2, userName: 'Bob' }
194
- ];
195
- expect(deepTransformKeys(input, 'camel')).toEqual(expected);
196
- });
197
-
198
- it('应该转换嵌套数组和对象', () => {
199
- const input = {
200
- user_list: [
201
- {
202
- user_id: 1,
203
- user_tags: [
204
- { tag_name: 'vip', tag_level: 5 },
205
- { tag_name: 'active', tag_level: 3 }
206
- ]
207
- }
208
- ]
209
- };
210
- const expected = {
211
- userList: [
212
- {
213
- userId: 1,
214
- userTags: [
215
- { tagName: 'vip', tagLevel: 5 },
216
- { tagName: 'active', tagLevel: 3 }
217
- ]
218
- }
219
- ]
220
- };
221
- expect(deepTransformKeys(input, 'camel')).toEqual(expected);
222
- });
223
- });
224
-
225
- describe('边界情况', () => {
226
- it('应该处理 null 值', () => {
227
- expect(deepTransformKeys(null, 'camel')).toBeNull();
228
- });
229
-
230
- it('应该处理 undefined', () => {
231
- expect(deepTransformKeys(undefined, 'camel')).toBeUndefined();
232
- });
233
-
234
- it('应该处理基本类型', () => {
235
- expect(deepTransformKeys('string', 'camel')).toBe('string');
236
- expect(deepTransformKeys(123, 'camel')).toBe(123);
237
- expect(deepTransformKeys(true, 'camel')).toBe(true);
238
- });
239
-
240
- it('应该处理空对象', () => {
241
- expect(deepTransformKeys({}, 'camel')).toEqual({});
242
- });
243
-
244
- it('应该处理空数组', () => {
245
- expect(deepTransformKeys([], 'camel')).toEqual([]);
246
- });
247
-
248
- it('应该处理混合类型的数组', () => {
249
- const input = [{ user_id: 1 }, 'string', 123, null, { nested_obj: { deep_key: 'value' } }];
250
- const expected = [{ userId: 1 }, 'string', 123, null, { nestedObj: { deepKey: 'value' } }];
251
- expect(deepTransformKeys(input, 'camel')).toEqual(expected);
252
- });
253
-
254
- it('应该处理深层嵌套的结构', () => {
255
- const input = {
256
- level_1: {
257
- level_2: {
258
- level_3: {
259
- deep_key: 'deep_value'
260
- }
261
- }
262
- }
263
- };
264
- const expected = {
265
- level1: {
266
- level2: {
267
- level3: {
268
- deepKey: 'deep_value'
269
- }
270
- }
271
- }
272
- };
273
- expect(deepTransformKeys(input, 'camel')).toEqual(expected);
274
- });
275
- });
276
-
277
- describe('循环引用和深度限制', () => {
278
- it('应该处理循环引用的对象', () => {
279
- const obj: any = { user_id: 1, user_name: 'test' };
280
- obj.self = obj; // 循环引用
281
-
282
- const result = deepTransformKeys(obj, 'camel');
283
-
284
- expect(result.userId).toBe(1);
285
- expect(result.userName).toBe('test');
286
- // 循环引用的部分应该保持原样
287
- expect(result.self).toBe(obj);
288
- });
289
-
290
- it('应该处理循环引用的数组', () => {
291
- const arr: any = [{ user_id: 1 }];
292
- arr.push(arr); // 循环引用
293
-
294
- const result = deepTransformKeys(arr, 'camel');
295
-
296
- expect(result[0]).toEqual({ userId: 1 });
297
- // 循环引用的部分应该保持原样
298
- expect(result[1]).toBe(arr);
299
- });
300
-
301
- it('应该遵守 maxDepth 限制', () => {
302
- const input = {
303
- level_1: {
304
- level_2: {
305
- level_3: {
306
- deep_key: 'value'
307
- }
308
- }
309
- }
310
- };
311
-
312
- // 限制深度为 2
313
- const result = deepTransformKeys(input, 'camel', { maxDepth: 2 });
314
-
315
- expect(result.level1).toBeDefined();
316
- expect(result.level1.level2).toBeDefined();
317
- // 第 3 层应该保持原样
318
- expect(result.level1.level2.level_3).toBeDefined();
319
- expect(result.level1.level2.level_3.deep_key).toBe('value');
320
- });
321
-
322
- it('应该在深度为 1 时只转换第一层', () => {
323
- const input = {
324
- user_id: 1,
325
- user_info: {
326
- first_name: 'John'
327
- }
328
- };
329
-
330
- const result = deepTransformKeys(input, 'camel', { maxDepth: 1 });
331
-
332
- expect(result.userId).toBe(1);
333
- // 第二层应该保持原样
334
- expect(result.userInfo.first_name).toBe('John');
335
- });
336
-
337
- it('maxDepth 为 0 时不限制深度', () => {
338
- const input = {
339
- l1: { l2: { l3: { l4: { l5: { deep_key: 'value' } } } } }
340
- };
341
-
342
- const result = deepTransformKeys(input, 'camel', { maxDepth: 0 });
343
-
344
- expect(result.l1.l2.l3.l4.l5.deepKey).toBe('value');
345
- });
346
-
347
- it('默认 maxDepth 应该足够处理常见深度', () => {
348
- // 创建 50 层深度的对象(小于默认的 100)
349
- let obj: any = { deep_key: 'value' };
350
- for (let i = 0; i < 49; i++) {
351
- obj = { nested_obj: obj };
352
- }
353
-
354
- const result = deepTransformKeys(obj, 'camel');
355
-
356
- // 应该能完全转换
357
- let current = result;
358
- for (let i = 0; i < 49; i++) {
359
- expect(current.nestedObj).toBeDefined();
360
- current = current.nestedObj;
361
- }
362
- expect(current.deepKey).toBe('value');
363
- });
364
- });
365
-
366
- describe('排除键名功能', () => {
367
- it('应该排除指定的键名不转换', () => {
368
- const input = { _id: '123', user_id: 456, user_name: 'John' };
369
- const result = deepTransformKeys(input, 'camel', { excludeKeys: ['_id'] });
370
-
371
- expect(result._id).toBe('123');
372
- expect(result.userId).toBe(456);
373
- expect(result.userName).toBe('John');
374
- });
375
-
376
- it('应该排除嵌套对象中的指定键名', () => {
377
- const input = {
378
- _id: '123',
379
- user_id: 456,
380
- user_info: {
381
- _id: '789',
382
- first_name: 'John',
383
- __v: 1
384
- }
385
- };
386
- const result = deepTransformKeys(input, 'camel', { excludeKeys: ['_id', '__v'] });
387
-
388
- expect(result._id).toBe('123');
389
- expect(result.userId).toBe(456);
390
- expect(result.userInfo._id).toBe('789');
391
- expect(result.userInfo.firstName).toBe('John');
392
- expect(result.userInfo.__v).toBe(1);
393
- });
394
-
395
- it('应该排除数组中对象的指定键名', () => {
396
- const input = [
397
- { _id: '1', user_name: 'Alice' },
398
- { _id: '2', user_name: 'Bob' }
399
- ];
400
- const result = deepTransformKeys(input, 'camel', { excludeKeys: ['_id'] });
401
-
402
- expect(result[0]._id).toBe('1');
403
- expect(result[0].userName).toBe('Alice');
404
- expect(result[1]._id).toBe('2');
405
- expect(result[1].userName).toBe('Bob');
406
- });
407
-
408
- it('应该支持多个排除键名', () => {
409
- const input = {
410
- _id: '123',
411
- __v: 1,
412
- created_at: Date.now(),
413
- user_id: 456,
414
- user_name: 'John'
415
- };
416
- const result = deepTransformKeys(input, 'camel', {
417
- excludeKeys: ['_id', '__v', 'created_at']
418
- });
419
-
420
- expect(result._id).toBe('123');
421
- expect(result.__v).toBe(1);
422
- expect(result.created_at).toBe(input.created_at);
423
- expect(result.userId).toBe(456);
424
- expect(result.userName).toBe('John');
425
- });
426
-
427
- it('排除键名不存在时应该正常转换', () => {
428
- const input = { user_id: 1, user_name: 'test' };
429
- const result = deepTransformKeys(input, 'camel', {
430
- excludeKeys: ['_id', 'non_existent']
431
- });
432
-
433
- expect(result.userId).toBe(1);
434
- expect(result.userName).toBe('test');
435
- });
436
-
437
- it('空排除列表应该正常转换所有键', () => {
438
- const input = { user_id: 1, user_name: 'test' };
439
- const result = deepTransformKeys(input, 'camel', { excludeKeys: [] });
440
-
441
- expect(result.userId).toBe(1);
442
- expect(result.userName).toBe('test');
443
- });
444
-
445
- it('应该结合深度限制和排除键名使用', () => {
446
- const input = {
447
- _id: '123',
448
- user_info: {
449
- _id: '456',
450
- nested: {
451
- deep_key: 'value'
452
- }
453
- }
454
- };
455
- const result = deepTransformKeys(input, 'camel', {
456
- maxDepth: 2,
457
- excludeKeys: ['_id']
458
- });
459
-
460
- expect(result._id).toBe('123');
461
- expect(result.userInfo._id).toBe('456');
462
- // 深度限制,第三层保持原样
463
- expect(result.userInfo.nested.deep_key).toBe('value');
464
- });
465
- });
466
- });
@@ -1,39 +0,0 @@
1
- import { test, expect } from 'bun:test';
2
- import { fieldClear } from '../src/fieldClear';
3
- import type { FieldClearOptions } from '../types/fieldClear';
4
-
5
- test('对象 pick/omit', () => {
6
- const obj = { a: 1, b: 2, c: 3 };
7
- const options: FieldClearOptions = { pickKeys: ['a', 'c'] };
8
- expect(fieldClear(obj, options)).toEqual({ a: 1, c: 3 });
9
- });
10
-
11
- test('数组 keepValues/excludeValues', () => {
12
- const arr = [
13
- { a: 1, b: 2 },
14
- { a: 3, b: 4 },
15
- { a: 5, b: 6 }
16
- ];
17
- const options: FieldClearOptions = { keepValues: [1, 5] };
18
- expect(fieldClear(arr, options)).toEqual([{ a: 1 }, { a: 5 }]);
19
- });
20
-
21
- test('空对象和空数组', () => {
22
- expect(fieldClear({}, {})).toEqual({});
23
- expect(fieldClear([], {})).toEqual([]);
24
- });
25
-
26
- test('原始值直接返回', () => {
27
- expect(fieldClear(123, {})).toBe(123);
28
- });
29
-
30
- test('should support keepMap to force keep values', () => {
31
- const obj = { a: 1, b: null, c: 0 };
32
- const options: FieldClearOptions = {
33
- excludeValues: [null, 0],
34
- keepMap: { c: 0 }
35
- };
36
- // c=0 is in excludeValues but also in keepMap, so it should be kept
37
- // b=null is in excludeValues and NOT in keepMap, so it should be excluded
38
- expect(fieldClear(obj, options)).toEqual({ a: 1, c: 0 });
39
- });
@@ -1,22 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { keysToCamel } from '../src/keysToCamel';
3
-
4
- describe('keysToCamel', () => {
5
- test('should convert keys to camelCase', () => {
6
- const input = { user_id: 123, user_name: 'John' };
7
- const expected = { userId: 123, userName: 'John' };
8
- expect(keysToCamel(input)).toEqual(expected);
9
- });
10
-
11
- test('should handle nested objects (shallow)', () => {
12
- const input = { user_info: { first_name: 'John' } };
13
- const expected = { userInfo: { first_name: 'John' } };
14
- expect(keysToCamel(input)).toEqual(expected);
15
- });
16
-
17
- test('should return original if not plain object', () => {
18
- expect(keysToCamel(null as any)).toBeNull();
19
- expect(keysToCamel(undefined as any)).toBeUndefined();
20
- expect(keysToCamel('string' as any)).toBe('string');
21
- });
22
- });
@@ -1,22 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { keysToSnake } from '../src/keysToSnake';
3
-
4
- describe('keysToSnake', () => {
5
- test('should convert keys to snake_case', () => {
6
- const input = { userId: 123, userName: 'John' };
7
- const expected = { user_id: 123, user_name: 'John' };
8
- expect(keysToSnake(input)).toEqual(expected);
9
- });
10
-
11
- test('should handle nested objects (shallow)', () => {
12
- const input = { userInfo: { firstName: 'John' } };
13
- const expected = { user_info: { firstName: 'John' } };
14
- expect(keysToSnake(input)).toEqual(expected);
15
- });
16
-
17
- test('should return original if not plain object', () => {
18
- expect(keysToSnake(null as any)).toBeNull();
19
- expect(keysToSnake(undefined as any)).toBeUndefined();
20
- expect(keysToSnake('string' as any)).toBe('string');
21
- });
22
- });
@@ -1,93 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { Layouts, type RouteConfig } from '../src/layouts';
3
-
4
- describe('Layouts', () => {
5
- it('should handle simple routes with default layout', () => {
6
- const routes: RouteConfig[] = [{ path: 'home', component: 'HomeComponent' }];
7
- const result = Layouts(routes);
8
- expect(result).toEqual([{ path: 'home', layoutName: 'default', component: 'HomeComponent', meta: undefined }]);
9
- });
10
-
11
- it('should handle routes with specified layout suffix', () => {
12
- const routes: RouteConfig[] = [{ path: 'login_1', component: 'LoginComponent' }];
13
- const result = Layouts(routes);
14
- expect(result).toEqual([{ path: 'login', layoutName: '1', component: 'LoginComponent', meta: undefined }]);
15
- });
16
-
17
- it('should handle index routes correctly', () => {
18
- const routes: RouteConfig[] = [{ path: 'index', component: 'IndexComponent' }];
19
- const result = Layouts(routes);
20
- expect(result).toEqual([{ path: '', layoutName: 'default', component: 'IndexComponent', meta: undefined }]);
21
- });
22
-
23
- it('should handle index routes with layout suffix', () => {
24
- const routes: RouteConfig[] = [{ path: 'index_2', component: 'IndexComponent' }];
25
- const result = Layouts(routes);
26
- expect(result).toEqual([{ path: '', layoutName: '2', component: 'IndexComponent', meta: undefined }]);
27
- });
28
-
29
- it('should handle nested routes and inherit layout', () => {
30
- const routes: RouteConfig[] = [
31
- {
32
- path: 'admin_3',
33
- children: [
34
- { path: 'dashboard', component: 'DashboardComponent' },
35
- { path: 'settings_4', component: 'SettingsComponent' }
36
- ]
37
- }
38
- ];
39
- const result = Layouts(routes);
40
- expect(result).toHaveLength(2);
41
-
42
- // Inherited layout '3'
43
- expect(result[0]).toEqual({
44
- path: 'admin/dashboard',
45
- layoutName: '3',
46
- component: 'DashboardComponent',
47
- meta: undefined
48
- });
49
-
50
- // Overridden layout '4'
51
- expect(result[1]).toEqual({
52
- path: 'admin/settings',
53
- layoutName: '4',
54
- component: 'SettingsComponent',
55
- meta: undefined
56
- });
57
- });
58
-
59
- it('should handle deep nesting', () => {
60
- const routes: RouteConfig[] = [
61
- {
62
- path: 'a_1',
63
- children: [
64
- {
65
- path: 'b',
66
- children: [{ path: 'c', component: 'CComponent' }]
67
- }
68
- ]
69
- }
70
- ];
71
- const result = Layouts(routes);
72
- expect(result).toEqual([{ path: 'a/b/c', layoutName: '1', component: 'CComponent', meta: undefined }]);
73
- });
74
-
75
- it('should handle path cleaning correctly', () => {
76
- const routes: RouteConfig[] = [
77
- {
78
- path: 'users_5',
79
- children: [
80
- { path: 'list', component: 'ListComponent' },
81
- { path: 'detail_6', component: 'DetailComponent' }
82
- ]
83
- }
84
- ];
85
- const result = Layouts(routes);
86
-
87
- expect(result[0].path).toBe('users/list');
88
- expect(result[0].layoutName).toBe('5');
89
-
90
- expect(result[1].path).toBe('users/detail');
91
- expect(result[1].layoutName).toBe('6');
92
- });
93
- });
@@ -1,22 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { pickFields } from '../src/pickFields';
3
-
4
- describe('pickFields', () => {
5
- test('should pick specified fields', () => {
6
- const input = { a: 1, b: 2, c: 3 };
7
- const keys = ['a', 'c'];
8
- const expected = { a: 1, c: 3 };
9
- expect(pickFields(input, keys)).toEqual(expected);
10
- });
11
-
12
- test('should ignore non-existent keys', () => {
13
- const input = { a: 1 };
14
- const keys = ['a', 'b'];
15
- const expected = { a: 1 };
16
- expect(pickFields(input, keys)).toEqual(expected);
17
- });
18
-
19
- test('should return empty object for invalid input', () => {
20
- expect(pickFields(null as any, ['a'])).toEqual({});
21
- });
22
- });