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