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
@@ -2,10 +2,12 @@ import { Compression, Databases, Permission, Query, Role, Storage, } from "node-
2
2
  import { tryAwaitWithRetry } from "appwrite-utils";
3
3
  import { getClientFromConfig } from "../utils/getClientFromConfig.js";
4
4
  import { ulid } from "ulidx";
5
- import { logOperation } from "../migrations/helper.js";
6
- import { splitIntoBatches } from "../migrations/migrationHelper.js";
5
+ import { logOperation } from "../shared/operationLogger.js";
6
+ import { splitIntoBatches } from "../shared/migrationHelpers.js";
7
7
  import { retryFailedPromises } from "../utils/retryFailedPromises.js";
8
8
  import { InputFile } from "node-appwrite/file";
9
+ import { MessageFormatter, Messages } from "../shared/messageFormatter.js";
10
+ import { ProgressManager } from "../shared/progressManager.js";
9
11
  export const getStorage = (config) => {
10
12
  const client = getClientFromConfig(config);
11
13
  return new Storage(client);
@@ -83,19 +85,37 @@ export const ensureDatabaseConfigBucketsExist = async (storage, config, database
83
85
  }
84
86
  }
85
87
  };
86
- export const wipeDocumentStorage = async (storage, bucketId) => {
87
- console.log(`Wiping storage for bucket ID: ${bucketId}`);
88
+ export const wipeDocumentStorage = async (storage, bucketId, options = {}) => {
89
+ MessageFormatter.warning(`About to delete all files in bucket: ${bucketId}`);
90
+ if (!options.skipConfirmation) {
91
+ const { ConfirmationDialogs } = await import("../shared/confirmationDialogs.js");
92
+ const confirmed = await ConfirmationDialogs.confirmDestructiveOperation({
93
+ operation: "Storage Wipe",
94
+ targets: [bucketId],
95
+ consequences: [
96
+ "Delete ALL files in the storage bucket",
97
+ "This action cannot be undone",
98
+ ],
99
+ requireExplicitConfirmation: true,
100
+ confirmationText: "DELETE FILES",
101
+ });
102
+ if (!confirmed) {
103
+ MessageFormatter.info("Storage wipe cancelled by user");
104
+ return;
105
+ }
106
+ }
107
+ MessageFormatter.progress(`Scanning files in bucket: ${bucketId}`);
88
108
  let moreFiles = true;
89
109
  let lastFileId;
90
110
  const allFiles = [];
111
+ // First pass: collect all file IDs
91
112
  while (moreFiles) {
92
- const queries = [Query.limit(100)]; // Adjust the limit as needed
113
+ const queries = [Query.limit(100)];
93
114
  if (lastFileId) {
94
115
  queries.push(Query.cursorAfter(lastFileId));
95
116
  }
96
117
  const filesPulled = await tryAwaitWithRetry(async () => await storage.listFiles(bucketId, queries));
97
118
  if (filesPulled.files.length === 0) {
98
- console.log("No files found, done!");
99
119
  moreFiles = false;
100
120
  break;
101
121
  }
@@ -103,16 +123,32 @@ export const wipeDocumentStorage = async (storage, bucketId) => {
103
123
  const fileIds = filesPulled.files.map((file) => file.$id);
104
124
  allFiles.push(...fileIds);
105
125
  }
106
- moreFiles = filesPulled.files.length === 100; // Adjust based on the limit
126
+ moreFiles = filesPulled.files.length === 100;
107
127
  if (moreFiles) {
108
128
  lastFileId = filesPulled.files[filesPulled.files.length - 1].$id;
109
129
  }
110
130
  }
111
- for (const fileId of allFiles) {
112
- console.log(`Deleting file: ${fileId}`);
113
- await tryAwaitWithRetry(async () => await storage.deleteFile(bucketId, fileId));
131
+ if (allFiles.length === 0) {
132
+ MessageFormatter.info("No files found in bucket");
133
+ return;
134
+ }
135
+ // Second pass: delete files with progress tracking
136
+ const progress = ProgressManager.create(`wipe-${bucketId}`, allFiles.length, {
137
+ title: `Deleting files from ${bucketId}`,
138
+ });
139
+ try {
140
+ for (let i = 0; i < allFiles.length; i++) {
141
+ const fileId = allFiles[i];
142
+ await tryAwaitWithRetry(async () => await storage.deleteFile(bucketId, fileId));
143
+ progress.update(i + 1, `Deleted file: ${fileId.slice(0, 20)}...`);
144
+ }
145
+ progress.stop();
146
+ MessageFormatter.success(`All ${MessageFormatter.formatNumber(allFiles.length)} files in bucket ${bucketId} have been deleted`);
147
+ }
148
+ catch (error) {
149
+ progress.fail(error instanceof Error ? error.message : String(error));
150
+ throw error;
114
151
  }
115
- console.log(`All files in bucket ${bucketId} have been deleted.`);
116
152
  };
117
153
  export const initOrGetDocumentStorage = async (storage, config, dbId, bucketName) => {
118
154
  const bucketId = bucketName ??
@@ -138,9 +174,9 @@ export const initOrGetBackupStorage = async (config, storage) => {
138
174
  }
139
175
  };
140
176
  export const backupDatabase = async (config, database, databaseId, storage) => {
141
- console.log("---------------------------------");
142
- console.log("Starting Database Backup of " + databaseId);
143
- console.log("---------------------------------");
177
+ const startTime = Date.now();
178
+ MessageFormatter.banner("Database Backup", `Backing up database: ${databaseId}`);
179
+ MessageFormatter.info(Messages.BACKUP_STARTED(databaseId));
144
180
  let data = {
145
181
  database: "",
146
182
  collections: [],
@@ -154,25 +190,57 @@ export const backupDatabase = async (config, database, databaseId, storage) => {
154
190
  total: 100,
155
191
  error: "",
156
192
  status: "in_progress",
157
- });
193
+ }, undefined, config.useMigrations);
194
+ let progress = null;
195
+ let totalDocuments = 0;
196
+ let processedDocuments = 0;
158
197
  try {
159
198
  const db = await tryAwaitWithRetry(async () => await database.get(databaseId));
160
199
  data.database = JSON.stringify(db);
200
+ // First pass: count collections and documents for progress tracking
201
+ MessageFormatter.step(1, 3, "Analyzing database structure");
161
202
  let lastCollectionId = "";
162
203
  let moreCollections = true;
163
- let progress = 0;
164
- let total = 0;
204
+ let totalCollections = 0;
205
+ while (moreCollections) {
206
+ const collectionResponse = await tryAwaitWithRetry(async () => await database.listCollections(databaseId, [
207
+ Query.limit(500),
208
+ ...(lastCollectionId ? [Query.cursorAfter(lastCollectionId)] : []),
209
+ ]));
210
+ totalCollections += collectionResponse.collections.length;
211
+ // Count documents in each collection
212
+ for (const { $id: collectionId } of collectionResponse.collections) {
213
+ try {
214
+ const documentCount = await tryAwaitWithRetry(async () => (await database.listDocuments(databaseId, collectionId, [Query.limit(1)])).total);
215
+ totalDocuments += documentCount;
216
+ }
217
+ catch (error) {
218
+ MessageFormatter.warning(`Could not count documents in collection ${collectionId}`);
219
+ }
220
+ }
221
+ moreCollections = collectionResponse.collections.length === 500;
222
+ if (moreCollections) {
223
+ lastCollectionId = collectionResponse.collections[collectionResponse.collections.length - 1].$id;
224
+ }
225
+ }
226
+ const totalItems = totalCollections + totalDocuments;
227
+ progress = ProgressManager.create(`backup-${databaseId}`, totalItems, {
228
+ title: `Backing up ${databaseId}`,
229
+ });
230
+ MessageFormatter.step(2, 3, `Processing ${totalCollections} collections and ${totalDocuments} documents`);
231
+ // Second pass: actual backup with progress tracking
232
+ lastCollectionId = "";
233
+ moreCollections = true;
165
234
  while (moreCollections) {
166
235
  const collectionResponse = await tryAwaitWithRetry(async () => await database.listCollections(databaseId, [
167
236
  Query.limit(500),
168
237
  ...(lastCollectionId ? [Query.cursorAfter(lastCollectionId)] : []),
169
238
  ]));
170
- total += collectionResponse.collections.length;
171
239
  for (const { $id: collectionId, name: collectionName, } of collectionResponse.collections) {
172
240
  try {
173
241
  const collection = await tryAwaitWithRetry(async () => await database.getCollection(databaseId, collectionId));
174
- progress++;
175
242
  data.collections.push(JSON.stringify(collection));
243
+ progress?.increment(1, `Processing collection: ${collectionName}`);
176
244
  let lastDocumentId = "";
177
245
  let moreDocuments = true;
178
246
  let collectionDocumentCount = 0;
@@ -183,7 +251,6 @@ export const backupDatabase = async (config, database, databaseId, storage) => {
183
251
  ? [Query.cursorAfter(lastDocumentId)]
184
252
  : []),
185
253
  ]));
186
- total += documentResponse.documents.length;
187
254
  collectionDocumentCount += documentResponse.documents.length;
188
255
  const documentPromises = documentResponse.documents.map(({ $id: documentId }) => database.getDocument(databaseId, collectionId, documentId));
189
256
  const promiseBatches = splitIntoBatches(documentPromises);
@@ -191,31 +258,35 @@ export const backupDatabase = async (config, database, databaseId, storage) => {
191
258
  for (const batch of promiseBatches) {
192
259
  const successfulDocuments = await retryFailedPromises(batch);
193
260
  documentsPulled.push(...successfulDocuments);
261
+ // Update progress for each batch
262
+ progress?.increment(successfulDocuments.length, `Processing ${collectionName}: ${processedDocuments + successfulDocuments.length}/${totalDocuments} documents`);
263
+ processedDocuments += successfulDocuments.length;
194
264
  }
195
265
  data.documents.push({
196
266
  collectionId: collectionId,
197
267
  data: JSON.stringify(documentsPulled),
198
268
  });
199
- progress += documentsPulled.length;
200
- await logOperation(database, databaseId, {
201
- operationType: "backup",
202
- collectionId: collectionId,
203
- data: `Backing up, ${data.collections.length} collections so far`,
204
- progress: progress,
205
- total: total,
206
- error: "",
207
- status: "in_progress",
208
- }, backupOperation.$id);
269
+ if (backupOperation) {
270
+ await logOperation(database, databaseId, {
271
+ operationType: "backup",
272
+ collectionId: collectionId,
273
+ data: `Backing up, ${data.collections.length} collections so far`,
274
+ progress: processedDocuments,
275
+ total: totalDocuments,
276
+ error: "",
277
+ status: "in_progress",
278
+ }, backupOperation.$id, config.useMigrations);
279
+ }
209
280
  moreDocuments = documentResponse.documents.length === 500;
210
281
  if (moreDocuments) {
211
282
  lastDocumentId =
212
283
  documentResponse.documents[documentResponse.documents.length - 1].$id;
213
284
  }
214
285
  }
215
- console.log(`Collection ${collectionName} backed up with ${collectionDocumentCount} documents.`);
286
+ MessageFormatter.success(`Collection ${collectionName} backed up with ${MessageFormatter.formatNumber(collectionDocumentCount)} documents`);
216
287
  }
217
288
  catch (error) {
218
- console.log(`Collection ${collectionName} must not exist, continuing...`);
289
+ MessageFormatter.warning(`Collection ${collectionName} could not be backed up: ${error instanceof Error ? error.message : String(error)}`);
219
290
  continue;
220
291
  }
221
292
  }
@@ -225,32 +296,50 @@ export const backupDatabase = async (config, database, databaseId, storage) => {
225
296
  collectionResponse.collections[collectionResponse.collections.length - 1].$id;
226
297
  }
227
298
  }
299
+ MessageFormatter.step(3, 3, "Creating backup file");
228
300
  const bucket = await initOrGetDocumentStorage(storage, config, databaseId);
229
- const inputFile = InputFile.fromPlainText(JSON.stringify(data), `${new Date().toISOString()}-${databaseId}.json`);
301
+ const backupData = JSON.stringify(data);
302
+ const backupSize = Buffer.byteLength(backupData, 'utf8');
303
+ const fileName = `${new Date().toISOString()}-${databaseId}.json`;
304
+ const inputFile = InputFile.fromPlainText(backupData, fileName);
230
305
  const fileCreated = await storage.createFile(bucket.$id, ulid(), inputFile);
231
- await logOperation(database, databaseId, {
232
- operationType: "backup",
233
- collectionId: "",
234
- data: fileCreated.$id,
235
- progress: 100,
236
- total: total,
237
- error: "",
238
- status: "completed",
239
- }, backupOperation.$id);
240
- console.log("---------------------------------");
241
- console.log("Database Backup Complete");
242
- console.log("---------------------------------");
306
+ progress?.stop();
307
+ if (backupOperation) {
308
+ await logOperation(database, databaseId, {
309
+ operationType: "backup",
310
+ collectionId: "",
311
+ data: fileCreated.$id,
312
+ progress: totalItems,
313
+ total: totalItems,
314
+ error: "",
315
+ status: "completed",
316
+ }, backupOperation.$id, config.useMigrations);
317
+ }
318
+ const duration = Date.now() - startTime;
319
+ MessageFormatter.operationSummary("Backup", {
320
+ database: databaseId,
321
+ collections: data.collections.length,
322
+ documents: processedDocuments,
323
+ fileSize: MessageFormatter.formatBytes(backupSize),
324
+ backupFile: fileName,
325
+ bucket: bucket.$id,
326
+ }, duration);
327
+ MessageFormatter.success(Messages.BACKUP_COMPLETED(databaseId, backupSize));
243
328
  }
244
329
  catch (error) {
245
- console.error("Error during backup:", error);
246
- await logOperation(database, databaseId, {
247
- operationType: "backup",
248
- collectionId: "",
249
- data: "Backup failed",
250
- progress: 0,
251
- total: 100,
252
- error: String(error),
253
- status: "error",
254
- }, backupOperation.$id);
330
+ progress?.fail(error instanceof Error ? error.message : String(error));
331
+ MessageFormatter.error("Backup failed", error instanceof Error ? error : new Error(String(error)));
332
+ if (backupOperation) {
333
+ await logOperation(database, databaseId, {
334
+ operationType: "backup",
335
+ collectionId: "",
336
+ data: "Backup failed",
337
+ progress: 0,
338
+ total: totalDocuments,
339
+ error: String(error),
340
+ status: "error",
341
+ }, backupOperation.$id, config.useMigrations);
342
+ }
343
+ throw error;
255
344
  }
256
345
  };
@@ -9,31 +9,31 @@ export declare const BackupSchema: z.ZodObject<{
9
9
  collectionId: z.ZodString;
10
10
  data: z.ZodString;
11
11
  }, "strip", z.ZodTypeAny, {
12
- collectionId: string;
13
12
  data: string;
14
- }, {
15
13
  collectionId: string;
14
+ }, {
16
15
  data: string;
16
+ collectionId: string;
17
17
  }>, "many">>;
18
18
  }, "strip", z.ZodTypeAny, {
19
- collections: string[];
20
19
  documents: {
21
- collectionId: string;
22
20
  data: string;
21
+ collectionId: string;
23
22
  }[];
24
23
  $id: string;
25
24
  $createdAt: string;
26
25
  $updatedAt: string;
26
+ collections: string[];
27
27
  database: string;
28
28
  }, {
29
- collections: string[];
30
29
  $id: string;
31
30
  $createdAt: string;
32
31
  $updatedAt: string;
32
+ collections: string[];
33
33
  database: string;
34
34
  documents?: {
35
- collectionId: string;
36
35
  data: string;
36
+ collectionId: string;
37
37
  }[] | undefined;
38
38
  }>;
39
39
  export type Backup = z.infer<typeof BackupSchema>;
@@ -47,25 +47,25 @@ export declare const BackupCreateSchema: z.ZodObject<Omit<{
47
47
  collectionId: z.ZodString;
48
48
  data: z.ZodString;
49
49
  }, "strip", z.ZodTypeAny, {
50
- collectionId: string;
51
50
  data: string;
52
- }, {
53
51
  collectionId: string;
52
+ }, {
54
53
  data: string;
54
+ collectionId: string;
55
55
  }>, "many">>;
56
56
  }, "$id" | "$createdAt" | "$updatedAt">, "strip", z.ZodTypeAny, {
57
- collections: string[];
58
57
  documents: {
59
- collectionId: string;
60
58
  data: string;
59
+ collectionId: string;
61
60
  }[];
61
+ collections: string[];
62
62
  database: string;
63
63
  }, {
64
64
  collections: string[];
65
65
  database: string;
66
66
  documents?: {
67
- collectionId: string;
68
67
  data: string;
68
+ collectionId: string;
69
69
  }[] | undefined;
70
70
  }>;
71
71
  export type BackupCreate = z.infer<typeof BackupCreateSchema>;
@@ -76,16 +76,16 @@ export declare const BatchSchema: z.ZodObject<{
76
76
  data: z.ZodString;
77
77
  processed: z.ZodDefault<z.ZodBoolean>;
78
78
  }, "strip", z.ZodTypeAny, {
79
+ data: string;
79
80
  $id: string;
80
81
  $createdAt: string;
81
82
  $updatedAt: string;
82
- data: string;
83
83
  processed: boolean;
84
84
  }, {
85
+ data: string;
85
86
  $id: string;
86
87
  $createdAt: string;
87
88
  $updatedAt: string;
88
- data: string;
89
89
  processed?: boolean | undefined;
90
90
  }>;
91
91
  export type Batch = z.infer<typeof BatchSchema>;
@@ -116,11 +116,11 @@ export declare const OperationSchema: z.ZodObject<{
116
116
  error: z.ZodString;
117
117
  status: z.ZodDefault<z.ZodEnum<["pending", "ready", "in_progress", "completed", "error", "cancelled"]>>;
118
118
  }, "strip", z.ZodTypeAny, {
119
+ status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
120
+ error: string;
119
121
  $id: string;
120
122
  $createdAt: string;
121
123
  $updatedAt: string;
122
- status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
123
- error: string;
124
124
  collectionId: string;
125
125
  operationType: string;
126
126
  progress: number;
@@ -128,10 +128,10 @@ export declare const OperationSchema: z.ZodObject<{
128
128
  data?: any;
129
129
  batches?: string[] | undefined;
130
130
  }, {
131
+ error: string;
131
132
  $id: string;
132
133
  $createdAt: string;
133
134
  $updatedAt: string;
134
- error: string;
135
135
  collectionId: string;
136
136
  operationType: string;
137
137
  progress: number;
@@ -198,6 +198,16 @@ export declare const getMigrationCollectionSchemas: () => {
198
198
  xdefault?: number | null | undefined;
199
199
  min?: number | undefined;
200
200
  max?: number | undefined;
201
+ } | {
202
+ type: "double";
203
+ key: string;
204
+ description?: string | Record<string, string> | null | undefined;
205
+ required?: boolean | undefined;
206
+ array?: boolean | undefined;
207
+ error?: string | undefined;
208
+ xdefault?: number | null | undefined;
209
+ min?: number | undefined;
210
+ max?: number | undefined;
201
211
  } | {
202
212
  type: "float";
203
213
  key: string;
@@ -351,6 +361,16 @@ export declare const getMigrationCollectionSchemas: () => {
351
361
  xdefault?: number | null | undefined;
352
362
  min?: number | undefined;
353
363
  max?: number | undefined;
364
+ } | {
365
+ type: "double";
366
+ key: string;
367
+ description?: string | Record<string, string> | null | undefined;
368
+ required?: boolean | undefined;
369
+ array?: boolean | undefined;
370
+ error?: string | undefined;
371
+ xdefault?: number | null | undefined;
372
+ min?: number | undefined;
373
+ max?: number | undefined;
354
374
  } | {
355
375
  type: "float";
356
376
  key: string;
@@ -453,6 +473,16 @@ export declare const getMigrationCollectionSchemas: () => {
453
473
  xdefault?: number | null | undefined;
454
474
  min?: number | undefined;
455
475
  max?: number | undefined;
476
+ } | {
477
+ type: "double";
478
+ key: string;
479
+ description?: string | Record<string, string> | null | undefined;
480
+ required?: boolean | undefined;
481
+ array?: boolean | undefined;
482
+ error?: string | undefined;
483
+ xdefault?: number | null | undefined;
484
+ min?: number | undefined;
485
+ max?: number | undefined;
456
486
  } | {
457
487
  type: "float";
458
488
  key: string;
@@ -606,6 +636,16 @@ export declare const getMigrationCollectionSchemas: () => {
606
636
  xdefault?: number | null | undefined;
607
637
  min?: number | undefined;
608
638
  max?: number | undefined;
639
+ } | {
640
+ type: "double";
641
+ key: string;
642
+ description?: string | Record<string, string> | null | undefined;
643
+ required?: boolean | undefined;
644
+ array?: boolean | undefined;
645
+ error?: string | undefined;
646
+ xdefault?: number | null | undefined;
647
+ min?: number | undefined;
648
+ max?: number | undefined;
609
649
  } | {
610
650
  type: "float";
611
651
  key: string;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { ValidationRules } from "./migrations/validationRules.js";
1
+ export type { ValidationRules } from "./utils/validationRules.js";
2
2
  export { type AuthUserCreate, AuthUserCreateSchema, type AuthUser, AuthUserSchema, } from "./schemas/authUser.js";
3
- export { validationRules } from "./migrations/validationRules.js";
3
+ export { validationRules } from "./utils/validationRules.js";
4
4
  export { afterImportActions } from "./migrations/afterImportActions.js";
package/dist/types.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { AuthUserCreateSchema, AuthUserSchema, } from "./schemas/authUser.js";
2
- export { validationRules } from "./migrations/validationRules.js";
2
+ export { validationRules } from "./utils/validationRules.js";
3
3
  export { afterImportActions } from "./migrations/afterImportActions.js";
@@ -0,0 +1,16 @@
1
+ import type { AppwriteConfig } from "appwrite-utils";
2
+ import { Databases, type Models } from "node-appwrite";
3
+ import { type AuthUserCreate } from "../schemas/authUser.js";
4
+ export declare class UsersController {
5
+ private config;
6
+ private users;
7
+ static userFields: string[];
8
+ constructor(config: AppwriteConfig, db: Databases);
9
+ wipeUsers(): Promise<void>;
10
+ getAllUsers(): Promise<Models.User<Models.Preferences>[]>;
11
+ createUsersAndReturn(items: AuthUserCreate[]): Promise<(Models.User<Models.Preferences> | undefined)[]>;
12
+ createUserAndReturn(item: AuthUserCreate): Promise<Models.User<Models.Preferences> | undefined>;
13
+ createAndCheckForUserAndReturn(item: AuthUserCreate): Promise<Models.User<Models.Preferences> | undefined>;
14
+ getUserIdByEmailOrPhone(email?: string, phone?: string): Promise<string | undefined>;
15
+ transferUsersBetweenDbsLocalToRemote: (endpoint: string, projectId: string, apiKey: string) => Promise<void>;
16
+ }