appwrite-utils-cli 1.2.12 → 1.2.16

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/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.12",
4
+ "version": "1.2.16",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -109,7 +109,7 @@ export const createOrUpdateIndexWithStatusCheck = async (
109
109
  collection: Models.Collection,
110
110
  index: Index,
111
111
  retryCount: number = 0,
112
- maxRetries: number = 5
112
+ maxRetries: number = 3,
113
113
  ): Promise<boolean> => {
114
114
  console.log(chalk.blue(`Creating/updating index '${index.key}' (attempt ${retryCount + 1}/${maxRetries + 1})`));
115
115
 
@@ -171,10 +171,10 @@ export const createOrUpdateIndexWithStatusCheck = async (
171
171
  console.log(chalk.red(`Error creating index '${index.key}': ${errorMessage}`));
172
172
 
173
173
  // Check if this is a permanent error that shouldn't be retried
174
- if (errorMessage.includes('not found') ||
175
- errorMessage.includes('missing') ||
176
- errorMessage.includes('does not exist') ||
177
- errorMessage.includes('attribute') && errorMessage.includes('not found')) {
174
+ if (errorMessage.toLowerCase().includes('not found') ||
175
+ errorMessage.toLowerCase().includes('missing') ||
176
+ errorMessage.toLowerCase().includes('does not exist') ||
177
+ errorMessage.toLowerCase().includes('attribute') && errorMessage.toLowerCase().includes('not found')) {
178
178
  console.log(chalk.red(`❌ Index '${index.key}' has permanent error - not retrying`));
179
179
  return false;
180
180
  }
@@ -285,8 +285,7 @@ export const createOrUpdateIndex = async (
285
285
  (existingIndex) =>
286
286
  (existingIndex.key === index.key &&
287
287
  existingIndex.type === index.type &&
288
- existingIndex.attributes === index.attributes) ||
289
- JSON.stringify(existingIndex) === JSON.stringify(index)
288
+ existingIndex.attributes === index.attributes)
290
289
  )
291
290
  ) {
292
291
  await db.deleteIndex(dbId, collectionId, existingIndex.indexes[0].key);
@@ -161,6 +161,16 @@ export const listSpecifications = async (client: Client) => {
161
161
  return specifications;
162
162
  };
163
163
 
164
+ export const listFunctionDeployments = async (
165
+ client: Client,
166
+ functionId: string,
167
+ queries?: string[]
168
+ ) => {
169
+ const functions = new Functions(client);
170
+ const deployments = await functions.listDeployments(functionId, queries);
171
+ return deployments;
172
+ };
173
+
164
174
  export const updateFunction = async (
165
175
  client: Client,
166
176
  functionConfig: AppwriteFunction
@@ -27,7 +27,7 @@ import {
27
27
  } from "appwrite-utils";
28
28
  import { getDatabaseFromConfig } from "./afterImportActions.js";
29
29
  import { listBuckets } from "../storage/methods.js";
30
- import { listFunctions } from "../functions/methods.js";
30
+ import { listFunctions, listFunctionDeployments } from "../functions/methods.js";
31
31
 
32
32
  export class AppwriteToX {
33
33
  config: AppwriteConfig;
@@ -241,22 +241,9 @@ export class AppwriteToX {
241
241
  const remoteFunctions = await listFunctions(this.config.appwriteClient!, [
242
242
  Query.limit(1000),
243
243
  ]);
244
- const functionDeployments = await Promise.all(
245
- remoteFunctions.functions.map(async (func) => {
246
- const deployments =
247
- await this.config.appwriteClient!.functions.listDeployments(
248
- func.$id,
249
- [Query.orderDesc("$createdAt"), Query.limit(1)]
250
- );
251
- return {
252
- function: func,
253
- schemaStrings: deployments.deployments[0]?.schemaStrings || [],
254
- };
255
- })
256
- );
257
244
 
258
- this.updatedConfig.functions = functionDeployments.map(
259
- ({ function: func, schemaStrings }) => ({
245
+ this.updatedConfig.functions = remoteFunctions.functions.map(
246
+ (func) => ({
260
247
  $id: func.$id,
261
248
  name: func.name,
262
249
  runtime: func.runtime as Runtime,
@@ -270,7 +257,6 @@ export class AppwriteToX {
270
257
  commands: func.commands || "npm install",
271
258
  dirPath: `functions/${func.name}`,
272
259
  specification: func.specification as Specification,
273
- schemaStrings,
274
260
  })
275
261
  );
276
262