appwrite-utils-cli 0.10.85 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
  2. package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
  3. package/.appwrite/collections/Categories.yaml +182 -0
  4. package/.appwrite/collections/ExampleCollection.yaml +36 -0
  5. package/.appwrite/collections/Posts.yaml +227 -0
  6. package/.appwrite/collections/Users.yaml +149 -0
  7. package/.appwrite/config.yaml +109 -0
  8. package/.appwrite/import/README.md +148 -0
  9. package/.appwrite/import/categories-import.yaml +129 -0
  10. package/.appwrite/import/posts-import.yaml +208 -0
  11. package/.appwrite/import/users-import.yaml +130 -0
  12. package/.appwrite/importData/categories.json +194 -0
  13. package/.appwrite/importData/posts.json +270 -0
  14. package/.appwrite/importData/users.json +220 -0
  15. package/.appwrite/schemas/categories.json +128 -0
  16. package/.appwrite/schemas/exampleCollection.json +52 -0
  17. package/.appwrite/schemas/posts.json +173 -0
  18. package/.appwrite/schemas/users.json +125 -0
  19. package/README.md +261 -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 +196 -52
  32. package/dist/main.js +91 -30
  33. package/dist/migrations/afterImportActions.js +2 -2
  34. package/dist/migrations/appwriteToX.d.ts +10 -0
  35. package/dist/migrations/appwriteToX.js +15 -4
  36. package/dist/migrations/backup.d.ts +16 -16
  37. package/dist/migrations/dataLoader.d.ts +83 -1
  38. package/dist/migrations/dataLoader.js +4 -4
  39. package/dist/migrations/importController.js +25 -18
  40. package/dist/migrations/importDataActions.js +2 -2
  41. package/dist/migrations/logging.d.ts +9 -1
  42. package/dist/migrations/logging.js +41 -22
  43. package/dist/migrations/migrationHelper.d.ts +4 -4
  44. package/dist/migrations/relationships.js +1 -1
  45. package/dist/migrations/services/DataTransformationService.d.ts +55 -0
  46. package/dist/migrations/services/DataTransformationService.js +158 -0
  47. package/dist/migrations/services/FileHandlerService.d.ts +75 -0
  48. package/dist/migrations/services/FileHandlerService.js +236 -0
  49. package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
  50. package/dist/migrations/services/ImportOrchestrator.js +488 -0
  51. package/dist/migrations/services/RateLimitManager.d.ts +138 -0
  52. package/dist/migrations/services/RateLimitManager.js +279 -0
  53. package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
  54. package/dist/migrations/services/RelationshipResolver.js +332 -0
  55. package/dist/migrations/services/UserMappingService.d.ts +109 -0
  56. package/dist/migrations/services/UserMappingService.js +277 -0
  57. package/dist/migrations/services/ValidationService.d.ts +74 -0
  58. package/dist/migrations/services/ValidationService.js +260 -0
  59. package/dist/migrations/transfer.d.ts +0 -6
  60. package/dist/migrations/transfer.js +16 -132
  61. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
  62. package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
  63. package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
  64. package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
  65. package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
  66. package/dist/migrations/yaml/generateImportSchemas.js +575 -0
  67. package/dist/schemas/authUser.d.ts +9 -9
  68. package/dist/shared/attributeManager.d.ts +17 -0
  69. package/dist/shared/attributeManager.js +273 -0
  70. package/dist/shared/confirmationDialogs.d.ts +75 -0
  71. package/dist/shared/confirmationDialogs.js +236 -0
  72. package/dist/shared/functionManager.d.ts +48 -0
  73. package/dist/shared/functionManager.js +322 -0
  74. package/dist/shared/indexManager.d.ts +24 -0
  75. package/dist/shared/indexManager.js +150 -0
  76. package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
  77. package/dist/shared/jsonSchemaGenerator.js +313 -0
  78. package/dist/shared/logging.d.ts +10 -0
  79. package/dist/shared/logging.js +46 -0
  80. package/dist/shared/messageFormatter.d.ts +37 -0
  81. package/dist/shared/messageFormatter.js +152 -0
  82. package/dist/shared/migrationHelpers.d.ts +173 -0
  83. package/dist/shared/migrationHelpers.js +142 -0
  84. package/dist/shared/operationLogger.d.ts +3 -0
  85. package/dist/shared/operationLogger.js +25 -0
  86. package/dist/shared/operationQueue.d.ts +13 -0
  87. package/dist/shared/operationQueue.js +79 -0
  88. package/dist/shared/progressManager.d.ts +62 -0
  89. package/dist/shared/progressManager.js +215 -0
  90. package/dist/shared/schemaGenerator.d.ts +18 -0
  91. package/dist/shared/schemaGenerator.js +523 -0
  92. package/dist/storage/methods.d.ts +3 -1
  93. package/dist/storage/methods.js +144 -55
  94. package/dist/storage/schemas.d.ts +56 -16
  95. package/dist/types.d.ts +2 -2
  96. package/dist/types.js +1 -1
  97. package/dist/users/methods.d.ts +16 -0
  98. package/dist/users/methods.js +276 -0
  99. package/dist/utils/configMigration.d.ts +1 -0
  100. package/dist/utils/configMigration.js +156 -0
  101. package/dist/utils/dataConverters.d.ts +46 -0
  102. package/dist/utils/dataConverters.js +139 -0
  103. package/dist/utils/loadConfigs.d.ts +15 -4
  104. package/dist/utils/loadConfigs.js +377 -51
  105. package/dist/utils/schemaStrings.js +2 -1
  106. package/dist/utils/setupFiles.d.ts +2 -1
  107. package/dist/utils/setupFiles.js +723 -28
  108. package/dist/utils/validationRules.d.ts +43 -0
  109. package/dist/utils/validationRules.js +42 -0
  110. package/dist/utils/yamlConverter.d.ts +48 -0
  111. package/dist/utils/yamlConverter.js +98 -0
  112. package/dist/utilsController.js +65 -43
  113. package/package.json +19 -15
  114. package/src/collections/attributes.ts +3 -2
  115. package/src/collections/methods.ts +85 -51
  116. package/src/config/yamlConfig.ts +488 -0
  117. package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
  118. package/src/functions/methods.ts +8 -4
  119. package/src/functions/templates/count-docs-in-collection/package.json +25 -0
  120. package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
  121. package/src/functions/templates/typescript-node/package.json +24 -0
  122. package/src/functions/templates/typescript-node/tsconfig.json +28 -0
  123. package/src/functions/templates/uv/README.md +31 -0
  124. package/src/functions/templates/uv/pyproject.toml +29 -0
  125. package/src/interactiveCLI.ts +230 -63
  126. package/src/main.ts +111 -37
  127. package/src/migrations/afterImportActions.ts +2 -2
  128. package/src/migrations/appwriteToX.ts +17 -4
  129. package/src/migrations/dataLoader.ts +4 -4
  130. package/src/migrations/importController.ts +30 -22
  131. package/src/migrations/importDataActions.ts +2 -2
  132. package/src/migrations/relationships.ts +1 -1
  133. package/src/migrations/services/DataTransformationService.ts +196 -0
  134. package/src/migrations/services/FileHandlerService.ts +311 -0
  135. package/src/migrations/services/ImportOrchestrator.ts +669 -0
  136. package/src/migrations/services/RateLimitManager.ts +363 -0
  137. package/src/migrations/services/RelationshipResolver.ts +461 -0
  138. package/src/migrations/services/UserMappingService.ts +345 -0
  139. package/src/migrations/services/ValidationService.ts +349 -0
  140. package/src/migrations/transfer.ts +22 -228
  141. package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
  142. package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
  143. package/src/migrations/yaml/generateImportSchemas.ts +589 -0
  144. package/src/shared/attributeManager.ts +429 -0
  145. package/src/shared/confirmationDialogs.ts +327 -0
  146. package/src/shared/functionManager.ts +515 -0
  147. package/src/shared/indexManager.ts +253 -0
  148. package/src/shared/jsonSchemaGenerator.ts +403 -0
  149. package/src/shared/logging.ts +74 -0
  150. package/src/shared/messageFormatter.ts +195 -0
  151. package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
  152. package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
  153. package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
  154. package/src/shared/progressManager.ts +278 -0
  155. package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
  156. package/src/storage/methods.ts +199 -78
  157. package/src/types.ts +2 -2
  158. package/src/{migrations/users.ts → users/methods.ts} +2 -2
  159. package/src/utils/configMigration.ts +212 -0
  160. package/src/utils/loadConfigs.ts +414 -52
  161. package/src/utils/schemaStrings.ts +2 -1
  162. package/src/utils/setupFiles.ts +742 -40
  163. package/src/{migrations → utils}/validationRules.ts +1 -1
  164. package/src/utils/yamlConverter.ts +131 -0
  165. package/src/utilsController.ts +75 -54
  166. package/src/functions/templates/poetry/README.md +0 -30
  167. package/src/functions/templates/poetry/pyproject.toml +0 -16
  168. package/src/migrations/attributes.ts +0 -561
  169. package/src/migrations/backup.ts +0 -205
  170. package/src/migrations/databases.ts +0 -39
  171. package/src/migrations/dbHelpers.ts +0 -92
  172. package/src/migrations/indexes.ts +0 -40
  173. package/src/migrations/logging.ts +0 -29
  174. package/src/migrations/storage.ts +0 -538
  175. /package/src/{migrations → functions}/openapi.ts +0 -0
  176. /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
  177. /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
  178. /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
@@ -0,0 +1,375 @@
1
+ import { z } from "zod";
2
+ import path from "path";
3
+ import fs from "fs";
4
+ import yaml from "js-yaml";
5
+ import { logger } from "../../shared/logging.js";
6
+ // YAML Import Configuration Schema
7
+ export const YamlImportConfigSchema = z.object({
8
+ source: z.object({
9
+ file: z.string().describe("Path to the data file relative to .appwrite directory"),
10
+ basePath: z.string().optional().describe("JSON path to the data array (e.g., 'RECORDS')"),
11
+ type: z.enum(["json", "csv", "yaml"]).default("json").describe("Source file type"),
12
+ }),
13
+ target: z.object({
14
+ collection: z.string().describe("Name of the target collection"),
15
+ type: z.enum(["create", "update"]).default("create").describe("Import operation type"),
16
+ primaryKey: z.string().default("id").describe("Primary key field name in source data"),
17
+ createUsers: z.boolean().default(false).describe("Whether to create user accounts"),
18
+ }),
19
+ mapping: z.object({
20
+ attributes: z.array(z.object({
21
+ // Source mapping
22
+ oldKey: z.string().optional().describe("Source field name"),
23
+ oldKeys: z.array(z.string()).optional().describe("Multiple source field names"),
24
+ // Target mapping
25
+ targetKey: z.string().describe("Target field name in collection"),
26
+ valueToSet: z.any().optional().describe("Static value to set"),
27
+ // File handling
28
+ fileData: z.object({
29
+ path: z.string().describe("File path template (supports {field} placeholders)"),
30
+ name: z.string().describe("File name template (supports {field} placeholders)"),
31
+ }).optional(),
32
+ // Data transformation
33
+ converters: z.array(z.string()).default([]).describe("Converter function names"),
34
+ // Validation
35
+ validation: z.array(z.object({
36
+ rule: z.string().describe("Validation rule name"),
37
+ params: z.array(z.string()).describe("Validation parameters with {field} placeholders"),
38
+ })).default([]).describe("Validation rules"),
39
+ // Post-import actions
40
+ afterImport: z.array(z.object({
41
+ action: z.string().describe("Action name"),
42
+ params: z.array(z.union([z.string(), z.record(z.string(), z.any())])).describe("Action parameters"),
43
+ })).default([]).describe("Actions to execute after import"),
44
+ })).describe("Field mapping configuration"),
45
+ relationships: z.array(z.object({
46
+ sourceField: z.string().describe("Source field containing old ID"),
47
+ targetField: z.string().describe("Target field to set new ID"),
48
+ targetCollection: z.string().describe("Collection to find new ID in"),
49
+ fieldToSet: z.string().optional().describe("Field to set (defaults to sourceField)"),
50
+ targetFieldToMatch: z.string().optional().describe("Field to match in target collection"),
51
+ })).default([]).describe("Relationship mappings"),
52
+ }),
53
+ options: z.object({
54
+ batchSize: z.number().min(1).max(1000).default(50).describe("Batch size for processing"),
55
+ skipValidation: z.boolean().default(false).describe("Skip data validation"),
56
+ dryRun: z.boolean().default(false).describe("Perform dry run without actual import"),
57
+ continueOnError: z.boolean().default(true).describe("Continue processing if individual items fail"),
58
+ updateMapping: z.object({
59
+ originalIdField: z.string().describe("Field in source data for matching"),
60
+ targetField: z.string().describe("Field in collection to match against"),
61
+ }).optional().describe("Configuration for update operations"),
62
+ }).default({}),
63
+ });
64
+ /**
65
+ * Service for loading and converting YAML import configurations.
66
+ * Integrates with existing .appwrite YAML structure while providing
67
+ * enhanced import configuration capabilities.
68
+ */
69
+ export class YamlImportConfigLoader {
70
+ appwriteFolderPath;
71
+ constructor(appwriteFolderPath) {
72
+ this.appwriteFolderPath = appwriteFolderPath;
73
+ }
74
+ /**
75
+ * Loads a YAML import configuration file.
76
+ *
77
+ * @param configPath - Path to the YAML config file relative to .appwrite/import/
78
+ * @returns Parsed and validated YAML import configuration
79
+ */
80
+ async loadImportConfig(configPath) {
81
+ const fullPath = path.resolve(this.appwriteFolderPath, "import", configPath);
82
+ if (!fs.existsSync(fullPath)) {
83
+ throw new Error(`Import configuration file not found: ${fullPath}`);
84
+ }
85
+ try {
86
+ const yamlContent = fs.readFileSync(fullPath, "utf8");
87
+ const rawConfig = yaml.load(yamlContent);
88
+ // Validate against schema
89
+ const validatedConfig = YamlImportConfigSchema.parse(rawConfig);
90
+ logger.info(`Loaded import configuration: ${configPath}`);
91
+ return validatedConfig;
92
+ }
93
+ catch (error) {
94
+ if (error instanceof z.ZodError) {
95
+ const errorMessages = error.errors.map(err => `${err.path.join('.')}: ${err.message}`);
96
+ throw new Error(`Invalid import configuration in ${configPath}:\n${errorMessages.join('\n')}`);
97
+ }
98
+ throw new Error(`Failed to load import configuration ${configPath}: ${error}`);
99
+ }
100
+ }
101
+ /**
102
+ * Loads all import configurations from the .appwrite/import directory.
103
+ *
104
+ * @returns Map of collection names to their import configurations
105
+ */
106
+ async loadAllImportConfigs() {
107
+ const importDir = path.join(this.appwriteFolderPath, "import");
108
+ const configs = new Map();
109
+ if (!fs.existsSync(importDir)) {
110
+ logger.info("No import directory found, skipping YAML import configurations");
111
+ return configs;
112
+ }
113
+ try {
114
+ const files = fs.readdirSync(importDir, { withFileTypes: true });
115
+ for (const file of files) {
116
+ if (file.isFile() && file.name.endsWith('.yaml')) {
117
+ try {
118
+ const config = await this.loadImportConfig(file.name);
119
+ const collectionName = config.target.collection;
120
+ if (!configs.has(collectionName)) {
121
+ configs.set(collectionName, []);
122
+ }
123
+ configs.get(collectionName).push(config);
124
+ }
125
+ catch (error) {
126
+ logger.error(`Failed to load import config ${file.name}:`, error);
127
+ }
128
+ }
129
+ }
130
+ logger.info(`Loaded import configurations for ${configs.size} collections`);
131
+ return configs;
132
+ }
133
+ catch (error) {
134
+ logger.error("Failed to scan import directory:", error);
135
+ return configs;
136
+ }
137
+ }
138
+ /**
139
+ * Converts YAML import configuration to legacy ImportDef format.
140
+ * Maintains compatibility with existing import system.
141
+ *
142
+ * @param yamlConfig - YAML import configuration
143
+ * @returns Legacy ImportDef object
144
+ */
145
+ convertToImportDef(yamlConfig) {
146
+ const attributeMappings = yamlConfig.mapping.attributes.map(attr => ({
147
+ oldKey: attr.oldKey,
148
+ oldKeys: attr.oldKeys,
149
+ targetKey: attr.targetKey,
150
+ valueToSet: attr.valueToSet,
151
+ fileData: attr.fileData,
152
+ converters: attr.converters,
153
+ validationActions: attr.validation.map(v => ({
154
+ action: v.rule,
155
+ params: v.params,
156
+ })),
157
+ postImportActions: attr.afterImport.map(a => ({
158
+ action: a.action,
159
+ params: a.params,
160
+ })),
161
+ }));
162
+ const idMappings = yamlConfig.mapping.relationships.map(rel => ({
163
+ sourceField: rel.sourceField,
164
+ targetField: rel.targetField,
165
+ targetCollection: rel.targetCollection,
166
+ fieldToSet: rel.fieldToSet,
167
+ targetFieldToMatch: rel.targetFieldToMatch,
168
+ }));
169
+ return {
170
+ type: yamlConfig.target.type,
171
+ filePath: yamlConfig.source.file,
172
+ basePath: yamlConfig.source.basePath,
173
+ primaryKeyField: yamlConfig.target.primaryKey,
174
+ createUsers: yamlConfig.target.createUsers,
175
+ attributeMappings,
176
+ idMappings: idMappings.length > 0 ? idMappings : undefined,
177
+ updateMapping: yamlConfig.options.updateMapping,
178
+ };
179
+ }
180
+ /**
181
+ * Generates a template YAML import configuration.
182
+ * Useful for getting started with YAML-based imports.
183
+ *
184
+ * @param collectionName - Name of the collection
185
+ * @param sourceFile - Source data file name
186
+ * @returns YAML configuration template
187
+ */
188
+ generateTemplate(collectionName, sourceFile) {
189
+ const template = {
190
+ source: {
191
+ file: `importData/${sourceFile}`,
192
+ basePath: "RECORDS",
193
+ type: "json"
194
+ },
195
+ target: {
196
+ collection: collectionName,
197
+ type: "create",
198
+ primaryKey: "id",
199
+ createUsers: false
200
+ },
201
+ mapping: {
202
+ attributes: [
203
+ {
204
+ oldKey: "id",
205
+ targetKey: "id",
206
+ converters: ["anyToString"]
207
+ },
208
+ {
209
+ oldKey: "name",
210
+ targetKey: "name",
211
+ converters: ["anyToString"],
212
+ validation: [
213
+ {
214
+ rule: "required",
215
+ params: ["{name}"]
216
+ }
217
+ ]
218
+ },
219
+ {
220
+ oldKey: "avatar_url",
221
+ targetKey: "avatar",
222
+ fileData: {
223
+ path: "{avatar_url}",
224
+ name: "{name}_avatar"
225
+ },
226
+ afterImport: [
227
+ {
228
+ action: "createFileAndUpdateField",
229
+ params: ["{dbId}", "{collId}", "{docId}", "avatar", "{bucketId}", "{filePath}", "{fileName}"]
230
+ }
231
+ ]
232
+ }
233
+ ],
234
+ relationships: [
235
+ {
236
+ sourceField: "user_id",
237
+ targetField: "userId",
238
+ targetCollection: "Users"
239
+ }
240
+ ]
241
+ },
242
+ options: {
243
+ batchSize: 50,
244
+ skipValidation: false,
245
+ dryRun: false,
246
+ continueOnError: true
247
+ }
248
+ };
249
+ return yaml.dump(template, {
250
+ indent: 2,
251
+ lineWidth: 120,
252
+ sortKeys: false,
253
+ });
254
+ }
255
+ /**
256
+ * Creates the import directory structure if it doesn't exist.
257
+ * Sets up the recommended directory layout for YAML import configurations.
258
+ */
259
+ async createImportStructure() {
260
+ const importDir = path.join(this.appwriteFolderPath, "import");
261
+ const collectionsDir = path.join(importDir, "collections");
262
+ const templatesDir = path.join(importDir, "templates");
263
+ // Create directories
264
+ for (const dir of [importDir, collectionsDir, templatesDir]) {
265
+ if (!fs.existsSync(dir)) {
266
+ fs.mkdirSync(dir, { recursive: true });
267
+ logger.info(`Created directory: ${dir}`);
268
+ }
269
+ }
270
+ // Create README file
271
+ const readmePath = path.join(importDir, "README.md");
272
+ if (!fs.existsSync(readmePath)) {
273
+ const readmeContent = `# Import Configurations
274
+
275
+ This directory contains YAML-based import configurations for the Appwrite Utils CLI.
276
+
277
+ ## Structure
278
+
279
+ - \`collections/\` - Collection-specific import configurations
280
+ - \`templates/\` - Template configurations for reference
281
+ - \`*.yaml\` - Individual import configuration files
282
+
283
+ ## Configuration Format
284
+
285
+ Each YAML file defines:
286
+ - **source**: Data source configuration (file, type, basePath)
287
+ - **target**: Target collection and operation type
288
+ - **mapping**: Field mappings, transformations, and relationships
289
+ - **options**: Import options (batch size, validation, etc.)
290
+
291
+ ## Example
292
+
293
+ \`\`\`yaml
294
+ source:
295
+ file: "importData/users.json"
296
+ basePath: "RECORDS"
297
+ type: "json"
298
+
299
+ target:
300
+ collection: "Users"
301
+ type: "create"
302
+ primaryKey: "id"
303
+ createUsers: true
304
+
305
+ mapping:
306
+ attributes:
307
+ - oldKey: "user_id"
308
+ targetKey: "userId"
309
+ converters: ["anyToString"]
310
+ - oldKey: "profile_image"
311
+ targetKey: "avatar"
312
+ fileData:
313
+ path: "assets/profiles/{user_id}.jpg"
314
+ name: "{firstName}_{lastName}_avatar"
315
+
316
+ options:
317
+ batchSize: 50
318
+ continueOnError: true
319
+ \`\`\`
320
+
321
+ ## Usage
322
+
323
+ The CLI will automatically detect and load YAML import configurations during the import process.
324
+ `;
325
+ fs.writeFileSync(readmePath, readmeContent);
326
+ logger.info(`Created README: ${readmePath}`);
327
+ }
328
+ }
329
+ /**
330
+ * Validates import configuration against collection schema.
331
+ * Ensures that all target keys exist as attributes in the collection.
332
+ *
333
+ * @param yamlConfig - YAML import configuration
334
+ * @param collectionAttributes - Collection attribute definitions
335
+ * @returns Validation errors (empty if valid)
336
+ */
337
+ validateAgainstCollection(yamlConfig, collectionAttributes) {
338
+ const errors = [];
339
+ const attributeKeys = new Set(collectionAttributes.map(attr => attr.key));
340
+ for (const mapping of yamlConfig.mapping.attributes) {
341
+ if (!attributeKeys.has(mapping.targetKey)) {
342
+ errors.push(`Target key '${mapping.targetKey}' not found in collection attributes`);
343
+ }
344
+ }
345
+ return errors;
346
+ }
347
+ /**
348
+ * Gets statistics about import configurations.
349
+ *
350
+ * @param configs - Map of collection configurations
351
+ * @returns Statistics object
352
+ */
353
+ getStatistics(configs) {
354
+ let totalConfigurations = 0;
355
+ let totalAttributeMappings = 0;
356
+ let totalRelationshipMappings = 0;
357
+ const configsByType = {};
358
+ for (const [collectionName, collectionConfigs] of configs.entries()) {
359
+ totalConfigurations += collectionConfigs.length;
360
+ for (const config of collectionConfigs) {
361
+ totalAttributeMappings += config.mapping.attributes.length;
362
+ totalRelationshipMappings += config.mapping.relationships.length;
363
+ const type = config.target.type;
364
+ configsByType[type] = (configsByType[type] || 0) + 1;
365
+ }
366
+ }
367
+ return {
368
+ totalConfigurations,
369
+ collectionsWithConfigs: configs.size,
370
+ totalAttributeMappings,
371
+ totalRelationshipMappings,
372
+ configsByType,
373
+ };
374
+ }
375
+ }
@@ -0,0 +1,87 @@
1
+ import type { CollectionCreate, ImportDef } from "appwrite-utils";
2
+ /**
3
+ * Integration service that bridges YAML import configurations with the existing import system.
4
+ * Provides seamless integration between new YAML configs and legacy TypeScript collection definitions.
5
+ */
6
+ export declare class YamlImportIntegration {
7
+ private configLoader;
8
+ private appwriteFolderPath;
9
+ constructor(appwriteFolderPath: string);
10
+ /**
11
+ * Initializes the YAML import system.
12
+ * Creates necessary directories, schemas, and example files.
13
+ */
14
+ initialize(): Promise<void>;
15
+ /**
16
+ * Merges YAML import configurations with existing collection definitions.
17
+ * Allows collections to have both TypeScript and YAML import definitions.
18
+ *
19
+ * @param collections - Existing collection configurations
20
+ * @returns Collections with merged import definitions
21
+ */
22
+ mergeWithCollections(collections: CollectionCreate[]): Promise<CollectionCreate[]>;
23
+ /**
24
+ * Validates YAML import configurations against existing collection schemas.
25
+ * Ensures that all target fields exist in the collection definitions.
26
+ *
27
+ * @param collections - Collection definitions to validate against
28
+ * @returns Validation results with errors and warnings
29
+ */
30
+ validateConfigurations(collections: CollectionCreate[]): Promise<{
31
+ isValid: boolean;
32
+ errors: string[];
33
+ warnings: string[];
34
+ }>;
35
+ /**
36
+ * Validates that source files exist for import configurations.
37
+ */
38
+ private validateSourceFiles;
39
+ /**
40
+ * Validates that converter functions are available.
41
+ */
42
+ private validateConverters;
43
+ /**
44
+ * Generates a YAML import configuration from an existing ImportDef.
45
+ * Useful for migrating TypeScript configurations to YAML.
46
+ *
47
+ * @param importDef - Existing ImportDef to convert
48
+ * @param collectionName - Name of the collection
49
+ * @returns YAML configuration string
50
+ */
51
+ convertImportDefToYaml(importDef: ImportDef, collectionName: string): string;
52
+ /**
53
+ * Exports existing TypeScript import configurations to YAML files.
54
+ * Helps migrate from TypeScript to YAML-based configurations.
55
+ *
56
+ * @param collections - Collections with existing import definitions
57
+ */
58
+ exportToYaml(collections: CollectionCreate[]): Promise<void>;
59
+ /**
60
+ * Gets statistics about YAML import configurations.
61
+ */
62
+ getStatistics(): Promise<{
63
+ hasYamlConfigs: boolean;
64
+ totalConfigurations: number;
65
+ collectionsWithConfigs: number;
66
+ configurationsByType: {
67
+ [type: string]: number;
68
+ };
69
+ totalAttributeMappings: number;
70
+ totalRelationshipMappings: number;
71
+ }>;
72
+ /**
73
+ * Creates a new YAML import configuration from a template.
74
+ *
75
+ * @param collectionName - Name of the collection
76
+ * @param sourceFile - Source data file name
77
+ * @param outputPath - Output file path (optional)
78
+ */
79
+ createFromTemplate(collectionName: string, sourceFile: string, outputPath?: string): Promise<string>;
80
+ /**
81
+ * Checks if YAML import system is properly set up.
82
+ */
83
+ isSetupComplete(): Promise<{
84
+ isComplete: boolean;
85
+ missingComponents: string[];
86
+ }>;
87
+ }