appwrite-utils-cli 0.0.43 → 0.0.45
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.
|
@@ -154,20 +154,26 @@ export class ImportController {
|
|
|
154
154
|
const batches = dataSplit[i];
|
|
155
155
|
console.log(`Processing batch ${i + 1} of ${dataSplit.length}`);
|
|
156
156
|
const batchPromises = batches.map((item) => {
|
|
157
|
-
|
|
158
|
-
item.finalData.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
157
|
+
try {
|
|
158
|
+
const id = item.finalData.docId ||
|
|
159
|
+
item.finalData.userId ||
|
|
160
|
+
item.context.docId ||
|
|
161
|
+
item.context.userId;
|
|
162
|
+
if (item.finalData.hasOwnProperty("userId")) {
|
|
163
|
+
delete item.finalData.userId;
|
|
164
|
+
}
|
|
165
|
+
if (item.finalData.hasOwnProperty("docId")) {
|
|
166
|
+
delete item.finalData.docId;
|
|
167
|
+
}
|
|
168
|
+
if (!item.finalData) {
|
|
169
|
+
return Promise.resolve();
|
|
170
|
+
}
|
|
171
|
+
return tryAwaitWithRetry(async () => await this.database.createDocument(db.$id, collection.$id, id, item.finalData));
|
|
166
172
|
}
|
|
167
|
-
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error(error);
|
|
168
175
|
return Promise.resolve();
|
|
169
176
|
}
|
|
170
|
-
return tryAwaitWithRetry(async () => await this.database.createDocument(db.$id, collection.$id, id, item.finalData));
|
|
171
177
|
});
|
|
172
178
|
// Wait for all promises in the current batch to resolve
|
|
173
179
|
await Promise.all(batchPromises);
|
|
@@ -43,4 +43,4 @@ export declare let numTimesFailedTotal: number;
|
|
|
43
43
|
* @param {number} [attemptNum=0] - The number of attempts made so far (default: 0).
|
|
44
44
|
* @return {Promise<any>} - A promise that resolves to the result of the createFunction or rejects with an error if it fails after 5 attempts.
|
|
45
45
|
*/
|
|
46
|
-
export declare const tryAwaitWithRetry: <T>(createFunction: () => Promise<T>, attemptNum?: number) => Promise<T>;
|
|
46
|
+
export declare const tryAwaitWithRetry: <T>(createFunction: () => Promise<T>, attemptNum?: number, throwError?: boolean) => Promise<T>;
|
|
@@ -87,7 +87,7 @@ export let numTimesFailedTotal = 0;
|
|
|
87
87
|
* @param {number} [attemptNum=0] - The number of attempts made so far (default: 0).
|
|
88
88
|
* @return {Promise<any>} - A promise that resolves to the result of the createFunction or rejects with an error if it fails after 5 attempts.
|
|
89
89
|
*/
|
|
90
|
-
export const tryAwaitWithRetry = async (createFunction, attemptNum = 0) => {
|
|
90
|
+
export const tryAwaitWithRetry = async (createFunction, attemptNum = 0, throwError = false) => {
|
|
91
91
|
try {
|
|
92
92
|
return await createFunction();
|
|
93
93
|
}
|
|
@@ -102,6 +102,10 @@ export const tryAwaitWithRetry = async (createFunction, attemptNum = 0) => {
|
|
|
102
102
|
}
|
|
103
103
|
return tryAwaitWithRetry(createFunction, attemptNum + 1);
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
if (throwError) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
return Promise.resolve();
|
|
106
110
|
}
|
|
107
111
|
};
|
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.
|
|
4
|
+
"version": "0.0.45",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -220,29 +220,34 @@ export class ImportController {
|
|
|
220
220
|
const batches = dataSplit[i];
|
|
221
221
|
console.log(`Processing batch ${i + 1} of ${dataSplit.length}`);
|
|
222
222
|
const batchPromises = batches.map((item) => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
223
|
+
try {
|
|
224
|
+
const id =
|
|
225
|
+
item.finalData.docId ||
|
|
226
|
+
item.finalData.userId ||
|
|
227
|
+
item.context.docId ||
|
|
228
|
+
item.context.userId;
|
|
229
|
+
if (item.finalData.hasOwnProperty("userId")) {
|
|
230
|
+
delete item.finalData.userId;
|
|
231
|
+
}
|
|
232
|
+
if (item.finalData.hasOwnProperty("docId")) {
|
|
233
|
+
delete item.finalData.docId;
|
|
234
|
+
}
|
|
235
|
+
if (!item.finalData) {
|
|
236
|
+
return Promise.resolve();
|
|
237
|
+
}
|
|
238
|
+
return tryAwaitWithRetry(
|
|
239
|
+
async () =>
|
|
240
|
+
await this.database.createDocument(
|
|
241
|
+
db.$id,
|
|
242
|
+
collection.$id,
|
|
243
|
+
id,
|
|
244
|
+
item.finalData
|
|
245
|
+
)
|
|
246
|
+
);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
console.error(error);
|
|
235
249
|
return Promise.resolve();
|
|
236
250
|
}
|
|
237
|
-
return tryAwaitWithRetry(
|
|
238
|
-
async () =>
|
|
239
|
-
await this.database.createDocument(
|
|
240
|
-
db.$id,
|
|
241
|
-
collection.$id,
|
|
242
|
-
id,
|
|
243
|
-
item.finalData
|
|
244
|
-
)
|
|
245
|
-
);
|
|
246
251
|
});
|
|
247
252
|
// Wait for all promises in the current batch to resolve
|
|
248
253
|
await Promise.all(batchPromises);
|
|
@@ -137,7 +137,8 @@ export let numTimesFailedTotal = 0;
|
|
|
137
137
|
*/
|
|
138
138
|
export const tryAwaitWithRetry = async <T>(
|
|
139
139
|
createFunction: () => Promise<T>,
|
|
140
|
-
attemptNum: number = 0
|
|
140
|
+
attemptNum: number = 0,
|
|
141
|
+
throwError: boolean = false
|
|
141
142
|
): Promise<T> => {
|
|
142
143
|
try {
|
|
143
144
|
return await createFunction();
|
|
@@ -154,6 +155,10 @@ export const tryAwaitWithRetry = async <T>(
|
|
|
154
155
|
}
|
|
155
156
|
return tryAwaitWithRetry(createFunction, attemptNum + 1);
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
if (throwError) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
return Promise.resolve();
|
|
158
163
|
}
|
|
159
164
|
};
|