appwrite-utils-cli 0.9.98 → 0.9.981

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/README.md CHANGED
@@ -125,6 +125,7 @@ This updated CLI ensures that developers have robust tools at their fingertips t
125
125
 
126
126
  ## Changelog
127
127
 
128
+ - 0.9.981: Try fixing `tryAwaitWithRetry` to catch `522` errors from Cloudflare, they were appearing for some users, also added a 1000ms delay to `tryAwaitWithRetry`
128
129
  - 0.9.98: Fixing some import errors reported by users
129
130
  - 0.9.95: Updated to include new version of `appwrite-utils`
130
131
  - 0.9.93: Updated `selectDatabases` and `selectCollections` from the interactive CLI to prefer local collections or databases when synchronizing the databases
@@ -2,6 +2,8 @@ import { Client, Databases, IndexType, Query, } from "node-appwrite";
2
2
  import { getAppwriteClient, tryAwaitWithRetry, } from "../utils/helperFunctions.js";
3
3
  export const fetchAllDatabases = async (database) => {
4
4
  const databases = await tryAwaitWithRetry(async () => await database.list([Query.limit(25)]));
5
+ if (!databases)
6
+ return [];
5
7
  const allDatabases = databases.databases;
6
8
  if (allDatabases.length === 0)
7
9
  return [];
@@ -92,14 +92,21 @@ export const tryAwaitWithRetry = async (createFunction, attemptNum = 0, throwErr
92
92
  return await createFunction();
93
93
  }
94
94
  catch (error) {
95
- if (error instanceof AppwriteException &&
95
+ if ((error instanceof AppwriteException &&
96
96
  (error.message.toLowerCase().includes("fetch failed") ||
97
- error.message.toLowerCase().includes("server error"))) {
97
+ error.message.toLowerCase().includes("server error"))) ||
98
+ (error.code === 522 || error.code === "522")) {
99
+ if (error.code === 522) {
100
+ console.log("Cloudflare error. Retrying...");
101
+ }
102
+ else {
103
+ console.log(`Fetch failed on attempt ${attemptNum}. Retrying...`);
104
+ }
98
105
  numTimesFailedTotal++;
99
- console.log(`Fetch failed on attempt ${attemptNum}. Retrying...`);
100
106
  if (attemptNum > 5) {
101
107
  throw error;
102
108
  }
109
+ await delay(1000);
103
110
  return tryAwaitWithRetry(createFunction, attemptNum + 1);
104
111
  }
105
112
  if (throwError) {
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.9.98",
4
+ "version": "0.9.981",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -16,6 +16,7 @@ export const fetchAllDatabases = async (
16
16
  const databases = await tryAwaitWithRetry(
17
17
  async () => await database.list([Query.limit(25)])
18
18
  );
19
+ if (!databases) return [];
19
20
  const allDatabases = databases.databases;
20
21
  if (allDatabases.length === 0) return [];
21
22
  let lastDatabaseId = allDatabases[allDatabases.length - 1].$id;
@@ -149,15 +149,21 @@ export const tryAwaitWithRetry = async <T>(
149
149
  return await createFunction();
150
150
  } catch (error) {
151
151
  if (
152
- error instanceof AppwriteException &&
152
+ (error instanceof AppwriteException &&
153
153
  (error.message.toLowerCase().includes("fetch failed") ||
154
- error.message.toLowerCase().includes("server error"))
154
+ error.message.toLowerCase().includes("server error"))) ||
155
+ ((error as any).code === 522 || (error as any).code === "522")
155
156
  ) {
157
+ if ((error as any).code === 522) {
158
+ console.log("Cloudflare error. Retrying...");
159
+ } else {
160
+ console.log(`Fetch failed on attempt ${attemptNum}. Retrying...`);
161
+ }
156
162
  numTimesFailedTotal++;
157
- console.log(`Fetch failed on attempt ${attemptNum}. Retrying...`);
158
163
  if (attemptNum > 5) {
159
164
  throw error;
160
165
  }
166
+ await delay(1000);
161
167
  return tryAwaitWithRetry(createFunction, attemptNum + 1);
162
168
  }
163
169
  if (throwError) {