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 +66 -1
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.d.ts +3 -1
- package/dist/s3db.es.js +66 -1
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/resource.class.js +79 -0
- package/src/s3db.d.ts +3 -1
package/package.json
CHANGED
package/src/resource.class.js
CHANGED
|
@@ -540,6 +540,85 @@ export class Resource extends AsyncEventEmitter {
|
|
|
540
540
|
return true;
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Find orphaned partitions (partitions that reference non-existent fields)
|
|
545
|
+
* @returns {Object} Object with orphaned partition names as keys and details as values
|
|
546
|
+
* @example
|
|
547
|
+
* const orphaned = resource.findOrphanedPartitions();
|
|
548
|
+
* // Returns: { byRegion: { missingFields: ['region'], definition: {...} } }
|
|
549
|
+
*/
|
|
550
|
+
findOrphanedPartitions() {
|
|
551
|
+
const orphaned = {};
|
|
552
|
+
|
|
553
|
+
if (!this.config.partitions) {
|
|
554
|
+
return orphaned;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
for (const [partitionName, partitionDef] of Object.entries(this.config.partitions)) {
|
|
558
|
+
if (!partitionDef.fields) {
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const missingFields = [];
|
|
563
|
+
for (const fieldName of Object.keys(partitionDef.fields)) {
|
|
564
|
+
if (!this.fieldExistsInAttributes(fieldName)) {
|
|
565
|
+
missingFields.push(fieldName);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (missingFields.length > 0) {
|
|
570
|
+
orphaned[partitionName] = {
|
|
571
|
+
missingFields,
|
|
572
|
+
definition: partitionDef,
|
|
573
|
+
allFields: Object.keys(partitionDef.fields)
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return orphaned;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Remove orphaned partitions (partitions that reference non-existent fields)
|
|
583
|
+
* WARNING: This will modify the resource configuration and should be followed by uploadMetadataFile()
|
|
584
|
+
* @param {Object} options - Options
|
|
585
|
+
* @param {boolean} options.dryRun - If true, only returns what would be removed without modifying (default: false)
|
|
586
|
+
* @returns {Object} Object with removed partition names and details
|
|
587
|
+
* @example
|
|
588
|
+
* // Dry run to see what would be removed
|
|
589
|
+
* const toRemove = resource.removeOrphanedPartitions({ dryRun: true });
|
|
590
|
+
* console.log('Would remove:', toRemove);
|
|
591
|
+
*
|
|
592
|
+
* // Actually remove orphaned partitions
|
|
593
|
+
* const removed = resource.removeOrphanedPartitions();
|
|
594
|
+
* await database.uploadMetadataFile(); // Save changes to S3
|
|
595
|
+
*/
|
|
596
|
+
removeOrphanedPartitions({ dryRun = false } = {}) {
|
|
597
|
+
const orphaned = this.findOrphanedPartitions();
|
|
598
|
+
|
|
599
|
+
if (Object.keys(orphaned).length === 0) {
|
|
600
|
+
return {};
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (dryRun) {
|
|
604
|
+
return orphaned;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Remove orphaned partitions from config
|
|
608
|
+
for (const partitionName of Object.keys(orphaned)) {
|
|
609
|
+
delete this.config.partitions[partitionName];
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Emit event for tracking
|
|
613
|
+
this.emit('orphanedPartitionsRemoved', {
|
|
614
|
+
resourceName: this.name,
|
|
615
|
+
removed: Object.keys(orphaned),
|
|
616
|
+
details: orphaned
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
return orphaned;
|
|
620
|
+
}
|
|
621
|
+
|
|
543
622
|
/**
|
|
544
623
|
* Apply a single partition rule to a field value
|
|
545
624
|
* @param {*} value - The field value
|
package/src/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>;
|