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.
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 +264 -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 +262 -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 +379 -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 +349 -0
  160. package/src/utils/loadConfigs.ts +416 -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
@@ -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
- console.log(`Transferring files from ${fromBucketId} to ${toBucketId}`);
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
- console.error(`Error downloading file ${fileId}: ${error}`);
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
- console.error(`Error downloading file ${file.$id}`);
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
- console.log(`Creating file: ${file.name}`);
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
- console.error(`Error downloading file ${file.$id}`);
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
- console.log(chalk.yellow(`File ${file.$id} already exists, skipping...`));
79
+ MessageFormatter.warning(`File ${file.$id} already exists, skipping...`, { prefix: "Transfer" });
78
80
  continue;
79
81
  }
80
82
  numberOfFiles++;
81
83
  }
82
84
  }
83
- console.log(`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`);
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
- console.log(`Transferring files from current storage ${fromBucketId} to ${endpoint} bucket ${toBucketId}`);
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
- console.log(chalk.yellow(`File ${file.$id} already exists, skipping...`));
117
+ MessageFormatter.warning(`File ${file.$id} already exists, skipping...`, { prefix: "Transfer" });
116
118
  continue;
117
119
  }
118
120
  numberOfFiles++;
119
121
  }
120
- console.log(`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`);
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
+ }