appwrite-utils-cli 0.10.86 → 1.0.1

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 (178) hide show
  1. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
  2. package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
  3. package/.appwrite/collections/Categories.yaml +182 -0
  4. package/.appwrite/collections/ExampleCollection.yaml +36 -0
  5. package/.appwrite/collections/Posts.yaml +227 -0
  6. package/.appwrite/collections/Users.yaml +149 -0
  7. package/.appwrite/config.yaml +109 -0
  8. package/.appwrite/import/README.md +148 -0
  9. package/.appwrite/import/categories-import.yaml +129 -0
  10. package/.appwrite/import/posts-import.yaml +208 -0
  11. package/.appwrite/import/users-import.yaml +130 -0
  12. package/.appwrite/importData/categories.json +194 -0
  13. package/.appwrite/importData/posts.json +270 -0
  14. package/.appwrite/importData/users.json +220 -0
  15. package/.appwrite/schemas/categories.json +128 -0
  16. package/.appwrite/schemas/exampleCollection.json +52 -0
  17. package/.appwrite/schemas/posts.json +173 -0
  18. package/.appwrite/schemas/users.json +125 -0
  19. package/README.md +260 -33
  20. package/dist/collections/attributes.js +3 -2
  21. package/dist/collections/methods.js +56 -38
  22. package/dist/config/yamlConfig.d.ts +501 -0
  23. package/dist/config/yamlConfig.js +452 -0
  24. package/dist/databases/setup.d.ts +6 -0
  25. package/dist/databases/setup.js +119 -0
  26. package/dist/functions/methods.d.ts +1 -1
  27. package/dist/functions/methods.js +5 -2
  28. package/dist/functions/openapi.d.ts +4 -0
  29. package/dist/functions/openapi.js +60 -0
  30. package/dist/interactiveCLI.d.ts +5 -0
  31. package/dist/interactiveCLI.js +194 -49
  32. package/dist/main.js +91 -30
  33. package/dist/migrations/afterImportActions.js +2 -2
  34. package/dist/migrations/appwriteToX.d.ts +10 -0
  35. package/dist/migrations/appwriteToX.js +15 -4
  36. package/dist/migrations/backup.d.ts +16 -16
  37. package/dist/migrations/dataLoader.d.ts +83 -1
  38. package/dist/migrations/dataLoader.js +4 -4
  39. package/dist/migrations/importController.js +25 -18
  40. package/dist/migrations/importDataActions.js +2 -2
  41. package/dist/migrations/logging.d.ts +9 -1
  42. package/dist/migrations/logging.js +41 -22
  43. package/dist/migrations/migrationHelper.d.ts +4 -4
  44. package/dist/migrations/relationships.js +1 -1
  45. package/dist/migrations/services/DataTransformationService.d.ts +55 -0
  46. package/dist/migrations/services/DataTransformationService.js +158 -0
  47. package/dist/migrations/services/FileHandlerService.d.ts +75 -0
  48. package/dist/migrations/services/FileHandlerService.js +236 -0
  49. package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
  50. package/dist/migrations/services/ImportOrchestrator.js +488 -0
  51. package/dist/migrations/services/RateLimitManager.d.ts +138 -0
  52. package/dist/migrations/services/RateLimitManager.js +279 -0
  53. package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
  54. package/dist/migrations/services/RelationshipResolver.js +332 -0
  55. package/dist/migrations/services/UserMappingService.d.ts +109 -0
  56. package/dist/migrations/services/UserMappingService.js +277 -0
  57. package/dist/migrations/services/ValidationService.d.ts +74 -0
  58. package/dist/migrations/services/ValidationService.js +260 -0
  59. package/dist/migrations/transfer.d.ts +0 -6
  60. package/dist/migrations/transfer.js +16 -132
  61. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
  62. package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
  63. package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
  64. package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
  65. package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
  66. package/dist/migrations/yaml/generateImportSchemas.js +575 -0
  67. package/dist/schemas/authUser.d.ts +9 -9
  68. package/dist/shared/attributeManager.d.ts +17 -0
  69. package/dist/shared/attributeManager.js +273 -0
  70. package/dist/shared/confirmationDialogs.d.ts +75 -0
  71. package/dist/shared/confirmationDialogs.js +236 -0
  72. package/dist/shared/functionManager.d.ts +48 -0
  73. package/dist/shared/functionManager.js +322 -0
  74. package/dist/shared/indexManager.d.ts +24 -0
  75. package/dist/shared/indexManager.js +150 -0
  76. package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
  77. package/dist/shared/jsonSchemaGenerator.js +313 -0
  78. package/dist/shared/logging.d.ts +10 -0
  79. package/dist/shared/logging.js +46 -0
  80. package/dist/shared/messageFormatter.d.ts +37 -0
  81. package/dist/shared/messageFormatter.js +152 -0
  82. package/dist/shared/migrationHelpers.d.ts +173 -0
  83. package/dist/shared/migrationHelpers.js +142 -0
  84. package/dist/shared/operationLogger.d.ts +3 -0
  85. package/dist/shared/operationLogger.js +25 -0
  86. package/dist/shared/operationQueue.d.ts +13 -0
  87. package/dist/shared/operationQueue.js +79 -0
  88. package/dist/shared/progressManager.d.ts +62 -0
  89. package/dist/shared/progressManager.js +215 -0
  90. package/dist/shared/schemaGenerator.d.ts +18 -0
  91. package/dist/shared/schemaGenerator.js +523 -0
  92. package/dist/storage/methods.d.ts +3 -1
  93. package/dist/storage/methods.js +144 -55
  94. package/dist/storage/schemas.d.ts +56 -16
  95. package/dist/types.d.ts +2 -2
  96. package/dist/types.js +1 -1
  97. package/dist/users/methods.d.ts +16 -0
  98. package/dist/users/methods.js +276 -0
  99. package/dist/utils/configMigration.d.ts +1 -0
  100. package/dist/utils/configMigration.js +156 -0
  101. package/dist/utils/dataConverters.d.ts +46 -0
  102. package/dist/utils/dataConverters.js +139 -0
  103. package/dist/utils/loadConfigs.d.ts +15 -4
  104. package/dist/utils/loadConfigs.js +377 -51
  105. package/dist/utils/schemaStrings.js +2 -1
  106. package/dist/utils/setupFiles.d.ts +2 -1
  107. package/dist/utils/setupFiles.js +723 -28
  108. package/dist/utils/validationRules.d.ts +43 -0
  109. package/dist/utils/validationRules.js +42 -0
  110. package/dist/utils/yamlConverter.d.ts +48 -0
  111. package/dist/utils/yamlConverter.js +98 -0
  112. package/dist/utilsController.js +65 -43
  113. package/package.json +19 -15
  114. package/src/collections/attributes.ts +3 -2
  115. package/src/collections/methods.ts +85 -51
  116. package/src/config/yamlConfig.ts +488 -0
  117. package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
  118. package/src/functions/methods.ts +8 -4
  119. package/src/functions/templates/count-docs-in-collection/package.json +25 -0
  120. package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
  121. package/src/functions/templates/typescript-node/package.json +24 -0
  122. package/src/functions/templates/typescript-node/tsconfig.json +28 -0
  123. package/src/functions/templates/uv/README.md +31 -0
  124. package/src/functions/templates/uv/pyproject.toml +29 -0
  125. package/src/interactiveCLI.ts +226 -61
  126. package/src/main.ts +111 -37
  127. package/src/migrations/afterImportActions.ts +2 -2
  128. package/src/migrations/appwriteToX.ts +17 -4
  129. package/src/migrations/dataLoader.ts +4 -4
  130. package/src/migrations/importController.ts +30 -22
  131. package/src/migrations/importDataActions.ts +2 -2
  132. package/src/migrations/relationships.ts +1 -1
  133. package/src/migrations/services/DataTransformationService.ts +196 -0
  134. package/src/migrations/services/FileHandlerService.ts +311 -0
  135. package/src/migrations/services/ImportOrchestrator.ts +669 -0
  136. package/src/migrations/services/RateLimitManager.ts +363 -0
  137. package/src/migrations/services/RelationshipResolver.ts +461 -0
  138. package/src/migrations/services/UserMappingService.ts +345 -0
  139. package/src/migrations/services/ValidationService.ts +349 -0
  140. package/src/migrations/transfer.ts +22 -228
  141. package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
  142. package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
  143. package/src/migrations/yaml/generateImportSchemas.ts +589 -0
  144. package/src/shared/attributeManager.ts +429 -0
  145. package/src/shared/confirmationDialogs.ts +327 -0
  146. package/src/shared/functionManager.ts +515 -0
  147. package/src/shared/indexManager.ts +253 -0
  148. package/src/shared/jsonSchemaGenerator.ts +403 -0
  149. package/src/shared/logging.ts +74 -0
  150. package/src/shared/messageFormatter.ts +195 -0
  151. package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
  152. package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
  153. package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
  154. package/src/shared/progressManager.ts +278 -0
  155. package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
  156. package/src/storage/methods.ts +199 -78
  157. package/src/types.ts +2 -2
  158. package/src/{migrations/users.ts → users/methods.ts} +2 -2
  159. package/src/utils/configMigration.ts +212 -0
  160. package/src/utils/loadConfigs.ts +414 -52
  161. package/src/utils/schemaStrings.ts +2 -1
  162. package/src/utils/setupFiles.ts +742 -40
  163. package/src/{migrations → utils}/validationRules.ts +1 -1
  164. package/src/utils/yamlConverter.ts +131 -0
  165. package/src/utilsController.ts +75 -54
  166. package/src/functions/templates/poetry/README.md +0 -30
  167. package/src/functions/templates/poetry/pyproject.toml +0 -16
  168. package/src/migrations/attributes.ts +0 -561
  169. package/src/migrations/backup.ts +0 -205
  170. package/src/migrations/databases.ts +0 -39
  171. package/src/migrations/dbHelpers.ts +0 -92
  172. package/src/migrations/indexes.ts +0 -40
  173. package/src/migrations/logging.ts +0 -29
  174. package/src/migrations/storage.ts +0 -538
  175. /package/src/{migrations → functions}/openapi.ts +0 -0
  176. /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
  177. /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
  178. /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
@@ -1,10 +1,12 @@
1
1
  import { Client, Databases, ID, Permission, Query, } from "node-appwrite";
2
- import { nameToIdMapping, processQueue } from "../migrations/queue.js";
2
+ import { nameToIdMapping, processQueue } from "../shared/operationQueue.js";
3
3
  import { createUpdateCollectionAttributes } from "./attributes.js";
4
4
  import { createOrUpdateIndexes } from "./indexes.js";
5
- import { SchemaGenerator } from "../migrations/schemaStrings.js";
5
+ import { SchemaGenerator } from "../shared/schemaGenerator.js";
6
6
  import { isNull, isUndefined, isNil, isPlainObject, isString, isJSONValue, chunk, } from "es-toolkit";
7
7
  import { delay, tryAwaitWithRetry } from "../utils/helperFunctions.js";
8
+ import { MessageFormatter } from "../shared/messageFormatter.js";
9
+ import { ProgressManager } from "../shared/progressManager.js";
8
10
  export const documentExists = async (db, dbId, targetCollectionId, toCreateObject) => {
9
11
  const collection = await db.getCollection(dbId, targetCollectionId);
10
12
  const attributes = collection.attributes;
@@ -48,19 +50,19 @@ export const documentExists = async (db, dbId, targetCollectionId, toCreateObjec
48
50
  };
49
51
  export const checkForCollection = async (db, dbId, collection) => {
50
52
  try {
51
- console.log(`Checking for collection with name: ${collection.name}`);
53
+ MessageFormatter.progress(`Checking for collection with name: ${collection.name}`, { prefix: "Collections" });
52
54
  const response = await tryAwaitWithRetry(async () => await db.listCollections(dbId, [Query.equal("name", collection.name)]));
53
55
  if (response.collections.length > 0) {
54
- console.log(`Collection found: ${response.collections[0].$id}`);
56
+ MessageFormatter.info(`Collection found: ${response.collections[0].$id}`, { prefix: "Collections" });
55
57
  return { ...collection, ...response.collections[0] };
56
58
  }
57
59
  else {
58
- console.log(`No collection found with name: ${collection.name}`);
60
+ MessageFormatter.info(`No collection found with name: ${collection.name}`, { prefix: "Collections" });
59
61
  return null;
60
62
  }
61
63
  }
62
64
  catch (error) {
63
- console.error(`Error checking for collection: ${error}`);
65
+ MessageFormatter.error(`Error checking for collection: ${collection.name}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Collections" });
64
66
  return null;
65
67
  }
66
68
  };
@@ -68,20 +70,20 @@ export const checkForCollection = async (db, dbId, collection) => {
68
70
  export const fetchAndCacheCollectionByName = async (db, dbId, collectionName) => {
69
71
  if (nameToIdMapping.has(collectionName)) {
70
72
  const collectionId = nameToIdMapping.get(collectionName);
71
- console.log(`\tCollection found in cache: ${collectionId}`);
73
+ MessageFormatter.debug(`Collection found in cache: ${collectionId}`, undefined, { prefix: "Collections" });
72
74
  return await tryAwaitWithRetry(async () => await db.getCollection(dbId, collectionId));
73
75
  }
74
76
  else {
75
- console.log(`\tFetching collection by name: ${collectionName}`);
77
+ MessageFormatter.progress(`Fetching collection by name: ${collectionName}`, { prefix: "Collections" });
76
78
  const collectionsPulled = await tryAwaitWithRetry(async () => await db.listCollections(dbId, [Query.equal("name", collectionName)]));
77
79
  if (collectionsPulled.total > 0) {
78
80
  const collection = collectionsPulled.collections[0];
79
- console.log(`\tCollection found: ${collection.$id}`);
81
+ MessageFormatter.info(`Collection found: ${collection.$id}`, { prefix: "Collections" });
80
82
  nameToIdMapping.set(collectionName, collection.$id);
81
83
  return collection;
82
84
  }
83
85
  else {
84
- console.log(`\tCollection not found by name: ${collectionName}`);
86
+ MessageFormatter.warning(`Collection not found by name: ${collectionName}`, { prefix: "Collections" });
85
87
  return undefined;
86
88
  }
87
89
  }
@@ -103,55 +105,71 @@ async function wipeDocumentsFromCollection(database, databaseId, collectionId) {
103
105
  ? docsResponse.documents[docsResponse.documents.length - 1].$id
104
106
  : undefined;
105
107
  if (totalDocuments % 10000 === 0) {
106
- console.log(`Found ${totalDocuments} documents...`);
108
+ MessageFormatter.progress(`Found ${totalDocuments} documents...`, { prefix: "Wipe" });
107
109
  }
108
110
  }
109
- console.log(`Found ${totalDocuments} documents to delete`);
111
+ MessageFormatter.info(`Found ${totalDocuments} documents to delete`, { prefix: "Wipe" });
112
+ if (totalDocuments === 0) {
113
+ MessageFormatter.info("No documents to delete", { prefix: "Wipe" });
114
+ return;
115
+ }
116
+ // Create progress tracker for deletion
117
+ const progress = ProgressManager.create(`delete-${collectionId}`, totalDocuments, { title: "Deleting documents" });
110
118
  const maxStackSize = 50; // Reduced batch size
111
119
  const docBatches = chunk(documents, maxStackSize);
112
- const quarterBatchSize = Math.ceil(docBatches.length / 4);
120
+ let documentsProcessed = 0;
113
121
  for (let i = 0; i < docBatches.length; i++) {
114
122
  const batch = docBatches[i];
115
123
  const deletePromises = batch.map(async (doc) => {
116
124
  try {
117
125
  await tryAwaitWithRetry(async () => database.deleteDocument(databaseId, collectionId, doc.$id));
126
+ documentsProcessed++;
127
+ progress.update(documentsProcessed);
118
128
  }
119
129
  catch (error) {
120
130
  // Skip if document doesn't exist or other non-critical errors
121
131
  if (!error.message?.includes("Document with the requested ID could not be found")) {
122
- console.error(`Failed to delete document ${doc.$id}:`, error.message);
132
+ MessageFormatter.error(`Failed to delete document ${doc.$id}`, error.message, { prefix: "Wipe" });
123
133
  }
134
+ documentsProcessed++;
135
+ progress.update(documentsProcessed);
124
136
  }
125
137
  });
126
138
  await Promise.all(deletePromises);
127
139
  await delay(50); // Increased delay between batches
128
- // Log at 25%, 50%, 75% and 100% completion
129
- if ((i + 1) % quarterBatchSize === 0 || i === docBatches.length - 1) {
130
- const percentComplete = Math.round(((i + 1) / docBatches.length) * 100);
131
- const documentsProcessed = Math.min((i + 1) * maxStackSize, totalDocuments);
132
- console.log(`Deleted ${documentsProcessed} documents (${percentComplete}% complete)`);
133
- }
140
+ // Progress is now handled by ProgressManager automatically
134
141
  }
135
- console.log(`Completed deletion of ${totalDocuments} documents from collection ${collectionId}`);
142
+ progress.stop();
143
+ MessageFormatter.success(`Completed deletion of ${totalDocuments} documents from collection ${collectionId}`, { prefix: "Wipe" });
136
144
  }
137
145
  catch (error) {
138
- console.error(`Error wiping documents from collection ${collectionId}:`, error);
146
+ MessageFormatter.error(`Error wiping documents from collection ${collectionId}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Wipe" });
139
147
  throw error;
140
148
  }
141
149
  }
142
150
  export const wipeDatabase = async (database, databaseId) => {
143
- console.log(`Wiping database: ${databaseId}`);
151
+ MessageFormatter.info(`Wiping database: ${databaseId}`, { prefix: "Wipe" });
144
152
  const existingCollections = await fetchAllCollections(databaseId, database);
145
153
  let collectionsDeleted = [];
154
+ if (existingCollections.length === 0) {
155
+ MessageFormatter.info("No collections to delete", { prefix: "Wipe" });
156
+ return collectionsDeleted;
157
+ }
158
+ const progress = ProgressManager.create(`wipe-db-${databaseId}`, existingCollections.length, { title: "Deleting collections" });
159
+ let processed = 0;
146
160
  for (const { $id: collectionId, name: name } of existingCollections) {
147
- console.log(`Deleting collection: ${collectionId}`);
161
+ MessageFormatter.progress(`Deleting collection: ${collectionId}`, { prefix: "Wipe" });
148
162
  collectionsDeleted.push({
149
163
  collectionId: collectionId,
150
164
  collectionName: name,
151
165
  });
152
166
  tryAwaitWithRetry(async () => await database.deleteCollection(databaseId, collectionId)); // Try to delete the collection and ignore errors if it doesn't exist or if it's already being deleted
167
+ processed++;
168
+ progress.update(processed);
153
169
  await delay(100);
154
170
  }
171
+ progress.stop();
172
+ MessageFormatter.success(`Deleted ${collectionsDeleted.length} collections from database`, { prefix: "Wipe" });
155
173
  return collectionsDeleted;
156
174
  };
157
175
  export const wipeCollection = async (database, databaseId, collectionId) => {
@@ -159,7 +177,7 @@ export const wipeCollection = async (database, databaseId, collectionId) => {
159
177
  Query.equal("$id", collectionId),
160
178
  ]);
161
179
  if (collections.total === 0) {
162
- console.log(`Collection ${collectionId} not found`);
180
+ MessageFormatter.warning(`Collection ${collectionId} not found`, { prefix: "Wipe" });
163
181
  return;
164
182
  }
165
183
  const collection = collections.collections[0];
@@ -202,7 +220,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
202
220
  permissions.push(Permission.write(permission.target));
203
221
  break;
204
222
  default:
205
- console.log(`Unknown permission: ${permission.permission}`);
223
+ MessageFormatter.warning(`Unknown permission: ${permission.permission}`, { prefix: "Collections" });
206
224
  break;
207
225
  }
208
226
  }
@@ -216,7 +234,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
216
234
  // Determine the correct ID for the collection
217
235
  let collectionId;
218
236
  if (!collectionToUse) {
219
- console.log(`Creating collection: ${collectionData.name}`);
237
+ MessageFormatter.info(`Creating collection: ${collectionData.name}`, { prefix: "Collections" });
220
238
  let foundColl = deletedCollections?.find((coll) => coll.collectionName.toLowerCase().trim().replace(" ", "") ===
221
239
  collectionData.name.toLowerCase().trim().replace(" ", ""));
222
240
  if (collectionData.$id) {
@@ -236,18 +254,18 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
236
254
  nameToIdMapping.set(collectionData.name, collectionToUse.$id);
237
255
  }
238
256
  catch (error) {
239
- console.error(`Failed to create collection ${collectionData.name} with ID ${collectionId}: ${error}`);
257
+ MessageFormatter.error(`Failed to create collection ${collectionData.name} with ID ${collectionId}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Collections" });
240
258
  continue;
241
259
  }
242
260
  }
243
261
  else {
244
- console.log(`Collection ${collectionData.name} exists, updating it`);
262
+ MessageFormatter.info(`Collection ${collectionData.name} exists, updating it`, { prefix: "Collections" });
245
263
  await tryAwaitWithRetry(async () => await database.updateCollection(databaseId, collectionToUse.$id, collectionData.name, permissions, collectionData.documentSecurity ?? false, collectionData.enabled ?? true));
246
264
  }
247
265
  // Add delay after creating/updating collection
248
266
  await delay(250);
249
267
  // Update attributes and indexes for the collection
250
- console.log("Creating Attributes");
268
+ MessageFormatter.progress("Creating Attributes", { prefix: "Collections" });
251
269
  await createUpdateCollectionAttributes(database, databaseId, collectionToUse,
252
270
  // @ts-expect-error
253
271
  attributes);
@@ -257,7 +275,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
257
275
  ? indexes
258
276
  : config.collections?.find((c) => c.$id === collectionToUse.$id)
259
277
  ?.indexes ?? [];
260
- console.log("Creating Indexes");
278
+ MessageFormatter.progress("Creating Indexes", { prefix: "Collections" });
261
279
  await createOrUpdateIndexes(databaseId, database, collectionToUse.$id, indexesToUse);
262
280
  // Add delay after creating indexes
263
281
  await delay(250);
@@ -268,7 +286,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
268
286
  export const generateMockData = async (database, databaseId, configCollections) => {
269
287
  for (const { collection, mockFunction } of configCollections) {
270
288
  if (mockFunction) {
271
- console.log(`Generating mock data for collection: ${collection.name}`);
289
+ MessageFormatter.progress(`Generating mock data for collection: ${collection.name}`, { prefix: "Mock Data" });
272
290
  const mockData = mockFunction();
273
291
  for (const data of mockData) {
274
292
  await database.createDocument(databaseId, collection.$id, ID.unique(), data);
@@ -277,7 +295,7 @@ export const generateMockData = async (database, databaseId, configCollections)
277
295
  }
278
296
  };
279
297
  export const fetchAllCollections = async (dbId, database) => {
280
- console.log(`Fetching all collections for database ID: ${dbId}`);
298
+ MessageFormatter.progress(`Fetching all collections for database ID: ${dbId}`, { prefix: "Collections" });
281
299
  let collections = [];
282
300
  let moreCollections = true;
283
301
  let lastCollectionId;
@@ -294,7 +312,7 @@ export const fetchAllCollections = async (dbId, database) => {
294
312
  response.collections[response.collections.length - 1].$id;
295
313
  }
296
314
  }
297
- console.log(`Fetched a total of ${collections.length} collections.`);
315
+ MessageFormatter.success(`Fetched a total of ${collections.length} collections`, { prefix: "Collections" });
298
316
  return collections;
299
317
  };
300
318
  /**
@@ -305,7 +323,7 @@ export const transferDocumentsBetweenDbsLocalToLocal = async (db, fromDbId, toDb
305
323
  let fromCollDocs = await tryAwaitWithRetry(async () => db.listDocuments(fromDbId, fromCollId, [Query.limit(50)]));
306
324
  let totalDocumentsTransferred = 0;
307
325
  if (fromCollDocs.documents.length === 0) {
308
- console.log(`No documents found in collection ${fromCollId}`);
326
+ MessageFormatter.info(`No documents found in collection ${fromCollId}`, { prefix: "Transfer" });
309
327
  return;
310
328
  }
311
329
  else if (fromCollDocs.documents.length < 50) {
@@ -360,7 +378,7 @@ export const transferDocumentsBetweenDbsLocalToLocal = async (db, fromDbId, toDb
360
378
  totalDocumentsTransferred += fromCollDocs.documents.length;
361
379
  }
362
380
  }
363
- console.log(`Transferred ${totalDocumentsTransferred} documents from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}`);
381
+ MessageFormatter.success(`Transferred ${totalDocumentsTransferred} documents from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}`, { prefix: "Transfer" });
364
382
  };
365
383
  export const transferDocumentsBetweenDbsLocalToRemote = async (localDb, endpoint, projectId, apiKey, fromDbId, toDbId, fromCollId, toCollId) => {
366
384
  const client = new Client()
@@ -371,7 +389,7 @@ export const transferDocumentsBetweenDbsLocalToRemote = async (localDb, endpoint
371
389
  const remoteDb = new Databases(client);
372
390
  let fromCollDocs = await tryAwaitWithRetry(async () => localDb.listDocuments(fromDbId, fromCollId, [Query.limit(50)]));
373
391
  if (fromCollDocs.documents.length === 0) {
374
- console.log(`No documents found in collection ${fromCollId}`);
392
+ MessageFormatter.info(`No documents found in collection ${fromCollId}`, { prefix: "Transfer" });
375
393
  return;
376
394
  }
377
395
  else if (fromCollDocs.documents.length < 50) {
@@ -426,5 +444,5 @@ export const transferDocumentsBetweenDbsLocalToRemote = async (localDb, endpoint
426
444
  totalDocumentsTransferred += fromCollDocs.documents.length;
427
445
  }
428
446
  }
429
- console.log(`Total documents transferred from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}: ${totalDocumentsTransferred}`);
447
+ MessageFormatter.success(`Total documents transferred from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}: ${totalDocumentsTransferred}`, { prefix: "Transfer" });
430
448
  };