appwrite-utils-cli 0.10.86 → 1.0.2
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/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
- package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
- package/.appwrite/collections/Categories.yaml +182 -0
- package/.appwrite/collections/ExampleCollection.yaml +36 -0
- package/.appwrite/collections/Posts.yaml +227 -0
- package/.appwrite/collections/Users.yaml +149 -0
- package/.appwrite/config.yaml +109 -0
- package/.appwrite/import/README.md +148 -0
- package/.appwrite/import/categories-import.yaml +129 -0
- package/.appwrite/import/posts-import.yaml +208 -0
- package/.appwrite/import/users-import.yaml +130 -0
- package/.appwrite/importData/categories.json +194 -0
- package/.appwrite/importData/posts.json +270 -0
- package/.appwrite/importData/users.json +220 -0
- package/.appwrite/schemas/categories.json +128 -0
- package/.appwrite/schemas/exampleCollection.json +52 -0
- package/.appwrite/schemas/posts.json +173 -0
- package/.appwrite/schemas/users.json +125 -0
- package/README.md +264 -33
- package/dist/collections/attributes.js +3 -2
- package/dist/collections/methods.js +56 -38
- package/dist/config/yamlConfig.d.ts +501 -0
- package/dist/config/yamlConfig.js +452 -0
- package/dist/databases/setup.d.ts +6 -0
- package/dist/databases/setup.js +119 -0
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -2
- package/dist/functions/openapi.d.ts +4 -0
- package/dist/functions/openapi.js +60 -0
- package/dist/interactiveCLI.d.ts +5 -0
- package/dist/interactiveCLI.js +194 -49
- package/dist/main.js +91 -30
- package/dist/migrations/afterImportActions.js +2 -2
- package/dist/migrations/appwriteToX.d.ts +10 -0
- package/dist/migrations/appwriteToX.js +15 -4
- package/dist/migrations/backup.d.ts +16 -16
- package/dist/migrations/dataLoader.d.ts +83 -1
- package/dist/migrations/dataLoader.js +4 -4
- package/dist/migrations/importController.js +25 -18
- package/dist/migrations/importDataActions.js +2 -2
- package/dist/migrations/logging.d.ts +9 -1
- package/dist/migrations/logging.js +41 -22
- package/dist/migrations/migrationHelper.d.ts +4 -4
- package/dist/migrations/relationships.js +1 -1
- package/dist/migrations/services/DataTransformationService.d.ts +55 -0
- package/dist/migrations/services/DataTransformationService.js +158 -0
- package/dist/migrations/services/FileHandlerService.d.ts +75 -0
- package/dist/migrations/services/FileHandlerService.js +236 -0
- package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
- package/dist/migrations/services/ImportOrchestrator.js +488 -0
- package/dist/migrations/services/RateLimitManager.d.ts +138 -0
- package/dist/migrations/services/RateLimitManager.js +279 -0
- package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
- package/dist/migrations/services/RelationshipResolver.js +332 -0
- package/dist/migrations/services/UserMappingService.d.ts +109 -0
- package/dist/migrations/services/UserMappingService.js +277 -0
- package/dist/migrations/services/ValidationService.d.ts +74 -0
- package/dist/migrations/services/ValidationService.js +260 -0
- package/dist/migrations/transfer.d.ts +0 -6
- package/dist/migrations/transfer.js +16 -132
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
- package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
- package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
- package/dist/migrations/yaml/generateImportSchemas.js +575 -0
- package/dist/schemas/authUser.d.ts +9 -9
- package/dist/shared/attributeManager.d.ts +17 -0
- package/dist/shared/attributeManager.js +273 -0
- package/dist/shared/confirmationDialogs.d.ts +75 -0
- package/dist/shared/confirmationDialogs.js +236 -0
- package/dist/shared/functionManager.d.ts +48 -0
- package/dist/shared/functionManager.js +322 -0
- package/dist/shared/indexManager.d.ts +24 -0
- package/dist/shared/indexManager.js +150 -0
- package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
- package/dist/shared/jsonSchemaGenerator.js +313 -0
- package/dist/shared/logging.d.ts +10 -0
- package/dist/shared/logging.js +46 -0
- package/dist/shared/messageFormatter.d.ts +37 -0
- package/dist/shared/messageFormatter.js +152 -0
- package/dist/shared/migrationHelpers.d.ts +173 -0
- package/dist/shared/migrationHelpers.js +142 -0
- package/dist/shared/operationLogger.d.ts +3 -0
- package/dist/shared/operationLogger.js +25 -0
- package/dist/shared/operationQueue.d.ts +13 -0
- package/dist/shared/operationQueue.js +79 -0
- package/dist/shared/progressManager.d.ts +62 -0
- package/dist/shared/progressManager.js +215 -0
- package/dist/shared/schemaGenerator.d.ts +18 -0
- package/dist/shared/schemaGenerator.js +523 -0
- package/dist/storage/methods.d.ts +3 -1
- package/dist/storage/methods.js +144 -55
- package/dist/storage/schemas.d.ts +56 -16
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -1
- package/dist/users/methods.d.ts +16 -0
- package/dist/users/methods.js +276 -0
- package/dist/utils/configMigration.d.ts +1 -0
- package/dist/utils/configMigration.js +262 -0
- package/dist/utils/dataConverters.d.ts +46 -0
- package/dist/utils/dataConverters.js +139 -0
- package/dist/utils/loadConfigs.d.ts +15 -4
- package/dist/utils/loadConfigs.js +379 -51
- package/dist/utils/schemaStrings.js +2 -1
- package/dist/utils/setupFiles.d.ts +2 -1
- package/dist/utils/setupFiles.js +723 -28
- package/dist/utils/validationRules.d.ts +43 -0
- package/dist/utils/validationRules.js +42 -0
- package/dist/utils/yamlConverter.d.ts +48 -0
- package/dist/utils/yamlConverter.js +98 -0
- package/dist/utilsController.js +65 -43
- package/package.json +19 -15
- package/src/collections/attributes.ts +3 -2
- package/src/collections/methods.ts +85 -51
- package/src/config/yamlConfig.ts +488 -0
- package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
- package/src/functions/methods.ts +8 -4
- package/src/functions/templates/count-docs-in-collection/package.json +25 -0
- package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
- package/src/functions/templates/typescript-node/package.json +24 -0
- package/src/functions/templates/typescript-node/tsconfig.json +28 -0
- package/src/functions/templates/uv/README.md +31 -0
- package/src/functions/templates/uv/pyproject.toml +29 -0
- package/src/interactiveCLI.ts +226 -61
- package/src/main.ts +111 -37
- package/src/migrations/afterImportActions.ts +2 -2
- package/src/migrations/appwriteToX.ts +17 -4
- package/src/migrations/dataLoader.ts +4 -4
- package/src/migrations/importController.ts +30 -22
- package/src/migrations/importDataActions.ts +2 -2
- package/src/migrations/relationships.ts +1 -1
- package/src/migrations/services/DataTransformationService.ts +196 -0
- package/src/migrations/services/FileHandlerService.ts +311 -0
- package/src/migrations/services/ImportOrchestrator.ts +669 -0
- package/src/migrations/services/RateLimitManager.ts +363 -0
- package/src/migrations/services/RelationshipResolver.ts +461 -0
- package/src/migrations/services/UserMappingService.ts +345 -0
- package/src/migrations/services/ValidationService.ts +349 -0
- package/src/migrations/transfer.ts +22 -228
- package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
- package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
- package/src/migrations/yaml/generateImportSchemas.ts +589 -0
- package/src/shared/attributeManager.ts +429 -0
- package/src/shared/confirmationDialogs.ts +327 -0
- package/src/shared/functionManager.ts +515 -0
- package/src/shared/indexManager.ts +253 -0
- package/src/shared/jsonSchemaGenerator.ts +403 -0
- package/src/shared/logging.ts +74 -0
- package/src/shared/messageFormatter.ts +195 -0
- package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
- package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
- package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
- package/src/shared/progressManager.ts +278 -0
- package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
- package/src/storage/methods.ts +199 -78
- package/src/types.ts +2 -2
- package/src/{migrations/users.ts → users/methods.ts} +2 -2
- package/src/utils/configMigration.ts +349 -0
- package/src/utils/loadConfigs.ts +416 -52
- package/src/utils/schemaStrings.ts +2 -1
- package/src/utils/setupFiles.ts +742 -40
- package/src/{migrations → utils}/validationRules.ts +1 -1
- package/src/utils/yamlConverter.ts +131 -0
- package/src/utilsController.ts +75 -54
- package/src/functions/templates/poetry/README.md +0 -30
- package/src/functions/templates/poetry/pyproject.toml +0 -16
- package/src/migrations/attributes.ts +0 -561
- package/src/migrations/backup.ts +0 -205
- package/src/migrations/databases.ts +0 -39
- package/src/migrations/dbHelpers.ts +0 -92
- package/src/migrations/indexes.ts +0 -40
- package/src/migrations/logging.ts +0 -29
- package/src/migrations/storage.ts +0 -538
- /package/src/{migrations → functions}/openapi.ts +0 -0
- /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
- /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
- /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
package/dist/storage/methods.js
CHANGED
@@ -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 "../
|
6
|
-
import { splitIntoBatches } from "../
|
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
|
-
|
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)];
|
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;
|
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
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
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
|
164
|
-
|
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
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
286
|
+
MessageFormatter.success(`Collection ${collectionName} backed up with ${MessageFormatter.formatNumber(collectionDocumentCount)} documents`);
|
216
287
|
}
|
217
288
|
catch (error) {
|
218
|
-
|
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
|
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
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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 "./
|
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 "./
|
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 "./
|
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
|
+
}
|