serverless-plugin-module-registry 1.0.22 → 1.0.23

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/dist/index.js CHANGED
@@ -16451,6 +16451,43 @@ var DynamoDBManager = class {
16451
16451
  ...entry
16452
16452
  }));
16453
16453
  }
16454
+ /**
16455
+ * Merge new module items with existing DDB records to preserve fields
16456
+ * not set by the current deploy (e.g., apiGatewayId).
16457
+ *
16458
+ * Uses existing → new merge order so that new values always win,
16459
+ * but fields only present in the existing record are preserved.
16460
+ */
16461
+ async mergeWithExistingModuleItems(newModuleItems, moduleNames) {
16462
+ const existingByModule = /* @__PURE__ */ new Map();
16463
+ for (const moduleName of moduleNames) {
16464
+ try {
16465
+ const existingItems = await this.queryModuleEntries(moduleName);
16466
+ const moduleRecord = existingItems.find((item) => item.sk === "MODULE");
16467
+ if (moduleRecord) {
16468
+ existingByModule.set(moduleName, moduleRecord);
16469
+ }
16470
+ } catch (err) {
16471
+ this.logger.warning(` Could not read existing record for module '${moduleName}': ${err.message}`);
16472
+ }
16473
+ }
16474
+ if (existingByModule.size === 0) {
16475
+ return newModuleItems;
16476
+ }
16477
+ return newModuleItems.map((newItem) => {
16478
+ const moduleName = newItem.moduleName;
16479
+ const existing = existingByModule.get(moduleName);
16480
+ if (!existing) return newItem;
16481
+ const merged = { ...existing, ...newItem };
16482
+ const preservedFields = Object.keys(existing).filter(
16483
+ (k) => !(k in newItem) && existing[k] !== void 0
16484
+ );
16485
+ if (preservedFields.length > 0) {
16486
+ this.logger.info(` \u{1F500} Module '${moduleName}': preserved existing fields: ${preservedFields.join(", ")}`);
16487
+ }
16488
+ return merged;
16489
+ });
16490
+ }
16454
16491
  /**
16455
16492
  * Clean up stale entries for given modules
16456
16493
  * Note: Settings are now stored as attributes on module items, not separate items
@@ -16519,12 +16556,13 @@ var DynamoDBManager = class {
16519
16556
  await this.ensureTable();
16520
16557
  const moduleNames = [...new Set(moduleEntries.map((m) => m.moduleName))];
16521
16558
  await this.cleanupStaleEntries(moduleNames, moduleEntries, featureEntries, settingsEntries);
16522
- const moduleItems = this.moduleEntriesToItems(moduleEntries, settingsEntries);
16559
+ let moduleItems = this.moduleEntriesToItems(moduleEntries, settingsEntries);
16523
16560
  const featureItems = this.featureEntriesToItems(featureEntries);
16524
16561
  this.logger.info(` \u{1F4CA} Preparing items: ${moduleItems.length} modules (${settingsEntries.length} with settings), ${featureItems.length} features`);
16525
16562
  if (settingsEntries.length > 0) {
16526
16563
  this.logger.info(` \u2699\uFE0F Modules with settings: ${settingsEntries.map((s) => s.moduleName).join(", ")}`);
16527
16564
  }
16565
+ moduleItems = await this.mergeWithExistingModuleItems(moduleItems, moduleNames);
16528
16566
  const allItems = [
16529
16567
  ...moduleItems,
16530
16568
  ...featureItems