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,589 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { logger } from "../../shared/logging.js";
4
+
5
+ /**
6
+ * Generates JSON Schema for YAML import configurations.
7
+ * Provides IntelliSense support for YAML files in IDEs.
8
+ */
9
+ export function generateImportConfigSchema(): any {
10
+ return {
11
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
12
+ "$id": "https://appwrite-utils.dev/schemas/import-config.schema.json",
13
+ "title": "Appwrite Import Configuration",
14
+ "description": "YAML configuration for importing data into Appwrite collections",
15
+ "type": "object",
16
+ "properties": {
17
+ "source": {
18
+ "type": "object",
19
+ "description": "Data source configuration",
20
+ "properties": {
21
+ "file": {
22
+ "type": "string",
23
+ "description": "Path to the data file relative to .appwrite directory",
24
+ "examples": ["importData/users.json", "data/products.csv"]
25
+ },
26
+ "basePath": {
27
+ "type": "string",
28
+ "description": "JSON path to the data array (e.g., 'RECORDS')",
29
+ "examples": ["RECORDS", "data", "items"]
30
+ },
31
+ "type": {
32
+ "type": "string",
33
+ "enum": ["json", "csv", "yaml"],
34
+ "default": "json",
35
+ "description": "Source file type"
36
+ }
37
+ },
38
+ "required": ["file"],
39
+ "additionalProperties": false
40
+ },
41
+ "target": {
42
+ "type": "object",
43
+ "description": "Target collection configuration",
44
+ "properties": {
45
+ "collection": {
46
+ "type": "string",
47
+ "description": "Name of the target collection",
48
+ "examples": ["Users", "Products", "Orders"]
49
+ },
50
+ "type": {
51
+ "type": "string",
52
+ "enum": ["create", "update"],
53
+ "default": "create",
54
+ "description": "Import operation type"
55
+ },
56
+ "primaryKey": {
57
+ "type": "string",
58
+ "default": "id",
59
+ "description": "Primary key field name in source data"
60
+ },
61
+ "createUsers": {
62
+ "type": "boolean",
63
+ "default": false,
64
+ "description": "Whether to create user accounts for user collections"
65
+ }
66
+ },
67
+ "required": ["collection"],
68
+ "additionalProperties": false
69
+ },
70
+ "mapping": {
71
+ "type": "object",
72
+ "description": "Field mapping and transformation configuration",
73
+ "properties": {
74
+ "attributes": {
75
+ "type": "array",
76
+ "description": "Field mapping configuration",
77
+ "items": {
78
+ "$ref": "#/$defs/attributeMapping"
79
+ }
80
+ },
81
+ "relationships": {
82
+ "type": "array",
83
+ "description": "Relationship mappings between collections",
84
+ "items": {
85
+ "$ref": "#/$defs/relationshipMapping"
86
+ },
87
+ "default": []
88
+ }
89
+ },
90
+ "required": ["attributes"],
91
+ "additionalProperties": false
92
+ },
93
+ "options": {
94
+ "type": "object",
95
+ "description": "Import options and settings",
96
+ "properties": {
97
+ "batchSize": {
98
+ "type": "number",
99
+ "minimum": 1,
100
+ "maximum": 1000,
101
+ "default": 50,
102
+ "description": "Batch size for processing"
103
+ },
104
+ "skipValidation": {
105
+ "type": "boolean",
106
+ "default": false,
107
+ "description": "Skip data validation during import"
108
+ },
109
+ "dryRun": {
110
+ "type": "boolean",
111
+ "default": false,
112
+ "description": "Perform dry run without actual import"
113
+ },
114
+ "continueOnError": {
115
+ "type": "boolean",
116
+ "default": true,
117
+ "description": "Continue processing if individual items fail"
118
+ },
119
+ "updateMapping": {
120
+ "type": "object",
121
+ "description": "Configuration for update operations",
122
+ "properties": {
123
+ "originalIdField": {
124
+ "type": "string",
125
+ "description": "Field in source data for matching existing records"
126
+ },
127
+ "targetField": {
128
+ "type": "string",
129
+ "description": "Field in collection to match against"
130
+ }
131
+ },
132
+ "required": ["originalIdField", "targetField"],
133
+ "additionalProperties": false
134
+ }
135
+ },
136
+ "additionalProperties": false
137
+ }
138
+ },
139
+ "required": ["source", "target", "mapping"],
140
+ "additionalProperties": false,
141
+ "$defs": {
142
+ "attributeMapping": {
143
+ "type": "object",
144
+ "description": "Single field mapping configuration",
145
+ "properties": {
146
+ "oldKey": {
147
+ "type": "string",
148
+ "description": "Source field name"
149
+ },
150
+ "oldKeys": {
151
+ "type": "array",
152
+ "items": {
153
+ "type": "string"
154
+ },
155
+ "description": "Multiple source field names (alternative to oldKey)"
156
+ },
157
+ "targetKey": {
158
+ "type": "string",
159
+ "description": "Target field name in collection"
160
+ },
161
+ "valueToSet": {
162
+ "description": "Static value to set (alternative to oldKey/oldKeys)"
163
+ },
164
+ "fileData": {
165
+ "type": "object",
166
+ "description": "File handling configuration",
167
+ "properties": {
168
+ "path": {
169
+ "type": "string",
170
+ "description": "File path template (supports {field} placeholders)",
171
+ "examples": ["{avatar_url}", "assets/profiles/{user_id}.jpg", "files/{filename}"]
172
+ },
173
+ "name": {
174
+ "type": "string",
175
+ "description": "File name template (supports {field} placeholders)",
176
+ "examples": ["{firstName}_{lastName}_avatar", "{productName}_image", "{timestamp}_{filename}"]
177
+ }
178
+ },
179
+ "required": ["path", "name"],
180
+ "additionalProperties": false
181
+ },
182
+ "converters": {
183
+ "type": "array",
184
+ "items": {
185
+ "type": "string",
186
+ "enum": [
187
+ "anyToString",
188
+ "anyToNumber",
189
+ "anyToBoolean",
190
+ "anyToDate",
191
+ "stringToLowerCase",
192
+ "stringToUpperCase",
193
+ "stringTrim",
194
+ "numberToString",
195
+ "booleanToString",
196
+ "dateToString",
197
+ "dateToTimestamp",
198
+ "timestampToDate",
199
+ "arrayToString",
200
+ "stringToArray",
201
+ "removeNulls",
202
+ "removeEmpty"
203
+ ]
204
+ },
205
+ "description": "Converter function names",
206
+ "default": []
207
+ },
208
+ "validation": {
209
+ "type": "array",
210
+ "items": {
211
+ "type": "object",
212
+ "properties": {
213
+ "rule": {
214
+ "type": "string",
215
+ "enum": [
216
+ "required",
217
+ "email",
218
+ "url",
219
+ "phone",
220
+ "minLength",
221
+ "maxLength",
222
+ "pattern",
223
+ "numeric",
224
+ "positive",
225
+ "negative",
226
+ "integer",
227
+ "double",
228
+ "boolean",
229
+ "date",
230
+ "array",
231
+ "object"
232
+ ],
233
+ "description": "Validation rule name"
234
+ },
235
+ "params": {
236
+ "type": "array",
237
+ "items": {
238
+ "type": "string"
239
+ },
240
+ "description": "Validation parameters with {field} placeholders"
241
+ }
242
+ },
243
+ "required": ["rule", "params"],
244
+ "additionalProperties": false
245
+ },
246
+ "description": "Validation rules",
247
+ "default": []
248
+ },
249
+ "afterImport": {
250
+ "type": "array",
251
+ "items": {
252
+ "type": "object",
253
+ "properties": {
254
+ "action": {
255
+ "type": "string",
256
+ "enum": [
257
+ "createFileAndUpdateField",
258
+ "updateCreatedDocument",
259
+ "checkAndUpdateFieldInDocument",
260
+ "setFieldFromOtherCollectionDocument",
261
+ "setFieldFromOtherCollectionDocuments",
262
+ "setTargetFieldFromOtherCollectionDocumentsByMatchingField",
263
+ "createOrGetBucket"
264
+ ],
265
+ "description": "Post-import action name"
266
+ },
267
+ "params": {
268
+ "type": "array",
269
+ "items": {
270
+ "oneOf": [
271
+ { "type": "string" },
272
+ { "type": "object" }
273
+ ]
274
+ },
275
+ "description": "Action parameters (supports {field} placeholders)"
276
+ }
277
+ },
278
+ "required": ["action", "params"],
279
+ "additionalProperties": false
280
+ },
281
+ "description": "Actions to execute after import",
282
+ "default": []
283
+ }
284
+ },
285
+ "required": ["targetKey"],
286
+ "oneOf": [
287
+ { "required": ["oldKey"] },
288
+ { "required": ["oldKeys"] },
289
+ { "required": ["valueToSet"] }
290
+ ],
291
+ "additionalProperties": false
292
+ },
293
+ "relationshipMapping": {
294
+ "type": "object",
295
+ "description": "Relationship mapping between collections",
296
+ "properties": {
297
+ "sourceField": {
298
+ "type": "string",
299
+ "description": "Source field containing old ID"
300
+ },
301
+ "targetField": {
302
+ "type": "string",
303
+ "description": "Target field to set new ID"
304
+ },
305
+ "targetCollection": {
306
+ "type": "string",
307
+ "description": "Collection to find new ID in"
308
+ },
309
+ "fieldToSet": {
310
+ "type": "string",
311
+ "description": "Field to set (defaults to sourceField)"
312
+ },
313
+ "targetFieldToMatch": {
314
+ "type": "string",
315
+ "description": "Field to match in target collection (defaults to targetField)"
316
+ }
317
+ },
318
+ "required": ["sourceField", "targetField", "targetCollection"],
319
+ "additionalProperties": false
320
+ }
321
+ }
322
+ };
323
+ }
324
+
325
+ /**
326
+ * Creates all necessary schema files for YAML import configurations.
327
+ *
328
+ * @param appwriteFolderPath - Path to the .appwrite directory
329
+ */
330
+ export async function createImportSchemas(appwriteFolderPath: string): Promise<void> {
331
+ const yamlSchemasDir = path.join(appwriteFolderPath, ".yaml_schemas");
332
+
333
+ // Ensure directory exists
334
+ if (!fs.existsSync(yamlSchemasDir)) {
335
+ fs.mkdirSync(yamlSchemasDir, { recursive: true });
336
+ }
337
+
338
+ // Generate and write import config schema
339
+ const importConfigSchema = generateImportConfigSchema();
340
+ const importSchemaPath = path.join(yamlSchemasDir, "import-config.schema.json");
341
+
342
+ fs.writeFileSync(importSchemaPath, JSON.stringify(importConfigSchema, null, 2));
343
+ logger.info(`Created import configuration schema: ${importSchemaPath}`);
344
+
345
+ // Create schema index file for easy reference
346
+ const schemaIndex = {
347
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
348
+ "$id": "https://appwrite-utils.dev/schemas/index.json",
349
+ "title": "Appwrite Utils Schema Index",
350
+ "description": "Index of all available schemas for Appwrite Utils YAML configurations",
351
+ "type": "object",
352
+ "properties": {
353
+ "schemas": {
354
+ "type": "object",
355
+ "properties": {
356
+ "collection": {
357
+ "type": "string",
358
+ "const": "./collection.schema.json",
359
+ "description": "Schema for collection definitions"
360
+ },
361
+ "appwriteConfig": {
362
+ "type": "string",
363
+ "const": "./appwrite-config.schema.json",
364
+ "description": "Schema for main Appwrite configuration"
365
+ },
366
+ "importConfig": {
367
+ "type": "string",
368
+ "const": "./import-config.schema.json",
369
+ "description": "Schema for import configurations"
370
+ }
371
+ }
372
+ }
373
+ }
374
+ };
375
+
376
+ const indexPath = path.join(yamlSchemasDir, "index.json");
377
+ fs.writeFileSync(indexPath, JSON.stringify(schemaIndex, null, 2));
378
+ logger.info(`Created schema index: ${indexPath}`);
379
+ }
380
+
381
+ /**
382
+ * Generates example YAML import configurations.
383
+ *
384
+ * @param appwriteFolderPath - Path to the .appwrite directory
385
+ */
386
+ export async function createImportExamples(appwriteFolderPath: string): Promise<void> {
387
+ const importDir = path.join(appwriteFolderPath, "import");
388
+ const examplesDir = path.join(importDir, "examples");
389
+
390
+ // Ensure directories exist
391
+ if (!fs.existsSync(examplesDir)) {
392
+ fs.mkdirSync(examplesDir, { recursive: true });
393
+ }
394
+
395
+ // User import example
396
+ const userImportExample = `# yaml-language-server: $schema=../.yaml_schemas/import-config.schema.json
397
+ # User Import Configuration Example
398
+
399
+ source:
400
+ file: "importData/users.json"
401
+ basePath: "RECORDS"
402
+ type: "json"
403
+
404
+ target:
405
+ collection: "Users"
406
+ type: "create"
407
+ primaryKey: "user_id"
408
+ createUsers: true
409
+
410
+ mapping:
411
+ attributes:
412
+ - oldKey: "user_id"
413
+ targetKey: "userId"
414
+ converters: ["anyToString"]
415
+ validation:
416
+ - rule: "required"
417
+ params: ["{userId}"]
418
+
419
+ - oldKey: "email"
420
+ targetKey: "email"
421
+ converters: ["anyToString", "stringToLowerCase"]
422
+ validation:
423
+ - rule: "email"
424
+ params: ["{email}"]
425
+ - rule: "required"
426
+ params: ["{email}"]
427
+
428
+ - oldKey: "full_name"
429
+ targetKey: "name"
430
+ converters: ["anyToString", "stringTrim"]
431
+
432
+ - oldKey: "profile_image_url"
433
+ targetKey: "avatar"
434
+ fileData:
435
+ path: "{profile_image_url}"
436
+ name: "{user_id}_avatar"
437
+ afterImport:
438
+ - action: "createFileAndUpdateField"
439
+ params: ["{dbId}", "{collId}", "{docId}", "avatar", "{bucketId}", "{filePath}", "{fileName}"]
440
+
441
+ - oldKey: "phone_number"
442
+ targetKey: "phone"
443
+ converters: ["anyToString"]
444
+ validation:
445
+ - rule: "phone"
446
+ params: ["{phone}"]
447
+
448
+ - oldKey: "is_active"
449
+ targetKey: "status"
450
+ converters: ["anyToBoolean"]
451
+
452
+ relationships: []
453
+
454
+ options:
455
+ batchSize: 25
456
+ skipValidation: false
457
+ dryRun: false
458
+ continueOnError: true
459
+ `;
460
+
461
+ // Product import example with relationships
462
+ const productImportExample = `# yaml-language-server: $schema=../.yaml_schemas/import-config.schema.json
463
+ # Product Import Configuration Example
464
+
465
+ source:
466
+ file: "importData/products.json"
467
+ basePath: "products"
468
+ type: "json"
469
+
470
+ target:
471
+ collection: "Products"
472
+ type: "create"
473
+ primaryKey: "product_id"
474
+ createUsers: false
475
+
476
+ mapping:
477
+ attributes:
478
+ - oldKey: "product_id"
479
+ targetKey: "productId"
480
+ converters: ["anyToString"]
481
+
482
+ - oldKey: "name"
483
+ targetKey: "name"
484
+ converters: ["anyToString", "stringTrim"]
485
+ validation:
486
+ - rule: "required"
487
+ params: ["{name}"]
488
+ - rule: "minLength"
489
+ params: ["{name}", "3"]
490
+
491
+ - oldKey: "description"
492
+ targetKey: "description"
493
+ converters: ["anyToString"]
494
+
495
+ - oldKey: "price"
496
+ targetKey: "price"
497
+ converters: ["anyToNumber"]
498
+ validation:
499
+ - rule: "numeric"
500
+ params: ["{price}"]
501
+ - rule: "positive"
502
+ params: ["{price}"]
503
+
504
+ - oldKey: "category_id"
505
+ targetKey: "categoryId"
506
+ converters: ["anyToString"]
507
+
508
+ - oldKey: "image_urls"
509
+ targetKey: "images"
510
+ fileData:
511
+ path: "assets/products/{product_id}/"
512
+ name: "product_{product_id}_{index}"
513
+ afterImport:
514
+ - action: "createFileAndUpdateField"
515
+ params: ["{dbId}", "{collId}", "{docId}", "images", "{bucketId}", "{filePath}", "{fileName}"]
516
+
517
+ - valueToSet: "active"
518
+ targetKey: "status"
519
+
520
+ relationships:
521
+ - sourceField: "category_id"
522
+ targetField: "categoryId"
523
+ targetCollection: "Categories"
524
+ fieldToSet: "categoryId"
525
+
526
+ - sourceField: "vendor_id"
527
+ targetField: "vendorId"
528
+ targetCollection: "Vendors"
529
+
530
+ options:
531
+ batchSize: 50
532
+ skipValidation: false
533
+ dryRun: false
534
+ continueOnError: true
535
+ `;
536
+
537
+ // Update example
538
+ const updateExample = `# yaml-language-server: $schema=../.yaml_schemas/import-config.schema.json
539
+ # Update Configuration Example
540
+
541
+ source:
542
+ file: "importData/user_updates.json"
543
+ type: "json"
544
+
545
+ target:
546
+ collection: "Users"
547
+ type: "update"
548
+ primaryKey: "user_id"
549
+
550
+ mapping:
551
+ attributes:
552
+ - oldKey: "updated_email"
553
+ targetKey: "email"
554
+ converters: ["anyToString", "stringToLowerCase"]
555
+ validation:
556
+ - rule: "email"
557
+ params: ["{email}"]
558
+
559
+ - oldKey: "new_phone"
560
+ targetKey: "phone"
561
+ converters: ["anyToString"]
562
+
563
+ - oldKey: "last_login"
564
+ targetKey: "lastLoginAt"
565
+ converters: ["anyToDate", "dateToTimestamp"]
566
+
567
+ relationships: []
568
+
569
+ options:
570
+ batchSize: 100
571
+ continueOnError: true
572
+ updateMapping:
573
+ originalIdField: "user_id"
574
+ targetField: "userId"
575
+ `;
576
+
577
+ // Write example files
578
+ const examples = [
579
+ { name: "users-import.yaml", content: userImportExample },
580
+ { name: "products-import.yaml", content: productImportExample },
581
+ { name: "users-update.yaml", content: updateExample },
582
+ ];
583
+
584
+ for (const example of examples) {
585
+ const examplePath = path.join(examplesDir, example.name);
586
+ fs.writeFileSync(examplePath, example.content);
587
+ logger.info(`Created import example: ${examplePath}`);
588
+ }
589
+ }