appwrite-utils-cli 0.0.273 → 0.0.275

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.
Files changed (77) hide show
  1. package/README.md +5 -39
  2. package/dist/init.d.ts +2 -0
  3. package/dist/init.js +57 -0
  4. package/dist/main.js +62 -100
  5. package/dist/migrations/afterImportActions.d.ts +1 -4
  6. package/dist/migrations/afterImportActions.js +1 -0
  7. package/dist/migrations/appwriteToX.d.ts +46 -46
  8. package/dist/migrations/appwriteToX.js +6 -2
  9. package/dist/migrations/attributes.d.ts +1 -1
  10. package/dist/migrations/attributes.js +98 -70
  11. package/dist/migrations/backup.d.ts +240 -240
  12. package/dist/migrations/backup.js +1 -1
  13. package/dist/migrations/collections.d.ts +1 -1
  14. package/dist/migrations/collections.js +5 -5
  15. package/dist/migrations/converters.d.ts +9 -127
  16. package/dist/migrations/converters.js +1 -504
  17. package/dist/migrations/dataLoader.d.ts +470 -453
  18. package/dist/migrations/dataLoader.js +19 -1
  19. package/dist/migrations/dbHelpers.d.ts +1 -1
  20. package/dist/migrations/dbHelpers.js +3 -0
  21. package/dist/migrations/importController.d.ts +1 -1
  22. package/dist/migrations/importController.js +4 -7
  23. package/dist/migrations/importDataActions.d.ts +4 -6
  24. package/dist/migrations/importDataActions.js +6 -4
  25. package/dist/migrations/indexes.d.ts +1 -1
  26. package/dist/migrations/indexes.js +1 -1
  27. package/dist/migrations/migrationHelper.d.ts +29 -29
  28. package/dist/migrations/migrationHelper.js +1 -1
  29. package/dist/migrations/openapi.d.ts +1 -1
  30. package/dist/migrations/openapi.js +4 -1
  31. package/dist/migrations/queue.d.ts +1 -1
  32. package/dist/migrations/relationships.d.ts +5 -5
  33. package/dist/migrations/relationships.js +3 -0
  34. package/dist/migrations/schemaStrings.d.ts +2 -2
  35. package/dist/migrations/schemaStrings.js +93 -8
  36. package/dist/migrations/setupDatabase.d.ts +1 -1
  37. package/dist/migrations/setupDatabase.js +1 -1
  38. package/dist/migrations/storage.d.ts +1 -1
  39. package/dist/migrations/users.d.ts +1 -1
  40. package/dist/schemas/authUser.d.ts +12 -10
  41. package/dist/types.d.ts +0 -5
  42. package/dist/types.js +0 -2
  43. package/dist/utils/helperFunctions.d.ts +2 -3
  44. package/dist/utils/loadConfigs.d.ts +13 -0
  45. package/dist/utils/loadConfigs.js +47 -0
  46. package/dist/utils/setupFiles.d.ts +1 -0
  47. package/dist/utils/setupFiles.js +98 -223
  48. package/dist/utilsController.d.ts +1 -3
  49. package/dist/utilsController.js +14 -18
  50. package/package.json +9 -2
  51. package/src/init.ts +64 -0
  52. package/src/main.ts +73 -98
  53. package/src/migrations/afterImportActions.ts +1 -5
  54. package/src/migrations/appwriteToX.ts +6 -2
  55. package/src/migrations/attributes.ts +198 -145
  56. package/src/migrations/backup.ts +1 -1
  57. package/src/migrations/collections.ts +6 -12
  58. package/src/migrations/converters.ts +1 -540
  59. package/src/migrations/dataLoader.ts +19 -2
  60. package/src/migrations/dbHelpers.ts +4 -1
  61. package/src/migrations/importController.ts +5 -15
  62. package/src/migrations/importDataActions.ts +10 -14
  63. package/src/migrations/indexes.ts +1 -1
  64. package/src/migrations/migrationHelper.ts +1 -1
  65. package/src/migrations/openapi.ts +4 -1
  66. package/src/migrations/queue.ts +1 -1
  67. package/src/migrations/relationships.ts +4 -1
  68. package/src/migrations/schemaStrings.ts +106 -9
  69. package/src/migrations/setupDatabase.ts +1 -1
  70. package/src/migrations/storage.ts +1 -1
  71. package/src/migrations/users.ts +1 -1
  72. package/src/types.ts +0 -5
  73. package/src/utils/helperFunctions.ts +2 -3
  74. package/src/utils/loadConfigs.ts +55 -0
  75. package/src/utils/setupFiles.ts +114 -225
  76. package/src/utilsController.ts +27 -35
  77. package/src/migrations/schema.ts +0 -748
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { attributeSchema, parseAttribute, CollectionCreateSchema, } from "./schema.js";
2
+ import { attributeSchema, parseAttribute, CollectionCreateSchema, } from "appwrite-utils";
3
3
  export const BackupSchema = z.object({
4
4
  $id: z.string(),
5
5
  $createdAt: z.string(),
@@ -1,5 +1,5 @@
1
1
  import { Databases, type Models } from "node-appwrite";
2
- import type { AppwriteConfig, CollectionCreate } from "./schema.js";
2
+ import type { AppwriteConfig, CollectionCreate } from "appwrite-utils";
3
3
  export declare const documentExists: (db: Databases, dbId: string, targetCollectionId: string, toCreateObject: any) => Promise<Models.Document | null>;
4
4
  export declare const checkForCollection: (db: Databases, dbId: string, collection: Partial<CollectionCreate>) => Promise<Models.Collection | null>;
5
5
  export declare const fetchAndCacheCollectionByName: (db: Databases, dbId: string, collectionName: string) => Promise<Models.Collection | undefined>;
@@ -2,11 +2,8 @@ import { Databases, ID, Permission, Query } from "node-appwrite";
2
2
  import { nameToIdMapping, processQueue } from "./queue.js";
3
3
  import { createUpdateCollectionAttributes } from "./attributes.js";
4
4
  import { createOrUpdateIndexes } from "./indexes.js";
5
- import { ensureDirectoryExistence, toCamelCase, toPascalCase, writeFileSync, } from "../utils/index.js";
6
5
  import _ from "lodash";
7
6
  import { SchemaGenerator } from "./schemaStrings.js";
8
- import path from "path";
9
- const { join } = _;
10
7
  export const documentExists = async (db, dbId, targetCollectionId, toCreateObject) => {
11
8
  // Had to do this because kept running into issues with type checking arrays so, sorry 40ms
12
9
  const collection = await db.getCollection(dbId, targetCollectionId);
@@ -112,6 +109,9 @@ export const generateSchemas = async (config, appwriteFolderPath) => {
112
109
  };
113
110
  export const createOrUpdateCollections = async (database, databaseId, config, deletedCollections) => {
114
111
  const configCollections = config.collections;
112
+ if (!configCollections) {
113
+ return;
114
+ }
115
115
  const usedIds = new Set(); // To track IDs used in this operation
116
116
  for (const { attributes, indexes, ...collection } of configCollections) {
117
117
  // Prepare permissions for the collection
@@ -173,13 +173,13 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
173
173
  }
174
174
  }
175
175
  else {
176
- console.log(`Collection ${collection.name} already exists.`);
176
+ console.log(`Collection ${collection.name} exists, using it`);
177
177
  }
178
178
  // Update attributes and indexes for the collection
179
179
  console.log("Creating Attributes");
180
180
  await createUpdateCollectionAttributes(database, databaseId, collectionToUse, attributes);
181
181
  console.log("Creating Indexes");
182
- await createOrUpdateIndexes(databaseId, database, collectionToUse.$id, indexes);
182
+ await createOrUpdateIndexes(databaseId, database, collectionToUse.$id, indexes ?? []);
183
183
  }
184
184
  // Process any remaining tasks in the queue
185
185
  await processQueue(database, databaseId);
@@ -1,121 +1,3 @@
1
- export interface ConverterFunctions {
2
- [key: string]: (value: any) => any;
3
- }
4
- export declare const converterFunctions: {
5
- /**
6
- * Converts any value to a string. Handles null and undefined explicitly.
7
- * @param {any} value The value to convert.
8
- * @return {string | null} The converted string or null if the value is null or undefined.
9
- */
10
- anyToString(value: any): string | null;
11
- /**
12
- * Converts any value to a number. Returns null for non-numeric values, null, or undefined.
13
- * @param {any} value The value to convert.
14
- * @return {number | null} The converted number or null.
15
- */
16
- anyToNumber(value: any): number | null;
17
- /**
18
- * Converts any value to a boolean. Specifically handles string representations.
19
- * @param {any} value The value to convert.
20
- * @return {boolean | null} The converted boolean or null if conversion is not possible.
21
- */
22
- anyToBoolean(value: any): boolean | null;
23
- /**
24
- * Converts any value to an array, attempting to split strings by a specified separator.
25
- * @param {any} value The value to convert.
26
- * @param {string | undefined} separator The separator to use when splitting strings.
27
- * @return {any[]} The resulting array after conversion.
28
- */
29
- anyToAnyArray(value: any): any[];
30
- /**
31
- * Converts any value to an array of strings. If the input is already an array, returns it as is.
32
- * Otherwise, if the input is a string, returns an array with the string as the only element.
33
- * Otherwise, returns an empty array.
34
- * @param {any} value The value to convert.
35
- * @return {string[]} The resulting array after conversion.
36
- */
37
- anyToStringArray(value: any): string[];
38
- /**
39
- * A function that converts any type of value to an array of numbers.
40
- *
41
- * @param {any} value - the value to be converted
42
- * @return {number[]} an array of numbers
43
- */
44
- anyToNumberArray(value: any): number[];
45
- trim(value: string): string;
46
- /**
47
- * Removes the start and end quotes from a string.
48
- * @param value The string to remove quotes from.
49
- * @return The string with quotes removed.
50
- **/
51
- removeStartEndQuotes(value: string): string;
52
- /**
53
- * Tries to split a string by different separators and returns the split that has the most uniform segment lengths.
54
- * This can be particularly useful for structured data like phone numbers.
55
- * @param value The string to split.
56
- * @return The split string array that has the most uniform segment lengths.
57
- */
58
- trySplitByDifferentSeparators(value: string): string[];
59
- joinValues(values: any[]): any;
60
- joinBySpace(values: any[]): any;
61
- joinByComma(values: any[]): any;
62
- joinByPipe(values: any[]): any;
63
- joinBySemicolon(values: any[]): any;
64
- joinByColon(values: any[]): any;
65
- joinBySlash(values: any[]): any;
66
- joinByHyphen(values: any[]): any;
67
- splitByComma(value: string): any;
68
- splitByPipe(value: string): any;
69
- splitBySemicolon(value: string): any;
70
- splitByColon(value: string): any;
71
- splitBySlash(value: string): any;
72
- splitByBackslash(value: string): any;
73
- splitBySpace(value: string): any;
74
- splitByDot(value: string): any;
75
- splitByUnderscore(value: string): any;
76
- splitByHyphen(value: string): any;
77
- /**
78
- * Takes the first element of an array and returns it.
79
- * @param {any[]} value The array to take the first element from.
80
- * @return {any} The first element of the array.
81
- */
82
- pickFirstElement(value: any[]): any;
83
- /**
84
- * Takes the last element of an array and returns it.
85
- * @param {any[]} value The array to take the last element from.
86
- * @return {any} The last element of the array.
87
- */
88
- pickLastElement(value: any[]): any;
89
- /**
90
- * Converts an object to a JSON string.
91
- * @param {any} object The object to convert.
92
- * @return {string} The JSON string representation of the object.
93
- */
94
- stringifyObject(object: any): string;
95
- /**
96
- * Converts a JSON string to an object.
97
- * @param {string} jsonString The JSON string to convert.
98
- * @return {any} The object representation of the JSON string.
99
- */
100
- parseObject(jsonString: string): any;
101
- convertPhoneStringToUSInternational(value: string): string;
102
- convertEmptyToNull(value: any): any;
103
- /**
104
- * A function that removes invalid elements from an array
105
- *
106
- * @param {any[]} array - the input array
107
- * @return {any[]} the filtered array without invalid elements
108
- */
109
- removeInvalidElements(array: any[]): any[];
110
- validateOrNullEmail(email: string): string | null;
111
- /**
112
- * Tries to parse a date from various formats using Luxon with enhanced error reporting.
113
- * @param {string | number} input The input date as a string or timestamp.
114
- * @return {string | null} The parsed date in ISO 8601 format or null if parsing failed.
115
- */
116
- safeParseDate(input: string | number): number | null;
117
- safeParseDateToYYYYMMDD(input: string | number): string | null;
118
- };
119
1
  /**
120
2
  * Deeply converts all properties of an object (or array) to strings.
121
3
  * @param data The input data to convert.
@@ -148,21 +30,21 @@ export declare const convertObjectBySchema: (obj: Record<string, any>, schema: R
148
30
  */
149
31
  export declare const convertObjectByAttributeMappings: (obj: Record<string, any>, attributeMappings: {
150
32
  targetKey: string;
151
- converters: string[];
152
- validationActions: {
153
- params: string[];
154
- action: string;
155
- }[];
156
- postImportActions: {
157
- params: (string | Record<string, any>)[];
158
- action: string;
159
- }[];
160
33
  oldKey?: string | undefined;
161
34
  oldKeys?: string[] | undefined;
162
35
  fileData?: {
163
36
  path: string;
164
37
  name: string;
165
38
  } | undefined;
39
+ converters?: string[] | undefined;
40
+ validationActions?: {
41
+ params: string[];
42
+ action: string;
43
+ }[] | undefined;
44
+ postImportActions?: {
45
+ params: (string | Record<string, any>)[];
46
+ action: string;
47
+ }[] | undefined;
166
48
  }[]) => Record<string, any>;
167
49
  /**
168
50
  * Ensures data conversion without mutating the original input.