appwrite-utils-cli 0.0.241 → 0.0.243

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.
@@ -164,5 +164,5 @@ export declare const findOrCreateOperation: (database: Databases, collectionId:
164
164
  }>;
165
165
  export declare const updateOperation: (database: Databases, operationId: string, updateFields: any) => Promise<void>;
166
166
  export declare const maxDataLength = 1073741820;
167
- export declare const maxBatchItems = 50;
167
+ export declare const maxBatchItems = 25;
168
168
  export declare const splitIntoBatches: (data: any[]) => any[][];
@@ -94,7 +94,7 @@ export const updateOperation = async (database, operationId, updateFields) => {
94
94
  };
95
95
  // Actual max 1073741824
96
96
  export const maxDataLength = 1073741820;
97
- export const maxBatchItems = 50;
97
+ export const maxBatchItems = 25;
98
98
  export const splitIntoBatches = (data) => {
99
99
  let batches = [];
100
100
  let currentBatch = [];
@@ -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,8 +40,19 @@ 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));
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.241",
4
+ "version": "0.0.243",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -158,7 +158,7 @@ export const updateOperation = async (
158
158
 
159
159
  // Actual max 1073741824
160
160
  export const maxDataLength = 1073741820;
161
- export const maxBatchItems = 50;
161
+ export const maxBatchItems = 25;
162
162
 
163
163
  export const splitIntoBatches = (data: any[]): any[][] => {
164
164
  let batches = [];
@@ -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,8 +48,19 @@ 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: Models.User<Models.Preferences>[]) => {
52
+ let maxBatchLength = 5;
53
+ const finalBatches: Models.User<Models.Preferences>[][] = [];
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));