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
@@ -6,10 +6,12 @@ import { createOrUpdateAttribute, createUpdateCollectionAttributes, } from "../c
|
|
6
6
|
import { parseAttribute } from "appwrite-utils";
|
7
7
|
import chalk from "chalk";
|
8
8
|
import { fetchAllCollections } from "../collections/methods.js";
|
9
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
10
|
+
import { ProgressManager } from "../shared/progressManager.js";
|
9
11
|
import { createOrUpdateIndex, createOrUpdateIndexes, } from "../collections/indexes.js";
|
10
12
|
import { getClient } from "../utils/getClientFromConfig.js";
|
11
13
|
export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucketId) => {
|
12
|
-
|
14
|
+
MessageFormatter.info(`Transferring files from ${fromBucketId} to ${toBucketId}`, { prefix: "Transfer" });
|
13
15
|
let lastFileId;
|
14
16
|
let fromFiles = await tryAwaitWithRetry(async () => await storage.listFiles(fromBucketId, [Query.limit(100)]));
|
15
17
|
const allFromFiles = fromFiles.files;
|
@@ -21,7 +23,7 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
|
|
21
23
|
return await storage.getFileDownload(bucketId, fileId);
|
22
24
|
}
|
23
25
|
catch (error) {
|
24
|
-
|
26
|
+
MessageFormatter.error(`Error downloading file ${fileId}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Transfer" });
|
25
27
|
attempts--;
|
26
28
|
if (attempts === 0)
|
27
29
|
throw error;
|
@@ -32,11 +34,11 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
|
|
32
34
|
for (const file of allFromFiles) {
|
33
35
|
const fileData = await tryAwaitWithRetry(async () => await downloadFileWithRetry(file.bucketId, file.$id));
|
34
36
|
if (!fileData) {
|
35
|
-
|
37
|
+
MessageFormatter.error(`Error downloading file ${file.$id}`, undefined, { prefix: "Transfer" });
|
36
38
|
continue;
|
37
39
|
}
|
38
40
|
const fileToCreate = InputFile.fromBuffer(new Uint8Array(fileData), file.name);
|
39
|
-
|
41
|
+
MessageFormatter.progress(`Creating file: ${file.name}`, { prefix: "Transfer" });
|
40
42
|
try {
|
41
43
|
await tryAwaitWithRetry(async () => await storage.createFile(toBucketId, file.$id, fileToCreate, file.$permissions));
|
42
44
|
}
|
@@ -65,7 +67,7 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
|
|
65
67
|
for (const file of allFromFiles) {
|
66
68
|
const fileData = await tryAwaitWithRetry(async () => await downloadFileWithRetry(file.bucketId, file.$id));
|
67
69
|
if (!fileData) {
|
68
|
-
|
70
|
+
MessageFormatter.error(`Error downloading file ${file.$id}`, undefined, { prefix: "Transfer" });
|
69
71
|
continue;
|
70
72
|
}
|
71
73
|
const fileToCreate = InputFile.fromBuffer(new Uint8Array(fileData), file.name);
|
@@ -74,16 +76,16 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
|
|
74
76
|
}
|
75
77
|
catch (error) {
|
76
78
|
// File already exists, so we can skip it
|
77
|
-
|
79
|
+
MessageFormatter.warning(`File ${file.$id} already exists, skipping...`, { prefix: "Transfer" });
|
78
80
|
continue;
|
79
81
|
}
|
80
82
|
numberOfFiles++;
|
81
83
|
}
|
82
84
|
}
|
83
|
-
|
85
|
+
MessageFormatter.success(`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`, { prefix: "Transfer" });
|
84
86
|
};
|
85
87
|
export const transferStorageLocalToRemote = async (localStorage, endpoint, projectId, apiKey, fromBucketId, toBucketId) => {
|
86
|
-
|
88
|
+
MessageFormatter.info(`Transferring files from current storage ${fromBucketId} to ${endpoint} bucket ${toBucketId}`, { prefix: "Transfer" });
|
87
89
|
const client = getAppwriteClient(endpoint, projectId, apiKey);
|
88
90
|
const remoteStorage = new Storage(client);
|
89
91
|
let numberOfFiles = 0;
|
@@ -112,135 +114,15 @@ export const transferStorageLocalToRemote = async (localStorage, endpoint, proje
|
|
112
114
|
}
|
113
115
|
catch (error) {
|
114
116
|
// File already exists, so we can skip it
|
115
|
-
|
117
|
+
MessageFormatter.warning(`File ${file.$id} already exists, skipping...`, { prefix: "Transfer" });
|
116
118
|
continue;
|
117
119
|
}
|
118
120
|
numberOfFiles++;
|
119
121
|
}
|
120
|
-
|
121
|
-
};
|
122
|
-
/**
|
123
|
-
* Transfers all documents from one collection to another in a different database
|
124
|
-
* within the same Appwrite Project
|
125
|
-
*/
|
126
|
-
export const transferDocumentsBetweenDbsLocalToLocal = async (db, fromDbId, toDbId, fromCollId, toCollId) => {
|
127
|
-
let totalDocumentsTransferred = 0;
|
128
|
-
let lastDocumentId;
|
129
|
-
let hasMoreDocuments = true;
|
130
|
-
while (hasMoreDocuments) {
|
131
|
-
const queryParams = [Query.limit(50)];
|
132
|
-
if (lastDocumentId) {
|
133
|
-
queryParams.push(Query.cursorAfter(lastDocumentId));
|
134
|
-
}
|
135
|
-
const fromCollDocs = await tryAwaitWithRetry(async () => db.listDocuments(fromDbId, fromCollId, queryParams));
|
136
|
-
if (fromCollDocs.documents.length === 0) {
|
137
|
-
if (totalDocumentsTransferred === 0) {
|
138
|
-
console.log(`No documents found in collection ${fromCollId}`);
|
139
|
-
}
|
140
|
-
break;
|
141
|
-
}
|
142
|
-
const allDocsToCreateCheck = await tryAwaitWithRetry(async () => await db.listDocuments(toDbId, toCollId, [
|
143
|
-
Query.equal("$id", fromCollDocs.documents.map((doc) => doc.$id)),
|
144
|
-
]));
|
145
|
-
const docsToCreate = fromCollDocs.documents.filter((doc) => !allDocsToCreateCheck.documents.some((d) => d.$id === doc.$id));
|
146
|
-
const batchedPromises = docsToCreate.map((doc) => {
|
147
|
-
const toCreateObject = {
|
148
|
-
...doc,
|
149
|
-
};
|
150
|
-
delete toCreateObject.$databaseId;
|
151
|
-
delete toCreateObject.$collectionId;
|
152
|
-
delete toCreateObject.$createdAt;
|
153
|
-
delete toCreateObject.$updatedAt;
|
154
|
-
delete toCreateObject.$id;
|
155
|
-
delete toCreateObject.$permissions;
|
156
|
-
return tryAwaitWithRetry(async () => await db.createDocument(toDbId, toCollId, doc.$id, toCreateObject, doc.$permissions));
|
157
|
-
});
|
158
|
-
await Promise.all(batchedPromises);
|
159
|
-
totalDocumentsTransferred += docsToCreate.length;
|
160
|
-
if (fromCollDocs.documents.length < 50) {
|
161
|
-
hasMoreDocuments = false;
|
162
|
-
}
|
163
|
-
else {
|
164
|
-
lastDocumentId =
|
165
|
-
fromCollDocs.documents[fromCollDocs.documents.length - 1].$id;
|
166
|
-
}
|
167
|
-
}
|
168
|
-
console.log(`Transferred ${totalDocumentsTransferred} documents from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}`);
|
169
|
-
};
|
170
|
-
export const transferDocumentsBetweenDbsLocalToRemote = async (localDb, endpoint, projectId, apiKey, fromDbId, toDbId, fromCollId, toCollId) => {
|
171
|
-
const client = new Client()
|
172
|
-
.setEndpoint(endpoint)
|
173
|
-
.setProject(projectId)
|
174
|
-
.setKey(apiKey);
|
175
|
-
let totalDocumentsTransferred = 0;
|
176
|
-
const remoteDb = new Databases(client);
|
177
|
-
let fromCollDocs = await tryAwaitWithRetry(async () => localDb.listDocuments(fromDbId, fromCollId, [Query.limit(50)]));
|
178
|
-
if (fromCollDocs.documents.length === 0) {
|
179
|
-
console.log(`No documents found in collection ${fromCollId}`);
|
180
|
-
return;
|
181
|
-
}
|
182
|
-
else if (fromCollDocs.documents.length < 50) {
|
183
|
-
const allDocsToCreateCheck = await tryAwaitWithRetry(async () => await remoteDb.listDocuments(toDbId, toCollId, [
|
184
|
-
Query.equal("$id", fromCollDocs.documents.map((doc) => doc.$id)),
|
185
|
-
]));
|
186
|
-
const docsToCreate = fromCollDocs.documents.filter((doc) => !allDocsToCreateCheck.documents.some((d) => d.$id === doc.$id));
|
187
|
-
const batchedPromises = docsToCreate.map((doc) => {
|
188
|
-
const toCreateObject = {
|
189
|
-
...doc,
|
190
|
-
};
|
191
|
-
delete toCreateObject.$databaseId;
|
192
|
-
delete toCreateObject.$collectionId;
|
193
|
-
delete toCreateObject.$createdAt;
|
194
|
-
delete toCreateObject.$updatedAt;
|
195
|
-
delete toCreateObject.$id;
|
196
|
-
delete toCreateObject.$permissions;
|
197
|
-
return tryAwaitWithRetry(async () => remoteDb.createDocument(toDbId, toCollId, doc.$id, toCreateObject, doc.$permissions));
|
198
|
-
});
|
199
|
-
await Promise.all(batchedPromises);
|
200
|
-
totalDocumentsTransferred += fromCollDocs.documents.length;
|
201
|
-
}
|
202
|
-
else {
|
203
|
-
const allDocsToCreateCheck = await tryAwaitWithRetry(async () => await remoteDb.listDocuments(toDbId, toCollId, [
|
204
|
-
Query.equal("$id", fromCollDocs.documents.map((doc) => doc.$id)),
|
205
|
-
]));
|
206
|
-
const docsToCreate = fromCollDocs.documents.filter((doc) => !allDocsToCreateCheck.documents.some((d) => d.$id === doc.$id));
|
207
|
-
const batchedPromises = docsToCreate.map((doc) => {
|
208
|
-
const toCreateObject = {
|
209
|
-
...doc,
|
210
|
-
};
|
211
|
-
delete toCreateObject.$databaseId;
|
212
|
-
delete toCreateObject.$collectionId;
|
213
|
-
delete toCreateObject.$createdAt;
|
214
|
-
delete toCreateObject.$updatedAt;
|
215
|
-
delete toCreateObject.$id;
|
216
|
-
delete toCreateObject.$permissions;
|
217
|
-
return tryAwaitWithRetry(async () => remoteDb.createDocument(toDbId, toCollId, doc.$id, toCreateObject, doc.$permissions));
|
218
|
-
});
|
219
|
-
await Promise.all(batchedPromises);
|
220
|
-
totalDocumentsTransferred += fromCollDocs.documents.length;
|
221
|
-
while (fromCollDocs.documents.length === 50) {
|
222
|
-
fromCollDocs = await tryAwaitWithRetry(async () => localDb.listDocuments(fromDbId, fromCollId, [
|
223
|
-
Query.limit(50),
|
224
|
-
Query.cursorAfter(fromCollDocs.documents[fromCollDocs.documents.length - 1].$id),
|
225
|
-
]));
|
226
|
-
const batchedPromises = fromCollDocs.documents.map((doc) => {
|
227
|
-
const toCreateObject = {
|
228
|
-
...doc,
|
229
|
-
};
|
230
|
-
delete toCreateObject.$databaseId;
|
231
|
-
delete toCreateObject.$collectionId;
|
232
|
-
delete toCreateObject.$createdAt;
|
233
|
-
delete toCreateObject.$updatedAt;
|
234
|
-
delete toCreateObject.$id;
|
235
|
-
delete toCreateObject.$permissions;
|
236
|
-
return tryAwaitWithRetry(async () => remoteDb.createDocument(toDbId, toCollId, doc.$id, toCreateObject, doc.$permissions));
|
237
|
-
});
|
238
|
-
await Promise.all(batchedPromises);
|
239
|
-
totalDocumentsTransferred += fromCollDocs.documents.length;
|
240
|
-
}
|
241
|
-
}
|
242
|
-
console.log(`Total documents transferred from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}: ${totalDocumentsTransferred}`);
|
122
|
+
MessageFormatter.success(`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`, { prefix: "Transfer" });
|
243
123
|
};
|
124
|
+
// Document transfer functions moved to collections/methods.ts with enhanced UX
|
125
|
+
// Remote document transfer functions moved to collections/methods.ts with enhanced UX
|
244
126
|
/**
|
245
127
|
* Transfers all collections and documents from one local database to another local database.
|
246
128
|
*
|
@@ -307,6 +189,7 @@ export const transferDatabaseLocalToLocal = async (localDb, fromDbId, targetDbId
|
|
307
189
|
}
|
308
190
|
}
|
309
191
|
// Transfer documents
|
192
|
+
const { transferDocumentsBetweenDbsLocalToLocal } = await import("../collections/methods.js");
|
310
193
|
await transferDocumentsBetweenDbsLocalToLocal(localDb, fromDbId, targetDbId, collection.$id, targetCollection.$id);
|
311
194
|
}
|
312
195
|
catch (error) {
|
@@ -371,6 +254,7 @@ export const transferDatabaseLocalToRemote = async (localDb, endpoint, projectId
|
|
371
254
|
}
|
372
255
|
}
|
373
256
|
// Transfer documents
|
257
|
+
const { transferDocumentsBetweenDbsLocalToRemote } = await import("../collections/methods.js");
|
374
258
|
await transferDocumentsBetweenDbsLocalToRemote(localDb, endpoint, projectId, apiKey, fromDbId, toDbId, collection.$id, targetCollection.$id);
|
375
259
|
}
|
376
260
|
catch (error) {
|
@@ -0,0 +1,384 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
import type { ImportDef } from "appwrite-utils";
|
3
|
+
export declare const YamlImportConfigSchema: z.ZodObject<{
|
4
|
+
source: z.ZodObject<{
|
5
|
+
file: z.ZodString;
|
6
|
+
basePath: z.ZodOptional<z.ZodString>;
|
7
|
+
type: z.ZodDefault<z.ZodEnum<["json", "csv", "yaml"]>>;
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
9
|
+
type: "json" | "csv" | "yaml";
|
10
|
+
file: string;
|
11
|
+
basePath?: string | undefined;
|
12
|
+
}, {
|
13
|
+
file: string;
|
14
|
+
type?: "json" | "csv" | "yaml" | undefined;
|
15
|
+
basePath?: string | undefined;
|
16
|
+
}>;
|
17
|
+
target: z.ZodObject<{
|
18
|
+
collection: z.ZodString;
|
19
|
+
type: z.ZodDefault<z.ZodEnum<["create", "update"]>>;
|
20
|
+
primaryKey: z.ZodDefault<z.ZodString>;
|
21
|
+
createUsers: z.ZodDefault<z.ZodBoolean>;
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
23
|
+
type: "create" | "update";
|
24
|
+
collection: string;
|
25
|
+
primaryKey: string;
|
26
|
+
createUsers: boolean;
|
27
|
+
}, {
|
28
|
+
collection: string;
|
29
|
+
type?: "create" | "update" | undefined;
|
30
|
+
primaryKey?: string | undefined;
|
31
|
+
createUsers?: boolean | undefined;
|
32
|
+
}>;
|
33
|
+
mapping: z.ZodObject<{
|
34
|
+
attributes: z.ZodArray<z.ZodObject<{
|
35
|
+
oldKey: z.ZodOptional<z.ZodString>;
|
36
|
+
oldKeys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
37
|
+
targetKey: z.ZodString;
|
38
|
+
valueToSet: z.ZodOptional<z.ZodAny>;
|
39
|
+
fileData: z.ZodOptional<z.ZodObject<{
|
40
|
+
path: z.ZodString;
|
41
|
+
name: z.ZodString;
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
43
|
+
path: string;
|
44
|
+
name: string;
|
45
|
+
}, {
|
46
|
+
path: string;
|
47
|
+
name: string;
|
48
|
+
}>>;
|
49
|
+
converters: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
50
|
+
validation: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
51
|
+
rule: z.ZodString;
|
52
|
+
params: z.ZodArray<z.ZodString, "many">;
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
54
|
+
params: string[];
|
55
|
+
rule: string;
|
56
|
+
}, {
|
57
|
+
params: string[];
|
58
|
+
rule: string;
|
59
|
+
}>, "many">>;
|
60
|
+
afterImport: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
61
|
+
action: z.ZodString;
|
62
|
+
params: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>, "many">;
|
63
|
+
}, "strip", z.ZodTypeAny, {
|
64
|
+
params: (string | Record<string, any>)[];
|
65
|
+
action: string;
|
66
|
+
}, {
|
67
|
+
params: (string | Record<string, any>)[];
|
68
|
+
action: string;
|
69
|
+
}>, "many">>;
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
71
|
+
validation: {
|
72
|
+
params: string[];
|
73
|
+
rule: string;
|
74
|
+
}[];
|
75
|
+
targetKey: string;
|
76
|
+
converters: string[];
|
77
|
+
afterImport: {
|
78
|
+
params: (string | Record<string, any>)[];
|
79
|
+
action: string;
|
80
|
+
}[];
|
81
|
+
oldKey?: string | undefined;
|
82
|
+
oldKeys?: string[] | undefined;
|
83
|
+
valueToSet?: any;
|
84
|
+
fileData?: {
|
85
|
+
path: string;
|
86
|
+
name: string;
|
87
|
+
} | undefined;
|
88
|
+
}, {
|
89
|
+
targetKey: string;
|
90
|
+
validation?: {
|
91
|
+
params: string[];
|
92
|
+
rule: string;
|
93
|
+
}[] | undefined;
|
94
|
+
oldKey?: string | undefined;
|
95
|
+
oldKeys?: string[] | undefined;
|
96
|
+
valueToSet?: any;
|
97
|
+
fileData?: {
|
98
|
+
path: string;
|
99
|
+
name: string;
|
100
|
+
} | undefined;
|
101
|
+
converters?: string[] | undefined;
|
102
|
+
afterImport?: {
|
103
|
+
params: (string | Record<string, any>)[];
|
104
|
+
action: string;
|
105
|
+
}[] | undefined;
|
106
|
+
}>, "many">;
|
107
|
+
relationships: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
108
|
+
sourceField: z.ZodString;
|
109
|
+
targetField: z.ZodString;
|
110
|
+
targetCollection: z.ZodString;
|
111
|
+
fieldToSet: z.ZodOptional<z.ZodString>;
|
112
|
+
targetFieldToMatch: z.ZodOptional<z.ZodString>;
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
114
|
+
targetField: string;
|
115
|
+
sourceField: string;
|
116
|
+
targetCollection: string;
|
117
|
+
fieldToSet?: string | undefined;
|
118
|
+
targetFieldToMatch?: string | undefined;
|
119
|
+
}, {
|
120
|
+
targetField: string;
|
121
|
+
sourceField: string;
|
122
|
+
targetCollection: string;
|
123
|
+
fieldToSet?: string | undefined;
|
124
|
+
targetFieldToMatch?: string | undefined;
|
125
|
+
}>, "many">>;
|
126
|
+
}, "strip", z.ZodTypeAny, {
|
127
|
+
attributes: {
|
128
|
+
validation: {
|
129
|
+
params: string[];
|
130
|
+
rule: string;
|
131
|
+
}[];
|
132
|
+
targetKey: string;
|
133
|
+
converters: string[];
|
134
|
+
afterImport: {
|
135
|
+
params: (string | Record<string, any>)[];
|
136
|
+
action: string;
|
137
|
+
}[];
|
138
|
+
oldKey?: string | undefined;
|
139
|
+
oldKeys?: string[] | undefined;
|
140
|
+
valueToSet?: any;
|
141
|
+
fileData?: {
|
142
|
+
path: string;
|
143
|
+
name: string;
|
144
|
+
} | undefined;
|
145
|
+
}[];
|
146
|
+
relationships: {
|
147
|
+
targetField: string;
|
148
|
+
sourceField: string;
|
149
|
+
targetCollection: string;
|
150
|
+
fieldToSet?: string | undefined;
|
151
|
+
targetFieldToMatch?: string | undefined;
|
152
|
+
}[];
|
153
|
+
}, {
|
154
|
+
attributes: {
|
155
|
+
targetKey: string;
|
156
|
+
validation?: {
|
157
|
+
params: string[];
|
158
|
+
rule: string;
|
159
|
+
}[] | undefined;
|
160
|
+
oldKey?: string | undefined;
|
161
|
+
oldKeys?: string[] | undefined;
|
162
|
+
valueToSet?: any;
|
163
|
+
fileData?: {
|
164
|
+
path: string;
|
165
|
+
name: string;
|
166
|
+
} | undefined;
|
167
|
+
converters?: string[] | undefined;
|
168
|
+
afterImport?: {
|
169
|
+
params: (string | Record<string, any>)[];
|
170
|
+
action: string;
|
171
|
+
}[] | undefined;
|
172
|
+
}[];
|
173
|
+
relationships?: {
|
174
|
+
targetField: string;
|
175
|
+
sourceField: string;
|
176
|
+
targetCollection: string;
|
177
|
+
fieldToSet?: string | undefined;
|
178
|
+
targetFieldToMatch?: string | undefined;
|
179
|
+
}[] | undefined;
|
180
|
+
}>;
|
181
|
+
options: z.ZodDefault<z.ZodObject<{
|
182
|
+
batchSize: z.ZodDefault<z.ZodNumber>;
|
183
|
+
skipValidation: z.ZodDefault<z.ZodBoolean>;
|
184
|
+
dryRun: z.ZodDefault<z.ZodBoolean>;
|
185
|
+
continueOnError: z.ZodDefault<z.ZodBoolean>;
|
186
|
+
updateMapping: z.ZodOptional<z.ZodObject<{
|
187
|
+
originalIdField: z.ZodString;
|
188
|
+
targetField: z.ZodString;
|
189
|
+
}, "strip", z.ZodTypeAny, {
|
190
|
+
targetField: string;
|
191
|
+
originalIdField: string;
|
192
|
+
}, {
|
193
|
+
targetField: string;
|
194
|
+
originalIdField: string;
|
195
|
+
}>>;
|
196
|
+
}, "strip", z.ZodTypeAny, {
|
197
|
+
batchSize: number;
|
198
|
+
skipValidation: boolean;
|
199
|
+
dryRun: boolean;
|
200
|
+
continueOnError: boolean;
|
201
|
+
updateMapping?: {
|
202
|
+
targetField: string;
|
203
|
+
originalIdField: string;
|
204
|
+
} | undefined;
|
205
|
+
}, {
|
206
|
+
batchSize?: number | undefined;
|
207
|
+
skipValidation?: boolean | undefined;
|
208
|
+
dryRun?: boolean | undefined;
|
209
|
+
continueOnError?: boolean | undefined;
|
210
|
+
updateMapping?: {
|
211
|
+
targetField: string;
|
212
|
+
originalIdField: string;
|
213
|
+
} | undefined;
|
214
|
+
}>>;
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
216
|
+
options: {
|
217
|
+
batchSize: number;
|
218
|
+
skipValidation: boolean;
|
219
|
+
dryRun: boolean;
|
220
|
+
continueOnError: boolean;
|
221
|
+
updateMapping?: {
|
222
|
+
targetField: string;
|
223
|
+
originalIdField: string;
|
224
|
+
} | undefined;
|
225
|
+
};
|
226
|
+
target: {
|
227
|
+
type: "create" | "update";
|
228
|
+
collection: string;
|
229
|
+
primaryKey: string;
|
230
|
+
createUsers: boolean;
|
231
|
+
};
|
232
|
+
source: {
|
233
|
+
type: "json" | "csv" | "yaml";
|
234
|
+
file: string;
|
235
|
+
basePath?: string | undefined;
|
236
|
+
};
|
237
|
+
mapping: {
|
238
|
+
attributes: {
|
239
|
+
validation: {
|
240
|
+
params: string[];
|
241
|
+
rule: string;
|
242
|
+
}[];
|
243
|
+
targetKey: string;
|
244
|
+
converters: string[];
|
245
|
+
afterImport: {
|
246
|
+
params: (string | Record<string, any>)[];
|
247
|
+
action: string;
|
248
|
+
}[];
|
249
|
+
oldKey?: string | undefined;
|
250
|
+
oldKeys?: string[] | undefined;
|
251
|
+
valueToSet?: any;
|
252
|
+
fileData?: {
|
253
|
+
path: string;
|
254
|
+
name: string;
|
255
|
+
} | undefined;
|
256
|
+
}[];
|
257
|
+
relationships: {
|
258
|
+
targetField: string;
|
259
|
+
sourceField: string;
|
260
|
+
targetCollection: string;
|
261
|
+
fieldToSet?: string | undefined;
|
262
|
+
targetFieldToMatch?: string | undefined;
|
263
|
+
}[];
|
264
|
+
};
|
265
|
+
}, {
|
266
|
+
target: {
|
267
|
+
collection: string;
|
268
|
+
type?: "create" | "update" | undefined;
|
269
|
+
primaryKey?: string | undefined;
|
270
|
+
createUsers?: boolean | undefined;
|
271
|
+
};
|
272
|
+
source: {
|
273
|
+
file: string;
|
274
|
+
type?: "json" | "csv" | "yaml" | undefined;
|
275
|
+
basePath?: string | undefined;
|
276
|
+
};
|
277
|
+
mapping: {
|
278
|
+
attributes: {
|
279
|
+
targetKey: string;
|
280
|
+
validation?: {
|
281
|
+
params: string[];
|
282
|
+
rule: string;
|
283
|
+
}[] | undefined;
|
284
|
+
oldKey?: string | undefined;
|
285
|
+
oldKeys?: string[] | undefined;
|
286
|
+
valueToSet?: any;
|
287
|
+
fileData?: {
|
288
|
+
path: string;
|
289
|
+
name: string;
|
290
|
+
} | undefined;
|
291
|
+
converters?: string[] | undefined;
|
292
|
+
afterImport?: {
|
293
|
+
params: (string | Record<string, any>)[];
|
294
|
+
action: string;
|
295
|
+
}[] | undefined;
|
296
|
+
}[];
|
297
|
+
relationships?: {
|
298
|
+
targetField: string;
|
299
|
+
sourceField: string;
|
300
|
+
targetCollection: string;
|
301
|
+
fieldToSet?: string | undefined;
|
302
|
+
targetFieldToMatch?: string | undefined;
|
303
|
+
}[] | undefined;
|
304
|
+
};
|
305
|
+
options?: {
|
306
|
+
batchSize?: number | undefined;
|
307
|
+
skipValidation?: boolean | undefined;
|
308
|
+
dryRun?: boolean | undefined;
|
309
|
+
continueOnError?: boolean | undefined;
|
310
|
+
updateMapping?: {
|
311
|
+
targetField: string;
|
312
|
+
originalIdField: string;
|
313
|
+
} | undefined;
|
314
|
+
} | undefined;
|
315
|
+
}>;
|
316
|
+
export type YamlImportConfig = z.infer<typeof YamlImportConfigSchema>;
|
317
|
+
/**
|
318
|
+
* Service for loading and converting YAML import configurations.
|
319
|
+
* Integrates with existing .appwrite YAML structure while providing
|
320
|
+
* enhanced import configuration capabilities.
|
321
|
+
*/
|
322
|
+
export declare class YamlImportConfigLoader {
|
323
|
+
private appwriteFolderPath;
|
324
|
+
constructor(appwriteFolderPath: string);
|
325
|
+
/**
|
326
|
+
* Loads a YAML import configuration file.
|
327
|
+
*
|
328
|
+
* @param configPath - Path to the YAML config file relative to .appwrite/import/
|
329
|
+
* @returns Parsed and validated YAML import configuration
|
330
|
+
*/
|
331
|
+
loadImportConfig(configPath: string): Promise<YamlImportConfig>;
|
332
|
+
/**
|
333
|
+
* Loads all import configurations from the .appwrite/import directory.
|
334
|
+
*
|
335
|
+
* @returns Map of collection names to their import configurations
|
336
|
+
*/
|
337
|
+
loadAllImportConfigs(): Promise<Map<string, YamlImportConfig[]>>;
|
338
|
+
/**
|
339
|
+
* Converts YAML import configuration to legacy ImportDef format.
|
340
|
+
* Maintains compatibility with existing import system.
|
341
|
+
*
|
342
|
+
* @param yamlConfig - YAML import configuration
|
343
|
+
* @returns Legacy ImportDef object
|
344
|
+
*/
|
345
|
+
convertToImportDef(yamlConfig: YamlImportConfig): ImportDef;
|
346
|
+
/**
|
347
|
+
* Generates a template YAML import configuration.
|
348
|
+
* Useful for getting started with YAML-based imports.
|
349
|
+
*
|
350
|
+
* @param collectionName - Name of the collection
|
351
|
+
* @param sourceFile - Source data file name
|
352
|
+
* @returns YAML configuration template
|
353
|
+
*/
|
354
|
+
generateTemplate(collectionName: string, sourceFile: string): string;
|
355
|
+
/**
|
356
|
+
* Creates the import directory structure if it doesn't exist.
|
357
|
+
* Sets up the recommended directory layout for YAML import configurations.
|
358
|
+
*/
|
359
|
+
createImportStructure(): Promise<void>;
|
360
|
+
/**
|
361
|
+
* Validates import configuration against collection schema.
|
362
|
+
* Ensures that all target keys exist as attributes in the collection.
|
363
|
+
*
|
364
|
+
* @param yamlConfig - YAML import configuration
|
365
|
+
* @param collectionAttributes - Collection attribute definitions
|
366
|
+
* @returns Validation errors (empty if valid)
|
367
|
+
*/
|
368
|
+
validateAgainstCollection(yamlConfig: YamlImportConfig, collectionAttributes: any[]): string[];
|
369
|
+
/**
|
370
|
+
* Gets statistics about import configurations.
|
371
|
+
*
|
372
|
+
* @param configs - Map of collection configurations
|
373
|
+
* @returns Statistics object
|
374
|
+
*/
|
375
|
+
getStatistics(configs: Map<string, YamlImportConfig[]>): {
|
376
|
+
totalConfigurations: number;
|
377
|
+
collectionsWithConfigs: number;
|
378
|
+
totalAttributeMappings: number;
|
379
|
+
totalRelationshipMappings: number;
|
380
|
+
configsByType: {
|
381
|
+
[type: string]: number;
|
382
|
+
};
|
383
|
+
};
|
384
|
+
}
|