s3db.js 11.2.5 → 11.2.6

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/s3db.cjs.js CHANGED
@@ -13125,6 +13125,71 @@ ${errorDetails}`,
13125
13125
  }
13126
13126
  return true;
13127
13127
  }
13128
+ /**
13129
+ * Find orphaned partitions (partitions that reference non-existent fields)
13130
+ * @returns {Object} Object with orphaned partition names as keys and details as values
13131
+ * @example
13132
+ * const orphaned = resource.findOrphanedPartitions();
13133
+ * // Returns: { byRegion: { missingFields: ['region'], definition: {...} } }
13134
+ */
13135
+ findOrphanedPartitions() {
13136
+ const orphaned = {};
13137
+ if (!this.config.partitions) {
13138
+ return orphaned;
13139
+ }
13140
+ for (const [partitionName, partitionDef] of Object.entries(this.config.partitions)) {
13141
+ if (!partitionDef.fields) {
13142
+ continue;
13143
+ }
13144
+ const missingFields = [];
13145
+ for (const fieldName of Object.keys(partitionDef.fields)) {
13146
+ if (!this.fieldExistsInAttributes(fieldName)) {
13147
+ missingFields.push(fieldName);
13148
+ }
13149
+ }
13150
+ if (missingFields.length > 0) {
13151
+ orphaned[partitionName] = {
13152
+ missingFields,
13153
+ definition: partitionDef,
13154
+ allFields: Object.keys(partitionDef.fields)
13155
+ };
13156
+ }
13157
+ }
13158
+ return orphaned;
13159
+ }
13160
+ /**
13161
+ * Remove orphaned partitions (partitions that reference non-existent fields)
13162
+ * WARNING: This will modify the resource configuration and should be followed by uploadMetadataFile()
13163
+ * @param {Object} options - Options
13164
+ * @param {boolean} options.dryRun - If true, only returns what would be removed without modifying (default: false)
13165
+ * @returns {Object} Object with removed partition names and details
13166
+ * @example
13167
+ * // Dry run to see what would be removed
13168
+ * const toRemove = resource.removeOrphanedPartitions({ dryRun: true });
13169
+ * console.log('Would remove:', toRemove);
13170
+ *
13171
+ * // Actually remove orphaned partitions
13172
+ * const removed = resource.removeOrphanedPartitions();
13173
+ * await database.uploadMetadataFile(); // Save changes to S3
13174
+ */
13175
+ removeOrphanedPartitions({ dryRun = false } = {}) {
13176
+ const orphaned = this.findOrphanedPartitions();
13177
+ if (Object.keys(orphaned).length === 0) {
13178
+ return {};
13179
+ }
13180
+ if (dryRun) {
13181
+ return orphaned;
13182
+ }
13183
+ for (const partitionName of Object.keys(orphaned)) {
13184
+ delete this.config.partitions[partitionName];
13185
+ }
13186
+ this.emit("orphanedPartitionsRemoved", {
13187
+ resourceName: this.name,
13188
+ removed: Object.keys(orphaned),
13189
+ details: orphaned
13190
+ });
13191
+ return orphaned;
13192
+ }
13128
13193
  /**
13129
13194
  * Apply a single partition rule to a field value
13130
13195
  * @param {*} value - The field value
@@ -15218,7 +15283,7 @@ class Database extends EventEmitter {
15218
15283
  this.id = idGenerator(7);
15219
15284
  this.version = "1";
15220
15285
  this.s3dbVersion = (() => {
15221
- const [ok, err, version] = tryFn(() => true ? "11.2.5" : "latest");
15286
+ const [ok, err, version] = tryFn(() => true ? "11.2.6" : "latest");
15222
15287
  return ok ? version : "latest";
15223
15288
  })();
15224
15289
  this.resources = {};