appwrite-utils-cli 0.0.68 → 0.0.69

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
@@ -132,6 +132,7 @@ This setup ensures that developers have robust tools at their fingertips to mana
132
132
 
133
133
  ### Changelog
134
134
 
135
+ - 0.0.69: Fixed single ID not getting replaced due to the below change =D also, `nice`
135
136
  - 0.0.68: Fixed the occasional case where, when mapping ID's from old data to new, there would be an array of ID's to match against. `idMappings` now supports arrays.
136
137
  - 0.0.67: Fixed `updates` in `importDef`'s update mappings overwriting postImportActions from the original
137
138
  - 0.0.57: Fixed `dataLoader`'s `idMapping`'s giving me issues
@@ -229,6 +229,10 @@ export const afterImportActions = {
229
229
  // console.log(
230
230
  // `Processing field ${fieldName} in collection ${collId} for document ${docId} in database ${dbId} in bucket ${bucketId} with path ${filePath} and name ${fileName}...`
231
231
  // );
232
+ if (filePath.length === 0 || fileName.length === 0) {
233
+ console.error(`File path or name is empty for field ${fieldName} in collection ${collId}, skipping...`);
234
+ return;
235
+ }
232
236
  let isArray = false;
233
237
  if (!attribute) {
234
238
  console.log(`Field ${fieldName} not found in collection ${collId}, weird, skipping...`);
@@ -74,6 +74,15 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
74
74
  error?: string | undefined;
75
75
  xdefault?: number | null | undefined;
76
76
  min?: number | undefined;
77
+ /**
78
+ * Prepares the data for creating user collection documents.
79
+ * This involves loading the data, transforming it according to the import definition,
80
+ * and handling the creation of new unique IDs for each item.
81
+ *
82
+ * @param db - The database configuration.
83
+ * @param collection - The collection configuration.
84
+ * @param importDef - The import definition containing the attribute mappings and other relevant info.
85
+ */
77
86
  max?: number | undefined;
78
87
  }, {
79
88
  key: string;
@@ -666,16 +675,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
666
675
  converters?: string[] | undefined;
667
676
  validationActions?: {
668
677
  params: string[];
669
- action: string; /**
670
- * Generates attribute mappings with post-import actions based on the provided attribute mappings.
671
- * This method checks each mapping for a fileData attribute and adds a post-import action to create a file
672
- * and update the field with the file's ID if necessary.
673
- *
674
- * @param attributeMappings - The attribute mappings from the import definition.
675
- * @param context - The context object containing information about the database, collection, and document.
676
- * @param item - The item being imported, used for resolving template paths in fileData mappings.
677
- * @returns The attribute mappings updated with any necessary post-import actions.
678
- */
678
+ action: string;
679
679
  }[] | undefined;
680
680
  postImportActions?: {
681
681
  params: (string | Record<string, any>)[];
@@ -1295,16 +1295,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
1295
1295
  converters?: string[] | undefined;
1296
1296
  validationActions?: {
1297
1297
  params: string[];
1298
- action: string; /**
1299
- * Generates attribute mappings with post-import actions based on the provided attribute mappings.
1300
- * This method checks each mapping for a fileData attribute and adds a post-import action to create a file
1301
- * and update the field with the file's ID if necessary.
1302
- *
1303
- * @param attributeMappings - The attribute mappings from the import definition.
1304
- * @param context - The context object containing information about the database, collection, and document.
1305
- * @param item - The item being imported, used for resolving template paths in fileData mappings.
1306
- * @returns The attribute mappings updated with any necessary post-import actions.
1307
- */
1298
+ action: string;
1308
1299
  }[] | undefined;
1309
1300
  postImportActions?: {
1310
1301
  params: (string | Record<string, any>)[];
@@ -1708,16 +1699,7 @@ export declare class DataLoader {
1708
1699
  converters?: string[] | undefined;
1709
1700
  validationActions?: {
1710
1701
  params: string[];
1711
- action: string; /**
1712
- * Generates attribute mappings with post-import actions based on the provided attribute mappings.
1713
- * This method checks each mapping for a fileData attribute and adds a post-import action to create a file
1714
- * and update the field with the file's ID if necessary.
1715
- *
1716
- * @param attributeMappings - The attribute mappings from the import definition.
1717
- * @param context - The context object containing information about the database, collection, and document.
1718
- * @param item - The item being imported, used for resolving template paths in fileData mappings.
1719
- * @returns The attribute mappings updated with any necessary post-import actions.
1720
- */
1702
+ action: string;
1721
1703
  }[] | undefined;
1722
1704
  postImportActions?: {
1723
1705
  params: (string | Record<string, any>)[];
@@ -453,9 +453,9 @@ export class DataLoader {
453
453
  continue;
454
454
  // Handle cases where sourceValue is an array
455
455
  const sourceValues = Array.isArray(sourceValue)
456
- ? sourceValue
457
- : [sourceValue];
458
- const newData = [];
456
+ ? sourceValue.map((sourceValue) => `${sourceValue}`)
457
+ : [`${sourceValue}`];
458
+ let newData = [];
459
459
  for (const valueToMatch of sourceValues) {
460
460
  // Find matching data in the target collection
461
461
  const foundData = targetCollectionData.data.filter(({ context, finalData }) => {
@@ -468,12 +468,14 @@ export class DataLoader {
468
468
  });
469
469
  if (foundData.length) {
470
470
  newData.push(...foundData.map((data) => {
471
- return this.getValueFromData(data.finalData, data.context, idMapping.targetField);
471
+ const newValue = this.getValueFromData(data.finalData, data.context, idMapping.targetField);
472
+ return newValue;
472
473
  }));
473
474
  }
474
475
  else {
475
476
  logger.info(`No data found for collection: ${targetCollectionKey} with value: ${valueToMatch} for field: ${fieldToSetKey} -- idMapping: ${JSON.stringify(idMapping, null, 2)}`);
476
477
  }
478
+ continue;
477
479
  }
478
480
  const getCurrentDataFiltered = (currentData) => {
479
481
  if (Array.isArray(currentData.finalData[fieldToSetKey])) {
@@ -511,7 +513,8 @@ export class DataLoader {
511
513
  ...newData,
512
514
  ].filter((value) => value !== null &&
513
515
  value !== undefined &&
514
- value !== "")),
516
+ value !== "" &&
517
+ !sourceValues.includes(`${value}`))),
515
518
  ];
516
519
  }
517
520
  }
@@ -528,7 +531,8 @@ export class DataLoader {
528
531
  collectionData.data[i].finalData[fieldToSetKey] = [
529
532
  ...new Set([currentDataFiltered, ...newData].filter((value) => value !== null &&
530
533
  value !== undefined &&
531
- value !== "")),
534
+ value !== "" &&
535
+ !sourceValues.includes(`${value}`))),
532
536
  ].slice(0, 1)[0];
533
537
  }
534
538
  else if (!Array.isArray(newData) &&
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.68",
4
+ "version": "0.0.69",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -433,6 +433,13 @@ export const afterImportActions = {
433
433
  // console.log(
434
434
  // `Processing field ${fieldName} in collection ${collId} for document ${docId} in database ${dbId} in bucket ${bucketId} with path ${filePath} and name ${fileName}...`
435
435
  // );
436
+ if (filePath.length === 0 || fileName.length === 0) {
437
+ console.error(
438
+ `File path or name is empty for field ${fieldName} in collection ${collId}, skipping...`
439
+ );
440
+ return;
441
+ }
442
+
436
443
  let isArray = false;
437
444
  if (!attribute) {
438
445
  console.log(
@@ -567,9 +567,9 @@ export class DataLoader {
567
567
 
568
568
  // Handle cases where sourceValue is an array
569
569
  const sourceValues = Array.isArray(sourceValue)
570
- ? sourceValue
571
- : [sourceValue];
572
- const newData = [];
570
+ ? sourceValue.map((sourceValue) => `${sourceValue}`)
571
+ : [`${sourceValue}`];
572
+ let newData = [];
573
573
 
574
574
  for (const valueToMatch of sourceValues) {
575
575
  // Find matching data in the target collection
@@ -593,11 +593,12 @@ export class DataLoader {
593
593
  if (foundData.length) {
594
594
  newData.push(
595
595
  ...foundData.map((data) => {
596
- return this.getValueFromData(
596
+ const newValue = this.getValueFromData(
597
597
  data.finalData,
598
598
  data.context,
599
599
  idMapping.targetField
600
600
  );
601
+ return newValue;
601
602
  })
602
603
  );
603
604
  } else {
@@ -609,6 +610,7 @@ export class DataLoader {
609
610
  )}`
610
611
  );
611
612
  }
613
+ continue;
612
614
  }
613
615
 
614
616
  const getCurrentDataFiltered = (currentData: any) => {
@@ -660,7 +662,8 @@ export class DataLoader {
660
662
  (value: any) =>
661
663
  value !== null &&
662
664
  value !== undefined &&
663
- value !== ""
665
+ value !== "" &&
666
+ !sourceValues.includes(`${value}`)
664
667
  )
665
668
  ),
666
669
  ];
@@ -680,7 +683,8 @@ export class DataLoader {
680
683
  (value: any) =>
681
684
  value !== null &&
682
685
  value !== undefined &&
683
- value !== ""
686
+ value !== "" &&
687
+ !sourceValues.includes(`${value}`)
684
688
  )
685
689
  ),
686
690
  ].slice(0, 1)[0];