appwrite-utils-cli 0.0.242 → 0.0.244

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.
@@ -71,7 +71,7 @@ export const wipeDocumentStorage = async (storage, config, dbName) => {
71
71
  const fileIds = filesPulled.files.map((file) => file.$id);
72
72
  allFiles.push(...fileIds);
73
73
  }
74
- moreFiles = filesPulled.files.length > 100; // Adjust based on the limit
74
+ moreFiles = filesPulled.files.length === 100; // Adjust based on the limit
75
75
  if (moreFiles) {
76
76
  lastFileId = filesPulled.files[filesPulled.files.length - 1].$id;
77
77
  }
@@ -40,14 +40,25 @@ export class UsersController {
40
40
  lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
41
41
  }
42
42
  console.log("Deleting all users...");
43
+ const createBatches = (finalData) => {
44
+ let maxBatchLength = 5;
45
+ const finalBatches = [];
46
+ for (let i = 0; i < finalData.length; i++) {
47
+ if (i % maxBatchLength === 0) {
48
+ finalBatches.push([]);
49
+ }
50
+ finalBatches[finalBatches.length - 1].push(finalData[i]);
51
+ }
52
+ return finalBatches;
53
+ };
43
54
  const userPromises = [];
44
- const allUsersBatched = splitIntoBatches(allUsers);
55
+ const allUsersBatched = createBatches(allUsers);
45
56
  for (const userBatch of allUsersBatched) {
46
57
  for (const user of userBatch) {
47
58
  userPromises.push(this.users.delete(user.$id));
48
59
  }
49
60
  }
50
- const batchedUserPromises = splitIntoBatches(userPromises);
61
+ const batchedUserPromises = createBatches(userPromises);
51
62
  for (const batch of batchedUserPromises) {
52
63
  console.log(`Deleting ${batch.length} users...`);
53
64
  await Promise.all(batch);
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": "0.0.242",
4
+ "version": "0.0.244",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -111,7 +111,7 @@ export const wipeDocumentStorage = async (
111
111
  const fileIds = filesPulled.files.map((file) => file.$id);
112
112
  allFiles.push(...fileIds);
113
113
  }
114
- moreFiles = filesPulled.files.length > 100; // Adjust based on the limit
114
+ moreFiles = filesPulled.files.length === 100; // Adjust based on the limit
115
115
  if (moreFiles) {
116
116
  lastFileId = filesPulled.files[filesPulled.files.length - 1].$id;
117
117
  }
@@ -48,14 +48,25 @@ export class UsersController {
48
48
  lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
49
49
  }
50
50
  console.log("Deleting all users...");
51
+ const createBatches = (finalData: any[]) => {
52
+ let maxBatchLength = 5;
53
+ const finalBatches: any[][] = [];
54
+ for (let i = 0; i < finalData.length; i++) {
55
+ if (i % maxBatchLength === 0) {
56
+ finalBatches.push([]);
57
+ }
58
+ finalBatches[finalBatches.length - 1].push(finalData[i]);
59
+ }
60
+ return finalBatches;
61
+ };
51
62
  const userPromises: Promise<string>[] = [];
52
- const allUsersBatched = splitIntoBatches(allUsers);
63
+ const allUsersBatched = createBatches(allUsers);
53
64
  for (const userBatch of allUsersBatched) {
54
65
  for (const user of userBatch) {
55
66
  userPromises.push(this.users.delete(user.$id));
56
67
  }
57
68
  }
58
- const batchedUserPromises = splitIntoBatches(userPromises);
69
+ const batchedUserPromises = createBatches(userPromises);
59
70
  for (const batch of batchedUserPromises) {
60
71
  console.log(`Deleting ${batch.length} users...`);
61
72
  await Promise.all(batch);