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