adminforth 1.3.42 → 1.3.44

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.
@@ -125,6 +125,12 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
125
125
 
126
126
  for (const field of Object.keys(newValues)) {
127
127
  const col = resource.dataSourceColumns.find((col) => col.name == field);
128
+ if (!col) {
129
+ const similar = suggestIfTypo(resource.dataSourceColumns.map((col) => col.name), field);
130
+ throw new Error(`
131
+ Update record failed received field '${field}' (with value ${newValues[field]}), but such column not found in resource '${resource.resourceId}'. ${similar ? `Did you mean '${similar}'?` : ''}
132
+ `);
133
+ }
128
134
  recordWithOriginalValues[col.name] = this.setFieldValue(col, newValues[col.name]);
129
135
  }
130
136
 
@@ -110,6 +110,12 @@ export default class AdminForthBaseConnector {
110
110
  const recordWithOriginalValues = Object.assign({}, newValues);
111
111
  for (const field of Object.keys(newValues)) {
112
112
  const col = resource.dataSourceColumns.find((col) => col.name == field);
113
+ if (!col) {
114
+ const similar = suggestIfTypo(resource.dataSourceColumns.map((col) => col.name), field);
115
+ throw new Error(`
116
+ Update record failed received field '${field}' (with value ${newValues[field]}), but such column not found in resource '${resource.resourceId}'. ${similar ? `Did you mean '${similar}'?` : ''}
117
+ `);
118
+ }
113
119
  recordWithOriginalValues[col.name] = this.setFieldValue(col, newValues[col.name]);
114
120
  }
115
121
  process.env.HEAVY_DEBUG && console.log(`🪲✏️ updating record id:${recordId}, values: ${JSON.stringify(recordWithOriginalValues)}`);
@@ -24,6 +24,36 @@ try {
24
24
  catch (e) {
25
25
  TMP_DIR = '/tmp';
26
26
  }
27
+ function findHomePage(menuItem) {
28
+ for (const item of menuItem) {
29
+ if (item.homepage) {
30
+ return item;
31
+ }
32
+ if (item.children) {
33
+ const found = findHomePage(item.children);
34
+ if (found) {
35
+ return found;
36
+ }
37
+ }
38
+ }
39
+ return undefined;
40
+ }
41
+ function findFirstMenuItemWithResource(menuItem) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ for (const item of menuItem) {
44
+ if (item.path || item.resourceId) {
45
+ return item;
46
+ }
47
+ if (item.children) {
48
+ const found = yield findFirstMenuItemWithResource(item.children);
49
+ if (found) {
50
+ return found;
51
+ }
52
+ }
53
+ }
54
+ return undefined;
55
+ });
56
+ }
27
57
  const execAsync = promisify(exec);
28
58
  function hashify(obj) {
29
59
  return crypto.createHash('sha256').update(JSON.stringify(obj)).digest('hex');
@@ -128,7 +158,7 @@ class CodeInjector {
128
158
  }
129
159
  prepareSources(_a) {
130
160
  return __awaiter(this, arguments, void 0, function* ({ filesUpdated }) {
131
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
161
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
132
162
  // check SPA_TMP_PATH exists and create if not
133
163
  try {
134
164
  yield fs.promises.access(CodeInjector.SPA_TMP_PATH, fs.constants.F_OK);
@@ -377,12 +407,17 @@ class CodeInjector {
377
407
  `${this.adminforth.baseUrlSlashed}assets/favicon.png`);
378
408
  yield fs.promises.writeFile(indexHtmlPath, indexHtmlContent);
379
409
  /* generate custom routes */
380
- const homepageMenuItem = this.adminforth.config.menu.find((mi) => mi.homepage);
381
- let childrenHomePageMenuItem = this.adminforth.config.menu.find((mi) => { var _a; return mi.children && ((_a = mi.children) === null || _a === void 0 ? void 0 : _a.find((mi) => mi.homepage)); });
382
- let childrenHomepage = (_j = childrenHomePageMenuItem === null || childrenHomePageMenuItem === void 0 ? void 0 : childrenHomePageMenuItem.children) === null || _j === void 0 ? void 0 : _j.find((mi) => mi.homepage);
383
- let homePagePath = (homepageMenuItem === null || homepageMenuItem === void 0 ? void 0 : homepageMenuItem.path) || `/resource/${childrenHomepage === null || childrenHomepage === void 0 ? void 0 : childrenHomepage.resourceId}`;
410
+ let homepageMenuItem = findHomePage(this.adminforth.config.menu);
411
+ if (!homepageMenuItem) {
412
+ // find first item with path or resourceId. If we face a menu item with children earlier then path/resourceId, we should search in children
413
+ homepageMenuItem = yield findFirstMenuItemWithResource(this.adminforth.config.menu);
414
+ }
415
+ if (!homepageMenuItem) {
416
+ throw new Error('No homepage found in menu and no menu item with path/resourceId found. AdminForth can not generate routes');
417
+ }
418
+ let homePagePath = homepageMenuItem.path || `/resource/${homepageMenuItem.resourceId}`;
384
419
  if (!homePagePath) {
385
- homePagePath = ((_k = this.adminforth.config.menu.filter((mi) => mi.path)[0]) === null || _k === void 0 ? void 0 : _k.path) || `/resource/${(_l = this.adminforth.config.menu.filter((mi) => mi.children)[0]) === null || _l === void 0 ? void 0 : _l.resourceId}`;
420
+ homePagePath = ((_j = this.adminforth.config.menu.filter((mi) => mi.path)[0]) === null || _j === void 0 ? void 0 : _j.path) || `/resource/${(_k = this.adminforth.config.menu.filter((mi) => mi.children)[0]) === null || _k === void 0 ? void 0 : _k.resourceId}`;
386
421
  }
387
422
  routes += `{
388
423
  path: '/',
@@ -399,7 +434,7 @@ class CodeInjector {
399
434
  /* customPackageLock */
400
435
  let usersLockHash = '';
401
436
  let usersPackages = [];
402
- if ((_m = this.adminforth.config.customization) === null || _m === void 0 ? void 0 : _m.customComponentsDir) {
437
+ if ((_l = this.adminforth.config.customization) === null || _l === void 0 ? void 0 : _l.customComponentsDir) {
403
438
  [usersLockHash, usersPackages] = yield this.packagesFromNpm(this.adminforth.config.customization.customComponentsDir);
404
439
  }
405
440
  const pluginPackages = [];
@@ -8,7 +8,7 @@ import path from 'path';
8
8
  import { promisify } from 'util';
9
9
  import AdminForth from '../index.js';
10
10
  import { ADMIN_FORTH_ABSOLUTE_PATH, getComponentNameFromPath, transformObject, deepMerge } from './utils.js';
11
- import { ICodeInjector } from '../types/AdminForthConfig.js';
11
+ import { AdminForthConfigMenuItem, ICodeInjector } from '../types/AdminForthConfig.js';
12
12
  import { StylesGenerator } from './styleGenerator.js';
13
13
  import { title } from 'process';
14
14
 
@@ -22,6 +22,35 @@ try {
22
22
  }
23
23
 
24
24
 
25
+ function findHomePage(menuItem: AdminForthConfigMenuItem[]): AdminForthConfigMenuItem | undefined {
26
+ for (const item of menuItem) {
27
+ if (item.homepage) {
28
+ return item;
29
+ }
30
+ if (item.children) {
31
+ const found = findHomePage(item.children);
32
+ if (found) {
33
+ return found;
34
+ }
35
+ }
36
+ }
37
+ return undefined;
38
+ }
39
+ async function findFirstMenuItemWithResource(menuItem: AdminForthConfigMenuItem[]): Promise<AdminForthConfigMenuItem | undefined> {
40
+ for (const item of menuItem) {
41
+ if (item.path || item.resourceId) {
42
+ return item;
43
+ }
44
+ if (item.children) {
45
+ const found = await findFirstMenuItemWithResource(item.children);
46
+ if (found) {
47
+ return found;
48
+ }
49
+ }
50
+ }
51
+ return undefined;
52
+ }
53
+
25
54
  const execAsync = promisify(exec);
26
55
 
27
56
  function hashify(obj) {
@@ -429,10 +458,18 @@ class CodeInjector implements ICodeInjector {
429
458
 
430
459
 
431
460
  /* generate custom routes */
432
- const homepageMenuItem = this.adminforth.config.menu.find((mi)=>mi.homepage);
433
- let childrenHomePageMenuItem = this.adminforth.config.menu.find((mi)=>mi.children && mi.children?.find((mi)=>mi.homepage));
434
- let childrenHomepage = childrenHomePageMenuItem?.children?.find((mi)=>mi.homepage)
435
- let homePagePath = homepageMenuItem?.path || `/resource/${childrenHomepage?.resourceId}`;
461
+
462
+
463
+ let homepageMenuItem: AdminForthConfigMenuItem = findHomePage(this.adminforth.config.menu);
464
+ if (!homepageMenuItem) {
465
+ // find first item with path or resourceId. If we face a menu item with children earlier then path/resourceId, we should search in children
466
+ homepageMenuItem = await findFirstMenuItemWithResource(this.adminforth.config.menu);
467
+ }
468
+ if (!homepageMenuItem) {
469
+ throw new Error('No homepage found in menu and no menu item with path/resourceId found. AdminForth can not generate routes');
470
+ }
471
+
472
+ let homePagePath = homepageMenuItem.path || `/resource/${homepageMenuItem.resourceId}`;
436
473
  if (!homePagePath) {
437
474
  homePagePath=this.adminforth.config.menu.filter((mi)=>mi.path)[0]?.path || `/resource/${this.adminforth.config.menu.filter((mi)=>mi.children)[0]?.resourceId}` ;
438
475
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.3.42",
3
+ "version": "1.3.44",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",