appwrite-utils-cli 0.0.13 → 0.0.15

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.
@@ -2,6 +2,7 @@ import { Databases, Storage, InputFile, Query, ID, Client, } from "node-appwrite
2
2
  import path from "path";
3
3
  import fs from "fs";
4
4
  import os from "os";
5
+ import { logger } from "./logging.js";
5
6
  const getDatabaseFromConfig = (config) => {
6
7
  if (!config.appwriteClient) {
7
8
  config.appwriteClient = new Client()
@@ -307,6 +308,7 @@ export const afterImportActions = {
307
308
  }
308
309
  }
309
310
  catch (error) {
311
+ logger.error(`Error creating file and updating field, params were:\ndbId: ${dbId}, collId: ${collId}, docId: ${docId}, fieldName: ${fieldName}, filePath: ${filePath}, fileName: ${fileName}\n\nError: ${error}`);
310
312
  console.error("Error creating file and updating field: ", error);
311
313
  console.log(`Params were: dbId: ${dbId}, collId: ${collId}, docId: ${docId}, fieldName: ${fieldName}, filePath: ${filePath}, fileName: ${fileName}`);
312
314
  }
@@ -551,7 +551,6 @@ export const convertObjectByAttributeMappings = (obj, attributeMappings) => {
551
551
  }
552
552
  }
553
553
  }
554
- console.log("Resolved object:", result);
555
554
  return result;
556
555
  };
557
556
  /**
@@ -346,7 +346,8 @@ export class ImportController {
346
346
  const actionOperation = ContextObject.parse(JSON.parse(batch.data));
347
347
  const { context, finalItem, attributeMappings } = actionOperation;
348
348
  if (finalItem.$id && !context.docId) {
349
- context.docId = finalItem.$id;
349
+ context.docId =
350
+ finalItem.$id || context.createdDoc.$id || context.$id || undefined;
350
351
  logger.info(`Setting docId to ${finalItem.$id} because docId not found in context, batch ${batch.$id}, context is ${JSON.stringify(context)}`);
351
352
  }
352
353
  try {
@@ -58,7 +58,6 @@ export class ImportDataActions {
58
58
  const convertedItem = convertObjectBySchema(item, conversionSchema);
59
59
  // Merge the converted item back into the original item object
60
60
  Object.assign(item, convertedItem);
61
- console.log("Converted item:", item);
62
61
  return item;
63
62
  }
64
63
  /**
@@ -73,7 +72,6 @@ export class ImportDataActions {
73
72
  if (!validationActions ||
74
73
  !Array.isArray(validationActions) ||
75
74
  !validationActions.length) {
76
- console.warn("No validation actions defined for the item, assuming true");
77
75
  return true; // Assume items without validation actions as valid.
78
76
  }
79
77
  for (const ruleDef of validationActions) {
@@ -111,7 +109,6 @@ export class ImportDataActions {
111
109
  for (const actionDef of postImportActions) {
112
110
  const { action, params } = actionDef;
113
111
  console.log(`Executing post-import action '${action}' for attribute '${mapping.targetKey}' with params ${params.join(", ")}...`);
114
- logger.info(`Executing post-import action '${action}' for attribute '${mapping.targetKey}' with params ${params.join(", ")}...`);
115
112
  try {
116
113
  await this.executeAction(action, params, context, item);
117
114
  }
@@ -133,11 +130,12 @@ export class ImportDataActions {
133
130
  });
134
131
  // Execute the action with resolved parameters
135
132
  // Parameters are passed as-is, with objects treated as single parameters
133
+ console.log(`Executing action '${actionName}' from context with params:`, resolvedParams);
136
134
  logger.info(`Executing action '${actionName}' from context: ${JSON.stringify(context, null, 2)} with params:`, resolvedParams);
137
135
  await actionMethod(this.config, ...resolvedParams);
138
136
  }
139
137
  catch (error) {
140
- logger.error(`Error executing action '${actionName}':`, error);
138
+ logger.error(`Error executing action '${actionName}' with context:`, context, error);
141
139
  throw new Error(`Execution failed for action '${actionName}': ${error.message}`);
142
140
  }
143
141
  }
@@ -40,7 +40,6 @@ export class UsersController {
40
40
  }
41
41
  }
42
42
  async createUserAndReturn(item) {
43
- console.log("Creating user with item", item);
44
43
  // Attempt to find an existing user by email or phone.
45
44
  let foundUsers = [];
46
45
  if (item.email) {
@@ -59,13 +58,11 @@ export class UsersController {
59
58
  }
60
59
  let userToReturn = foundUsers[0] || undefined;
61
60
  if (!userToReturn) {
62
- console.log("Creating user cause not found");
63
61
  userToReturn = await this.users.create(item.userId || ID.unique(), item.email || undefined, item.phone && item.phone.length < 15 && item.phone.startsWith("+")
64
62
  ? item.phone
65
63
  : undefined, item.password?.toLowerCase() || `changeMe${item.email}`.toLowerCase(), item.name || undefined);
66
64
  }
67
65
  else {
68
- console.log("Updating user cause found");
69
66
  // Update user details as necessary, ensuring email uniqueness if attempting an update.
70
67
  if (item.email &&
71
68
  item.email !== userToReturn.email &&
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.13",
4
+ "version": "0.0.15",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -11,6 +11,7 @@ import type { AppwriteConfig } from "./schema.js";
11
11
  import path from "path";
12
12
  import fs from "fs";
13
13
  import os from "os";
14
+ import { logger } from "./logging.js";
14
15
 
15
16
  const getDatabaseFromConfig = (config: AppwriteConfig) => {
16
17
  if (!config.appwriteClient) {
@@ -481,6 +482,9 @@ export const afterImportActions = {
481
482
  console.log("Created file from path: ", file.$id);
482
483
  }
483
484
  } catch (error) {
485
+ logger.error(
486
+ `Error creating file and updating field, params were:\ndbId: ${dbId}, collId: ${collId}, docId: ${docId}, fieldName: ${fieldName}, filePath: ${filePath}, fileName: ${fileName}\n\nError: ${error}`
487
+ );
484
488
  console.error("Error creating file and updating field: ", error);
485
489
  console.log(
486
490
  `Params were: dbId: ${dbId}, collId: ${collId}, docId: ${docId}, fieldName: ${fieldName}, filePath: ${filePath}, fileName: ${fileName}`
@@ -596,7 +596,6 @@ export const convertObjectByAttributeMappings = (
596
596
  }
597
597
  }
598
598
  }
599
- console.log("Resolved object:", result);
600
599
  return result;
601
600
  };
602
601
 
@@ -548,7 +548,8 @@ export class ImportController {
548
548
  const actionOperation = ContextObject.parse(JSON.parse(batch.data));
549
549
  const { context, finalItem, attributeMappings } = actionOperation;
550
550
  if (finalItem.$id && !context.docId) {
551
- context.docId = finalItem.$id;
551
+ context.docId =
552
+ finalItem.$id || context.createdDoc.$id || context.$id || undefined;
552
553
  logger.info(
553
554
  `Setting docId to ${
554
555
  finalItem.$id
@@ -92,7 +92,6 @@ export class ImportDataActions {
92
92
  const convertedItem = convertObjectBySchema(item, conversionSchema);
93
93
  // Merge the converted item back into the original item object
94
94
  Object.assign(item, convertedItem);
95
- console.log("Converted item:", item);
96
95
  return item;
97
96
  }
98
97
 
@@ -114,9 +113,6 @@ export class ImportDataActions {
114
113
  !Array.isArray(validationActions) ||
115
114
  !validationActions.length
116
115
  ) {
117
- console.warn(
118
- "No validation actions defined for the item, assuming true"
119
- );
120
116
  return true; // Assume items without validation actions as valid.
121
117
  }
122
118
  for (const ruleDef of validationActions) {
@@ -178,11 +174,6 @@ export class ImportDataActions {
178
174
  mapping.targetKey
179
175
  }' with params ${params.join(", ")}...`
180
176
  );
181
- logger.info(
182
- `Executing post-import action '${action}' for attribute '${
183
- mapping.targetKey
184
- }' with params ${params.join(", ")}...`
185
- );
186
177
  try {
187
178
  await this.executeAction(action, params, context, item);
188
179
  } catch (error) {
@@ -213,6 +204,10 @@ export class ImportDataActions {
213
204
 
214
205
  // Execute the action with resolved parameters
215
206
  // Parameters are passed as-is, with objects treated as single parameters
207
+ console.log(
208
+ `Executing action '${actionName}' from context with params:`,
209
+ resolvedParams
210
+ );
216
211
  logger.info(
217
212
  `Executing action '${actionName}' from context: ${JSON.stringify(
218
213
  context,
@@ -223,7 +218,11 @@ export class ImportDataActions {
223
218
  );
224
219
  await (actionMethod as any)(this.config, ...resolvedParams);
225
220
  } catch (error: any) {
226
- logger.error(`Error executing action '${actionName}':`, error);
221
+ logger.error(
222
+ `Error executing action '${actionName}' with context:`,
223
+ context,
224
+ error
225
+ );
227
226
  throw new Error(
228
227
  `Execution failed for action '${actionName}': ${error.message}`
229
228
  );
@@ -49,8 +49,6 @@ export class UsersController {
49
49
  }
50
50
 
51
51
  async createUserAndReturn(item: AuthUserCreate) {
52
- console.log("Creating user with item", item);
53
-
54
52
  // Attempt to find an existing user by email or phone.
55
53
  let foundUsers: Models.User<Models.Preferences>[] = [];
56
54
  if (item.email) {
@@ -71,7 +69,6 @@ export class UsersController {
71
69
  let userToReturn = foundUsers[0] || undefined;
72
70
 
73
71
  if (!userToReturn) {
74
- console.log("Creating user cause not found");
75
72
  userToReturn = await this.users.create(
76
73
  item.userId || ID.unique(),
77
74
  item.email || undefined,
@@ -82,7 +79,6 @@ export class UsersController {
82
79
  item.name || undefined
83
80
  );
84
81
  } else {
85
- console.log("Updating user cause found");
86
82
  // Update user details as necessary, ensuring email uniqueness if attempting an update.
87
83
  if (
88
84
  item.email &&