@realtek/core-theme 0.0.107 → 0.0.109

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realtek/core-theme",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
4
4
  "type": "module",
5
5
  "description": "RealTek CORE-THEME — shared React component & admin-screen library (AddFormV1, EditFormV1, ListView, DetailViewV1, ...).",
6
6
  "license": "UNLICENSED",
@@ -9,12 +9,11 @@ import { stdin as input, stdout as output } from 'node:process';
9
9
  import { MongoClient, ObjectId } from 'mongodb';
10
10
 
11
11
  const INIT_MARKER_FILENAME = '.core-theme-mongodb-init.json';
12
-
13
12
  function isRunningFromOwnRepo() {
14
13
  const scriptPath = fileURLToPath(import.meta.url);
15
14
  return !scriptPath.split(/[\\/]/).includes('node_modules');
16
15
  }
17
- const DEFAULT_MONGO_URI = '';
16
+ const DEFAULT_MONGO_URI = 'mongodb://admin:e7cH06Dy2LK2@192.168.1.88:27017/znnxt?authSource=admin&authMechanism=SCRAM-SHA-256';
18
17
  const DEFAULT_ADMIN_EMAIL = 'admin@example.com';
19
18
  const DEFAULT_ADMIN_PASSWORD_HASH = '$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy';
20
19
  const HISTORY_COLLECTION = 'MONGO_MIGRATION_HISTORY';
@@ -480,10 +479,37 @@ async function seedPermissions(db) {
480
479
 
481
480
  async function seedMenus(db) {
482
481
  const timestamp = new Date();
482
+ const collection = db.collection('menus');
483
+ const existingMenus = await collection.find(
484
+ { isDeleted: { $ne: true } },
485
+ { projection: { legacyMenuId: 1, menuKey: 1 } },
486
+ ).toArray();
487
+ const usedIds = new Set(existingMenus.map((menu) => Number(menu.legacyMenuId)).filter(Number.isFinite));
488
+ const menusByKey = new Map(existingMenus.map((menu) => [menu.menuKey, menu]));
489
+ const assignedIdsByDefaultId = new Map();
490
+ let nextMenuId = Math.max(0, ...usedIds) + 1;
491
+
483
492
  for (const menu of MENUS) {
493
+ const defaultLegacyMenuId = menu.legacyMenuId;
494
+ const existing = menusByKey.get(menu.menuKey);
495
+ let legacyMenuId = Number(existing?.legacyMenuId);
496
+ if (!Number.isFinite(legacyMenuId)) {
497
+ legacyMenuId = usedIds.has(menu.legacyMenuId) ? nextMenuId : menu.legacyMenuId;
498
+ while (usedIds.has(legacyMenuId)) legacyMenuId += 1;
499
+ nextMenuId = Math.max(nextMenuId, legacyMenuId + 1);
500
+ usedIds.add(legacyMenuId);
501
+ }
502
+ // Downstream role/user permission seeds must use the real ID assigned in
503
+ // this database, not the default position from SIDE_MENU_STRUCTURE.
504
+ assignedIdsByDefaultId.set(defaultLegacyMenuId, legacyMenuId);
505
+ menu.legacyMenuId = legacyMenuId;
506
+ menu.parentMenuId = menu.parentMenuId == null
507
+ ? null
508
+ : assignedIdsByDefaultId.get(menu.parentMenuId) ?? menu.parentMenuId;
509
+
484
510
  await upsertOne(
485
- db.collection('menus'),
486
- { legacyMenuId: menu.legacyMenuId },
511
+ collection,
512
+ { menuKey: menu.menuKey },
487
513
  {
488
514
  $set: {
489
515
  parentMenuId: menu.parentMenuId,
@@ -496,7 +522,7 @@ async function seedMenus(db) {
496
522
  updatedAt: timestamp,
497
523
  },
498
524
  $setOnInsert: {
499
- legacyMenuId: menu.legacyMenuId,
525
+ legacyMenuId,
500
526
  migrationSource: 'core-theme-admin.seed',
501
527
  createdBy: 1,
502
528
  createdAt: timestamp,
@@ -505,7 +531,7 @@ async function seedMenus(db) {
505
531
  `menus.${menu.menuKey}`,
506
532
  );
507
533
  }
508
- await syncCounter(db, 'menus', MENUS.length);
534
+ await syncCounter(db, 'menus', Math.max(...usedIds));
509
535
  }
510
536
 
511
537
  async function seedRoles(db) {
@@ -812,14 +838,16 @@ async function main() {
812
838
  return;
813
839
  }
814
840
 
815
- const mongoUri = options.mongoUri || (
816
- options.skipPrompt
817
- ? DEFAULT_MONGO_URI
818
- : await promptForMongoUri(DEFAULT_MONGO_URI)
819
- );
841
+ const mongoUri =
842
+ options.mongoUri ||
843
+ process.env.MONGO_URI ||
844
+ DEFAULT_MONGO_URI;
845
+
820
846
  const dbName = options.dbName || (options.skipPrompt ? '' : await promptForDbName(options.dbName));
821
847
  if (!mongoUri) {
822
- throw new Error('MongoDB URI is required. Use --uri <mongoUri> or MONGO_URI.');
848
+ throw new Error(
849
+ 'MongoDB URI is required. Configure DEFAULT_MONGO_URI or set MONGO_URI.'
850
+ );
823
851
  }
824
852
  if (!dbName) {
825
853
  throw new Error('MongoDB database name is required. Use --db <databaseName> or MONGO_DB_NAME.');