appwrite-utils-cli 1.2.1 → 1.2.2

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.
@@ -74,6 +74,10 @@ export declare class ComprehensiveTransfer {
74
74
  * Helper method to fetch all collections from a database
75
75
  */
76
76
  private fetchAllCollections;
77
+ /**
78
+ * Helper method to fetch all buckets with pagination
79
+ */
80
+ private fetchAllBuckets;
77
81
  /**
78
82
  * Helper method to parse attribute objects (simplified version of parseAttribute)
79
83
  */
@@ -272,21 +272,22 @@ export class ComprehensiveTransfer {
272
272
  async transferAllBuckets() {
273
273
  MessageFormatter.info("Starting bucket transfer phase", { prefix: "Transfer" });
274
274
  try {
275
- const sourceBuckets = await this.sourceStorage.listBuckets();
276
- const targetBuckets = await this.targetStorage.listBuckets();
275
+ // Get all buckets from source with pagination
276
+ const allSourceBuckets = await this.fetchAllBuckets(this.sourceStorage);
277
+ const allTargetBuckets = await this.fetchAllBuckets(this.targetStorage);
277
278
  if (this.options.dryRun) {
278
279
  let totalFiles = 0;
279
- for (const bucket of sourceBuckets.buckets) {
280
+ for (const bucket of allSourceBuckets) {
280
281
  const files = await this.sourceStorage.listFiles(bucket.$id, [Query.limit(1)]);
281
282
  totalFiles += files.total;
282
283
  }
283
- MessageFormatter.info(`DRY RUN: Would transfer ${sourceBuckets.buckets.length} buckets with ${totalFiles} files`, { prefix: "Transfer" });
284
+ MessageFormatter.info(`DRY RUN: Would transfer ${allSourceBuckets.length} buckets with ${totalFiles} files`, { prefix: "Transfer" });
284
285
  return;
285
286
  }
286
- const transferTasks = sourceBuckets.buckets.map(bucket => this.limit(async () => {
287
+ const transferTasks = allSourceBuckets.map(bucket => this.limit(async () => {
287
288
  try {
288
289
  // Check if bucket exists in target
289
- const existingBucket = targetBuckets.buckets.find(tb => tb.$id === bucket.$id);
290
+ const existingBucket = allTargetBuckets.find(tb => tb.$id === bucket.$id);
290
291
  if (!existingBucket) {
291
292
  // Create bucket in target
292
293
  await this.targetStorage.createBucket(bucket.$id, bucket.name, bucket.$permissions, bucket.fileSecurity, bucket.enabled, bucket.maximumFileSize, bucket.allowedFileExtensions, bucket.compression, bucket.encryption, bucket.antivirus);
@@ -480,6 +481,29 @@ export class ComprehensiveTransfer {
480
481
  }
481
482
  return collections;
482
483
  }
484
+ /**
485
+ * Helper method to fetch all buckets with pagination
486
+ */
487
+ async fetchAllBuckets(storage) {
488
+ const buckets = [];
489
+ let lastId;
490
+ while (true) {
491
+ const queries = [Query.limit(100)];
492
+ if (lastId) {
493
+ queries.push(Query.cursorAfter(lastId));
494
+ }
495
+ const result = await tryAwaitWithRetry(async () => storage.listBuckets(queries));
496
+ if (result.buckets.length === 0) {
497
+ break;
498
+ }
499
+ buckets.push(...result.buckets);
500
+ if (result.buckets.length < 100) {
501
+ break;
502
+ }
503
+ lastId = result.buckets[result.buckets.length - 1].$id;
504
+ }
505
+ return buckets;
506
+ }
483
507
  /**
484
508
  * Helper method to parse attribute objects (simplified version of parseAttribute)
485
509
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "appwrite-utils-cli",
3
3
  "description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -408,24 +408,25 @@ export class ComprehensiveTransfer {
408
408
  MessageFormatter.info("Starting bucket transfer phase", { prefix: "Transfer" });
409
409
 
410
410
  try {
411
- const sourceBuckets = await this.sourceStorage.listBuckets();
412
- const targetBuckets = await this.targetStorage.listBuckets();
411
+ // Get all buckets from source with pagination
412
+ const allSourceBuckets = await this.fetchAllBuckets(this.sourceStorage);
413
+ const allTargetBuckets = await this.fetchAllBuckets(this.targetStorage);
413
414
 
414
415
  if (this.options.dryRun) {
415
416
  let totalFiles = 0;
416
- for (const bucket of sourceBuckets.buckets) {
417
+ for (const bucket of allSourceBuckets) {
417
418
  const files = await this.sourceStorage.listFiles(bucket.$id, [Query.limit(1)]);
418
419
  totalFiles += files.total;
419
420
  }
420
- MessageFormatter.info(`DRY RUN: Would transfer ${sourceBuckets.buckets.length} buckets with ${totalFiles} files`, { prefix: "Transfer" });
421
+ MessageFormatter.info(`DRY RUN: Would transfer ${allSourceBuckets.length} buckets with ${totalFiles} files`, { prefix: "Transfer" });
421
422
  return;
422
423
  }
423
424
 
424
- const transferTasks = sourceBuckets.buckets.map(bucket =>
425
+ const transferTasks = allSourceBuckets.map(bucket =>
425
426
  this.limit(async () => {
426
427
  try {
427
428
  // Check if bucket exists in target
428
- const existingBucket = targetBuckets.buckets.find(tb => tb.$id === bucket.$id);
429
+ const existingBucket = allTargetBuckets.find(tb => tb.$id === bucket.$id);
429
430
 
430
431
  if (!existingBucket) {
431
432
  // Create bucket in target
@@ -676,6 +677,37 @@ export class ComprehensiveTransfer {
676
677
  return collections;
677
678
  }
678
679
 
680
+ /**
681
+ * Helper method to fetch all buckets with pagination
682
+ */
683
+ private async fetchAllBuckets(storage: Storage): Promise<Models.Bucket[]> {
684
+ const buckets: Models.Bucket[] = [];
685
+ let lastId: string | undefined;
686
+
687
+ while (true) {
688
+ const queries = [Query.limit(100)];
689
+ if (lastId) {
690
+ queries.push(Query.cursorAfter(lastId));
691
+ }
692
+
693
+ const result = await tryAwaitWithRetry(async () => storage.listBuckets(queries));
694
+
695
+ if (result.buckets.length === 0) {
696
+ break;
697
+ }
698
+
699
+ buckets.push(...result.buckets);
700
+
701
+ if (result.buckets.length < 100) {
702
+ break;
703
+ }
704
+
705
+ lastId = result.buckets[result.buckets.length - 1].$id;
706
+ }
707
+
708
+ return buckets;
709
+ }
710
+
679
711
  /**
680
712
  * Helper method to parse attribute objects (simplified version of parseAttribute)
681
713
  */