appwrite-utils-cli 0.0.10 → 0.0.12

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.
@@ -119,8 +119,8 @@ export class ImportController {
119
119
  continue;
120
120
  console.log(`Processing update definitions for collection ID: ${collection.$id}`);
121
121
  await this.processBatch(db, collection, importDef, dataToImport);
122
+ await setAllPendingAfterImportActionsToReady(this.database, db.$id, collection.$id);
122
123
  }
123
- await setAllPendingAfterImportActionsToReady(this.database, db.$id, collection.$id);
124
124
  }
125
125
  async loadData(importDef) {
126
126
  const filePath = path.resolve(this.appwriteFolderPath, importDef.filePath);
@@ -191,29 +191,23 @@ export class ImportController {
191
191
  logger.error(`Skipping user & contact creation for ${item} due to lack of email...`);
192
192
  }
193
193
  context = { ...context, ...finalItem };
194
- if (!(await this.importDataActions.validateItem(finalItem, importDef.attributeMappings, context))) {
194
+ const validated = await this.importDataActions.validateItem(finalItem, importDef.attributeMappings, context);
195
+ if (!validated) {
195
196
  console.error("Validation failed for item:", finalItem);
197
+ logger.error("Validation failed for item:", finalItem);
196
198
  return;
197
199
  }
198
- let afterContext;
199
200
  if ((importDef.type === "create" || !importDef.type) &&
200
201
  !associatedDoc) {
201
202
  const createdContext = await this.handleCreate(context, finalItem, updateDefs, createIdToUse);
202
- if (createdContext) {
203
- afterContext = createdContext;
204
- }
203
+ context = { ...context, ...createdContext };
205
204
  logger.info(`Handled create for ${context.docId}}`);
206
205
  }
207
206
  else {
208
207
  const updatedContext = await this.handleUpdate(context, finalItem, importDef);
209
- if (updatedContext) {
210
- afterContext = updatedContext;
211
- }
208
+ context = { ...context, ...updatedContext };
212
209
  logger.info(`Handled update for ${context.docId}`);
213
210
  }
214
- if (afterContext) {
215
- context = { ...context, ...afterContext };
216
- }
217
211
  const afterImportActionContext = structuredClone(context);
218
212
  const attributeMappingsWithActions = this.getAttributeMappingsWithActions(importDef.attributeMappings, context, finalItem);
219
213
  if (attributeMappingsWithActions.some((m) => m.postImportActions)) {
@@ -364,10 +358,6 @@ export class ImportController {
364
358
  await this.importDataActions.executeAfterImportActions(finalItem, attributeMappings, context);
365
359
  // Mark batch as processed
366
360
  await this.database.deleteDocument("migrations", "batches", batch.$id);
367
- await updateOperation(this.database, operation.$id, {
368
- status: "completed",
369
- batches: [],
370
- });
371
361
  }
372
362
  catch (error) {
373
363
  logger.error(`Failed to execute batch ${batch.$id}:`, error);
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.10",
4
+ "version": "0.0.12",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -113,7 +113,6 @@ export class ImportController {
113
113
  async importCollections(db: ConfigDatabase) {
114
114
  const maxParallel = 3; // Maximum number of collections to process in parallel
115
115
  let activePromises: Promise<void>[] = []; // Array to keep track of active promises
116
-
117
116
  for (const collection of this.config.collections) {
118
117
  // Function that returns a promise for processing a single collection
119
118
  const processCollection = async (col: ConfigCollection) => {
@@ -200,13 +199,12 @@ export class ImportController {
200
199
  `Processing update definitions for collection ID: ${collection.$id}`
201
200
  );
202
201
  await this.processBatch(db, collection, importDef, dataToImport);
202
+ await setAllPendingAfterImportActionsToReady(
203
+ this.database,
204
+ db.$id,
205
+ collection.$id
206
+ );
203
207
  }
204
-
205
- await setAllPendingAfterImportActionsToReady(
206
- this.database,
207
- db.$id,
208
- collection.$id
209
- );
210
208
  }
211
209
 
212
210
  async loadData(importDef: ImportDef): Promise<any[]> {
@@ -321,19 +319,17 @@ export class ImportController {
321
319
  }
322
320
 
323
321
  context = { ...context, ...finalItem };
324
-
325
- if (
326
- !(await this.importDataActions.validateItem(
327
- finalItem,
328
- importDef.attributeMappings,
329
- context
330
- ))
331
- ) {
322
+ const validated = await this.importDataActions.validateItem(
323
+ finalItem,
324
+ importDef.attributeMappings,
325
+ context
326
+ );
327
+ if (!validated) {
332
328
  console.error("Validation failed for item:", finalItem);
329
+ logger.error("Validation failed for item:", finalItem);
333
330
  return;
334
331
  }
335
332
 
336
- let afterContext;
337
333
  if (
338
334
  (importDef.type === "create" || !importDef.type) &&
339
335
  !associatedDoc
@@ -344,9 +340,7 @@ export class ImportController {
344
340
  updateDefs,
345
341
  createIdToUse
346
342
  );
347
- if (createdContext) {
348
- afterContext = createdContext;
349
- }
343
+ context = { ...context, ...createdContext };
350
344
  logger.info(`Handled create for ${context.docId}}`);
351
345
  } else {
352
346
  const updatedContext = await this.handleUpdate(
@@ -354,14 +348,9 @@ export class ImportController {
354
348
  finalItem,
355
349
  importDef
356
350
  );
357
- if (updatedContext) {
358
- afterContext = updatedContext;
359
- }
351
+ context = { ...context, ...updatedContext };
360
352
  logger.info(`Handled update for ${context.docId}`);
361
353
  }
362
- if (afterContext) {
363
- context = { ...context, ...afterContext };
364
- }
365
354
  const afterImportActionContext = structuredClone(context);
366
355
  const attributeMappingsWithActions =
367
356
  this.getAttributeMappingsWithActions(
@@ -586,10 +575,6 @@ export class ImportController {
586
575
  "batches",
587
576
  batch.$id
588
577
  );
589
- await updateOperation(this.database, operation.$id, {
590
- status: "completed",
591
- batches: [],
592
- });
593
578
  } catch (error) {
594
579
  logger.error(`Failed to execute batch ${batch.$id}:`, error);
595
580
  }