appwrite-utils-cli 1.9.7 → 1.11.0

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 (425) hide show
  1. package/CONFIG_TODO.md +1189 -1189
  2. package/README.md +1004 -1004
  3. package/SELECTION_DIALOGS.md +145 -145
  4. package/SERVICE_IMPLEMENTATION_REPORT.md +462 -462
  5. package/package.json +6 -3
  6. package/scripts/copy-templates.ts +23 -23
  7. package/src/adapters/index.ts +11 -37
  8. package/src/backups/operations/bucketBackup.ts +277 -277
  9. package/src/backups/operations/collectionBackup.ts +310 -310
  10. package/src/backups/operations/comprehensiveBackup.ts +342 -342
  11. package/src/backups/schemas/bucketManifest.ts +78 -78
  12. package/src/backups/schemas/comprehensiveManifest.ts +76 -76
  13. package/src/backups/tracking/centralizedTracking.ts +352 -352
  14. package/src/cli/commands/configCommands.ts +265 -201
  15. package/src/cli/commands/databaseCommands.ts +931 -879
  16. package/src/cli/commands/functionCommands.ts +333 -332
  17. package/src/cli/commands/importFileCommands.ts +815 -0
  18. package/src/cli/commands/schemaCommands.ts +141 -141
  19. package/src/cli/commands/storageCommands.ts +2 -3
  20. package/src/cli/commands/transferCommands.ts +454 -457
  21. package/src/collections/attributes.ts.backup +1555 -1555
  22. package/src/collections/{attributes.ts → columns.ts} +15 -10
  23. package/src/collections/indexes.ts +350 -352
  24. package/src/collections/methods.ts +714 -700
  25. package/src/collections/tableOperations.ts +29 -8
  26. package/src/collections/transferOperations.ts +376 -377
  27. package/src/collections/wipeOperations.ts +449 -346
  28. package/src/databases/methods.ts +49 -49
  29. package/src/databases/setup.ts +77 -77
  30. package/src/examples/yamlTerminologyExample.ts +346 -346
  31. package/src/functions/deployments.ts +221 -220
  32. package/src/functions/fnConfigDiscovery.ts +2 -2
  33. package/src/functions/methods.ts +284 -284
  34. package/src/functions/templates/count-docs-in-collection/README.md +53 -53
  35. package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -159
  36. package/src/functions/templates/count-docs-in-collection/src/request.ts +8 -8
  37. package/src/functions/templates/hono-typescript/README.md +285 -285
  38. package/src/functions/templates/hono-typescript/src/adapters/request.ts +73 -73
  39. package/src/functions/templates/hono-typescript/src/adapters/response.ts +105 -105
  40. package/src/functions/templates/hono-typescript/src/app.ts +179 -179
  41. package/src/functions/templates/hono-typescript/src/context.ts +102 -102
  42. package/src/functions/templates/hono-typescript/src/{index.ts → main.ts} +53 -53
  43. package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +118 -118
  44. package/src/functions/templates/typescript-node/README.md +31 -31
  45. package/src/functions/templates/typescript-node/src/context.ts +102 -102
  46. package/src/functions/templates/typescript-node/src/{index.ts → main.ts} +29 -29
  47. package/src/functions/templates/uv/README.md +30 -30
  48. package/src/functions/templates/uv/pyproject.toml +29 -29
  49. package/src/functions/templates/uv/src/context.py +124 -124
  50. package/src/functions/templates/uv/src/{index.py → main.py} +45 -45
  51. package/src/init.ts +62 -62
  52. package/src/interactiveCLI.ts +1095 -1030
  53. package/src/main.ts +1517 -1670
  54. package/src/migrations/afterImportActions.ts +579 -580
  55. package/src/migrations/appwriteToX.ts +634 -630
  56. package/src/migrations/comprehensiveTransfer.ts +2149 -2149
  57. package/src/migrations/dataLoader.ts +1729 -1702
  58. package/src/migrations/importController.ts +440 -428
  59. package/src/migrations/importDataActions.ts +315 -315
  60. package/src/migrations/relationships.ts +333 -334
  61. package/src/migrations/services/DataTransformationService.ts +195 -195
  62. package/src/migrations/services/FileHandlerService.ts +310 -310
  63. package/src/migrations/services/ImportOrchestrator.ts +674 -665
  64. package/src/migrations/services/RateLimitManager.ts +362 -362
  65. package/src/migrations/services/RelationshipResolver.ts +460 -460
  66. package/src/migrations/services/UserMappingService.ts +344 -344
  67. package/src/migrations/services/ValidationService.ts +333 -333
  68. package/src/migrations/transfer.ts +987 -942
  69. package/src/migrations/yaml/YamlImportConfigLoader.ts +438 -438
  70. package/src/migrations/yaml/YamlImportIntegration.ts +438 -438
  71. package/src/migrations/yaml/generateImportSchemas.ts +1347 -1347
  72. package/src/schemas/authUser.ts +23 -23
  73. package/src/setup.ts +8 -8
  74. package/src/setupCommands.ts +5 -6
  75. package/src/setupController.ts +42 -42
  76. package/src/shared/backupMetadataSchema.ts +93 -93
  77. package/src/shared/backupTracking.ts +211 -211
  78. package/src/shared/confirmationDialogs.ts +326 -326
  79. package/src/shared/migrationHelpers.ts +232 -232
  80. package/src/shared/operationLogger.ts +20 -20
  81. package/src/shared/operationQueue.ts +326 -327
  82. package/src/shared/operationsTable.ts +338 -338
  83. package/src/shared/operationsTableSchema.ts +60 -60
  84. package/src/shared/progressManager.ts +277 -277
  85. package/src/shared/relationshipExtractor.ts +214 -214
  86. package/src/shared/selectionDialogs.ts +775 -722
  87. package/src/storage/backupCompression.ts +88 -88
  88. package/src/storage/methods.ts +695 -682
  89. package/src/storage/schemas.ts +205 -205
  90. package/src/tables/indexManager.ts +408 -408
  91. package/src/types/node-appwrite-tablesdb.d.ts +43 -43
  92. package/src/types.ts +9 -9
  93. package/src/users/methods.ts +358 -359
  94. package/src/utils/configMigration.ts +347 -347
  95. package/src/utils/index.ts +2 -2
  96. package/src/utils/loadConfigs.ts +457 -449
  97. package/src/utils/setupFiles.ts +1236 -1238
  98. package/src/utilsController.ts +1263 -1213
  99. package/tests/README.md +496 -496
  100. package/tests/adapters/AdapterFactory.test.ts +276 -276
  101. package/tests/integration/syncOperations.test.ts +462 -462
  102. package/tests/jest.config.js +24 -24
  103. package/tests/migration/configMigration.test.ts +545 -545
  104. package/tests/setup.ts +61 -61
  105. package/tests/testUtils.ts +339 -339
  106. package/tests/utils/loadConfigs.test.ts +349 -349
  107. package/tests/validation/configValidation.test.ts +411 -411
  108. package/tsconfig.json +44 -44
  109. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +0 -380
  110. package/.appwrite/.yaml_schemas/collection.schema.json +0 -255
  111. package/.appwrite/collections/Categories.yaml +0 -182
  112. package/.appwrite/collections/ExampleCollection.yaml +0 -36
  113. package/.appwrite/collections/Posts.yaml +0 -227
  114. package/.appwrite/collections/Users.yaml +0 -149
  115. package/.appwrite/config.yaml +0 -109
  116. package/.appwrite/import/README.md +0 -148
  117. package/.appwrite/import/categories-import.yaml +0 -129
  118. package/.appwrite/import/posts-import.yaml +0 -208
  119. package/.appwrite/import/users-import.yaml +0 -130
  120. package/.appwrite/importData/categories.json +0 -194
  121. package/.appwrite/importData/posts.json +0 -270
  122. package/.appwrite/importData/users.json +0 -220
  123. package/.appwrite/schemas/categories.json +0 -128
  124. package/.appwrite/schemas/exampleCollection.json +0 -52
  125. package/.appwrite/schemas/posts.json +0 -173
  126. package/.appwrite/schemas/users.json +0 -125
  127. package/dist/adapters/AdapterFactory.d.ts +0 -94
  128. package/dist/adapters/AdapterFactory.js +0 -420
  129. package/dist/adapters/DatabaseAdapter.d.ts +0 -243
  130. package/dist/adapters/DatabaseAdapter.js +0 -50
  131. package/dist/adapters/LegacyAdapter.d.ts +0 -50
  132. package/dist/adapters/LegacyAdapter.js +0 -615
  133. package/dist/adapters/TablesDBAdapter.d.ts +0 -45
  134. package/dist/adapters/TablesDBAdapter.js +0 -611
  135. package/dist/adapters/index.d.ts +0 -11
  136. package/dist/adapters/index.js +0 -12
  137. package/dist/backups/operations/bucketBackup.d.ts +0 -19
  138. package/dist/backups/operations/bucketBackup.js +0 -197
  139. package/dist/backups/operations/collectionBackup.d.ts +0 -30
  140. package/dist/backups/operations/collectionBackup.js +0 -201
  141. package/dist/backups/operations/comprehensiveBackup.d.ts +0 -25
  142. package/dist/backups/operations/comprehensiveBackup.js +0 -238
  143. package/dist/backups/schemas/bucketManifest.d.ts +0 -93
  144. package/dist/backups/schemas/bucketManifest.js +0 -33
  145. package/dist/backups/schemas/comprehensiveManifest.d.ts +0 -108
  146. package/dist/backups/schemas/comprehensiveManifest.js +0 -32
  147. package/dist/backups/tracking/centralizedTracking.d.ts +0 -34
  148. package/dist/backups/tracking/centralizedTracking.js +0 -274
  149. package/dist/cli/commands/configCommands.d.ts +0 -8
  150. package/dist/cli/commands/configCommands.js +0 -166
  151. package/dist/cli/commands/databaseCommands.d.ts +0 -14
  152. package/dist/cli/commands/databaseCommands.js +0 -644
  153. package/dist/cli/commands/functionCommands.d.ts +0 -7
  154. package/dist/cli/commands/functionCommands.js +0 -330
  155. package/dist/cli/commands/schemaCommands.d.ts +0 -7
  156. package/dist/cli/commands/schemaCommands.js +0 -169
  157. package/dist/cli/commands/storageCommands.d.ts +0 -5
  158. package/dist/cli/commands/storageCommands.js +0 -143
  159. package/dist/cli/commands/transferCommands.d.ts +0 -5
  160. package/dist/cli/commands/transferCommands.js +0 -384
  161. package/dist/collections/attributes.d.ts +0 -13
  162. package/dist/collections/attributes.js +0 -1333
  163. package/dist/collections/indexes.d.ts +0 -12
  164. package/dist/collections/indexes.js +0 -217
  165. package/dist/collections/methods.d.ts +0 -19
  166. package/dist/collections/methods.js +0 -587
  167. package/dist/collections/tableOperations.d.ts +0 -86
  168. package/dist/collections/tableOperations.js +0 -447
  169. package/dist/collections/transferOperations.d.ts +0 -8
  170. package/dist/collections/transferOperations.js +0 -412
  171. package/dist/collections/wipeOperations.d.ts +0 -16
  172. package/dist/collections/wipeOperations.js +0 -233
  173. package/dist/config/ConfigManager.d.ts +0 -450
  174. package/dist/config/ConfigManager.js +0 -650
  175. package/dist/config/configMigration.d.ts +0 -87
  176. package/dist/config/configMigration.js +0 -390
  177. package/dist/config/configValidation.d.ts +0 -66
  178. package/dist/config/configValidation.js +0 -358
  179. package/dist/config/index.d.ts +0 -8
  180. package/dist/config/index.js +0 -7
  181. package/dist/config/services/ConfigDiscoveryService.d.ts +0 -122
  182. package/dist/config/services/ConfigDiscoveryService.js +0 -322
  183. package/dist/config/services/ConfigLoaderService.d.ts +0 -129
  184. package/dist/config/services/ConfigLoaderService.js +0 -535
  185. package/dist/config/services/ConfigMergeService.d.ts +0 -208
  186. package/dist/config/services/ConfigMergeService.js +0 -308
  187. package/dist/config/services/ConfigValidationService.d.ts +0 -214
  188. package/dist/config/services/ConfigValidationService.js +0 -310
  189. package/dist/config/services/SessionAuthService.d.ts +0 -225
  190. package/dist/config/services/SessionAuthService.js +0 -456
  191. package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +0 -1
  192. package/dist/config/services/__tests__/ConfigMergeService.test.js +0 -271
  193. package/dist/config/services/index.d.ts +0 -13
  194. package/dist/config/services/index.js +0 -10
  195. package/dist/config/yamlConfig.d.ts +0 -722
  196. package/dist/config/yamlConfig.js +0 -702
  197. package/dist/databases/methods.d.ts +0 -6
  198. package/dist/databases/methods.js +0 -35
  199. package/dist/databases/setup.d.ts +0 -5
  200. package/dist/databases/setup.js +0 -45
  201. package/dist/examples/yamlTerminologyExample.d.ts +0 -42
  202. package/dist/examples/yamlTerminologyExample.js +0 -272
  203. package/dist/functions/deployments.d.ts +0 -4
  204. package/dist/functions/deployments.js +0 -146
  205. package/dist/functions/fnConfigDiscovery.d.ts +0 -3
  206. package/dist/functions/fnConfigDiscovery.js +0 -108
  207. package/dist/functions/methods.d.ts +0 -16
  208. package/dist/functions/methods.js +0 -174
  209. package/dist/functions/pathResolution.d.ts +0 -37
  210. package/dist/functions/pathResolution.js +0 -185
  211. package/dist/functions/templates/count-docs-in-collection/README.md +0 -54
  212. package/dist/functions/templates/count-docs-in-collection/package.json +0 -25
  213. package/dist/functions/templates/count-docs-in-collection/src/main.ts +0 -159
  214. package/dist/functions/templates/count-docs-in-collection/src/request.ts +0 -9
  215. package/dist/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
  216. package/dist/functions/templates/hono-typescript/README.md +0 -286
  217. package/dist/functions/templates/hono-typescript/package.json +0 -26
  218. package/dist/functions/templates/hono-typescript/src/adapters/request.ts +0 -74
  219. package/dist/functions/templates/hono-typescript/src/adapters/response.ts +0 -106
  220. package/dist/functions/templates/hono-typescript/src/app.ts +0 -180
  221. package/dist/functions/templates/hono-typescript/src/context.ts +0 -103
  222. package/dist/functions/templates/hono-typescript/src/index.ts +0 -54
  223. package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -119
  224. package/dist/functions/templates/hono-typescript/tsconfig.json +0 -20
  225. package/dist/functions/templates/typescript-node/README.md +0 -32
  226. package/dist/functions/templates/typescript-node/package.json +0 -25
  227. package/dist/functions/templates/typescript-node/src/context.ts +0 -103
  228. package/dist/functions/templates/typescript-node/src/index.ts +0 -29
  229. package/dist/functions/templates/typescript-node/tsconfig.json +0 -28
  230. package/dist/functions/templates/uv/README.md +0 -31
  231. package/dist/functions/templates/uv/pyproject.toml +0 -30
  232. package/dist/functions/templates/uv/src/__init__.py +0 -0
  233. package/dist/functions/templates/uv/src/context.py +0 -125
  234. package/dist/functions/templates/uv/src/index.py +0 -46
  235. package/dist/init.d.ts +0 -2
  236. package/dist/init.js +0 -57
  237. package/dist/interactiveCLI.d.ts +0 -31
  238. package/dist/interactiveCLI.js +0 -898
  239. package/dist/main.d.ts +0 -2
  240. package/dist/main.js +0 -1180
  241. package/dist/migrations/afterImportActions.d.ts +0 -17
  242. package/dist/migrations/afterImportActions.js +0 -306
  243. package/dist/migrations/appwriteToX.d.ts +0 -211
  244. package/dist/migrations/appwriteToX.js +0 -491
  245. package/dist/migrations/comprehensiveTransfer.d.ts +0 -147
  246. package/dist/migrations/comprehensiveTransfer.js +0 -1317
  247. package/dist/migrations/dataLoader.d.ts +0 -753
  248. package/dist/migrations/dataLoader.js +0 -1250
  249. package/dist/migrations/importController.d.ts +0 -23
  250. package/dist/migrations/importController.js +0 -268
  251. package/dist/migrations/importDataActions.d.ts +0 -50
  252. package/dist/migrations/importDataActions.js +0 -230
  253. package/dist/migrations/relationships.d.ts +0 -29
  254. package/dist/migrations/relationships.js +0 -204
  255. package/dist/migrations/services/DataTransformationService.d.ts +0 -55
  256. package/dist/migrations/services/DataTransformationService.js +0 -158
  257. package/dist/migrations/services/FileHandlerService.d.ts +0 -75
  258. package/dist/migrations/services/FileHandlerService.js +0 -236
  259. package/dist/migrations/services/ImportOrchestrator.d.ts +0 -97
  260. package/dist/migrations/services/ImportOrchestrator.js +0 -485
  261. package/dist/migrations/services/RateLimitManager.d.ts +0 -138
  262. package/dist/migrations/services/RateLimitManager.js +0 -279
  263. package/dist/migrations/services/RelationshipResolver.d.ts +0 -120
  264. package/dist/migrations/services/RelationshipResolver.js +0 -332
  265. package/dist/migrations/services/UserMappingService.d.ts +0 -109
  266. package/dist/migrations/services/UserMappingService.js +0 -277
  267. package/dist/migrations/services/ValidationService.d.ts +0 -74
  268. package/dist/migrations/services/ValidationService.js +0 -260
  269. package/dist/migrations/transfer.d.ts +0 -26
  270. package/dist/migrations/transfer.js +0 -608
  271. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +0 -131
  272. package/dist/migrations/yaml/YamlImportConfigLoader.js +0 -383
  273. package/dist/migrations/yaml/YamlImportIntegration.d.ts +0 -93
  274. package/dist/migrations/yaml/YamlImportIntegration.js +0 -341
  275. package/dist/migrations/yaml/generateImportSchemas.d.ts +0 -30
  276. package/dist/migrations/yaml/generateImportSchemas.js +0 -1327
  277. package/dist/schemas/authUser.d.ts +0 -24
  278. package/dist/schemas/authUser.js +0 -17
  279. package/dist/setup.d.ts +0 -2
  280. package/dist/setup.js +0 -5
  281. package/dist/setupCommands.d.ts +0 -58
  282. package/dist/setupCommands.js +0 -490
  283. package/dist/setupController.d.ts +0 -9
  284. package/dist/setupController.js +0 -34
  285. package/dist/shared/attributeMapper.d.ts +0 -20
  286. package/dist/shared/attributeMapper.js +0 -203
  287. package/dist/shared/backupMetadataSchema.d.ts +0 -94
  288. package/dist/shared/backupMetadataSchema.js +0 -38
  289. package/dist/shared/backupTracking.d.ts +0 -18
  290. package/dist/shared/backupTracking.js +0 -176
  291. package/dist/shared/confirmationDialogs.d.ts +0 -75
  292. package/dist/shared/confirmationDialogs.js +0 -236
  293. package/dist/shared/errorUtils.d.ts +0 -54
  294. package/dist/shared/errorUtils.js +0 -95
  295. package/dist/shared/functionManager.d.ts +0 -48
  296. package/dist/shared/functionManager.js +0 -348
  297. package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
  298. package/dist/shared/jsonSchemaGenerator.js +0 -290
  299. package/dist/shared/logging.d.ts +0 -61
  300. package/dist/shared/logging.js +0 -116
  301. package/dist/shared/messageFormatter.d.ts +0 -39
  302. package/dist/shared/messageFormatter.js +0 -162
  303. package/dist/shared/migrationHelpers.d.ts +0 -61
  304. package/dist/shared/migrationHelpers.js +0 -145
  305. package/dist/shared/operationLogger.d.ts +0 -10
  306. package/dist/shared/operationLogger.js +0 -12
  307. package/dist/shared/operationQueue.d.ts +0 -40
  308. package/dist/shared/operationQueue.js +0 -311
  309. package/dist/shared/operationsTable.d.ts +0 -26
  310. package/dist/shared/operationsTable.js +0 -286
  311. package/dist/shared/operationsTableSchema.d.ts +0 -48
  312. package/dist/shared/operationsTableSchema.js +0 -35
  313. package/dist/shared/progressManager.d.ts +0 -62
  314. package/dist/shared/progressManager.js +0 -215
  315. package/dist/shared/pydanticModelGenerator.d.ts +0 -17
  316. package/dist/shared/pydanticModelGenerator.js +0 -615
  317. package/dist/shared/relationshipExtractor.d.ts +0 -56
  318. package/dist/shared/relationshipExtractor.js +0 -138
  319. package/dist/shared/schemaGenerator.d.ts +0 -40
  320. package/dist/shared/schemaGenerator.js +0 -556
  321. package/dist/shared/selectionDialogs.d.ts +0 -214
  322. package/dist/shared/selectionDialogs.js +0 -544
  323. package/dist/storage/backupCompression.d.ts +0 -20
  324. package/dist/storage/backupCompression.js +0 -67
  325. package/dist/storage/methods.d.ts +0 -32
  326. package/dist/storage/methods.js +0 -472
  327. package/dist/storage/schemas.d.ts +0 -842
  328. package/dist/storage/schemas.js +0 -175
  329. package/dist/tables/indexManager.d.ts +0 -65
  330. package/dist/tables/indexManager.js +0 -294
  331. package/dist/types.d.ts +0 -4
  332. package/dist/types.js +0 -3
  333. package/dist/users/methods.d.ts +0 -16
  334. package/dist/users/methods.js +0 -277
  335. package/dist/utils/ClientFactory.d.ts +0 -87
  336. package/dist/utils/ClientFactory.js +0 -212
  337. package/dist/utils/configDiscovery.d.ts +0 -78
  338. package/dist/utils/configDiscovery.js +0 -472
  339. package/dist/utils/configMigration.d.ts +0 -1
  340. package/dist/utils/configMigration.js +0 -261
  341. package/dist/utils/constantsGenerator.d.ts +0 -31
  342. package/dist/utils/constantsGenerator.js +0 -321
  343. package/dist/utils/dataConverters.d.ts +0 -46
  344. package/dist/utils/dataConverters.js +0 -139
  345. package/dist/utils/directoryUtils.d.ts +0 -22
  346. package/dist/utils/directoryUtils.js +0 -59
  347. package/dist/utils/getClientFromConfig.d.ts +0 -39
  348. package/dist/utils/getClientFromConfig.js +0 -199
  349. package/dist/utils/helperFunctions.d.ts +0 -63
  350. package/dist/utils/helperFunctions.js +0 -156
  351. package/dist/utils/index.d.ts +0 -2
  352. package/dist/utils/index.js +0 -2
  353. package/dist/utils/loadConfigs.d.ts +0 -50
  354. package/dist/utils/loadConfigs.js +0 -358
  355. package/dist/utils/pathResolvers.d.ts +0 -53
  356. package/dist/utils/pathResolvers.js +0 -72
  357. package/dist/utils/projectConfig.d.ts +0 -122
  358. package/dist/utils/projectConfig.js +0 -206
  359. package/dist/utils/retryFailedPromises.d.ts +0 -2
  360. package/dist/utils/retryFailedPromises.js +0 -23
  361. package/dist/utils/sessionAuth.d.ts +0 -48
  362. package/dist/utils/sessionAuth.js +0 -164
  363. package/dist/utils/setupFiles.d.ts +0 -4
  364. package/dist/utils/setupFiles.js +0 -1192
  365. package/dist/utils/typeGuards.d.ts +0 -35
  366. package/dist/utils/typeGuards.js +0 -57
  367. package/dist/utils/validationRules.d.ts +0 -43
  368. package/dist/utils/validationRules.js +0 -42
  369. package/dist/utils/versionDetection.d.ts +0 -58
  370. package/dist/utils/versionDetection.js +0 -251
  371. package/dist/utils/yamlConverter.d.ts +0 -100
  372. package/dist/utils/yamlConverter.js +0 -428
  373. package/dist/utils/yamlLoader.d.ts +0 -70
  374. package/dist/utils/yamlLoader.js +0 -267
  375. package/dist/utilsController.d.ts +0 -107
  376. package/dist/utilsController.js +0 -873
  377. package/src/adapters/AdapterFactory.ts +0 -529
  378. package/src/adapters/DatabaseAdapter.ts +0 -319
  379. package/src/adapters/LegacyAdapter.ts +0 -844
  380. package/src/adapters/TablesDBAdapter.ts +0 -823
  381. package/src/config/ConfigManager.ts +0 -849
  382. package/src/config/README.md +0 -274
  383. package/src/config/configMigration.ts +0 -575
  384. package/src/config/configValidation.ts +0 -445
  385. package/src/config/index.ts +0 -10
  386. package/src/config/services/ConfigDiscoveryService.ts +0 -410
  387. package/src/config/services/ConfigLoaderService.ts +0 -732
  388. package/src/config/services/ConfigMergeService.ts +0 -388
  389. package/src/config/services/ConfigValidationService.ts +0 -394
  390. package/src/config/services/SessionAuthService.ts +0 -565
  391. package/src/config/services/__tests__/ConfigMergeService.test.ts +0 -351
  392. package/src/config/services/index.ts +0 -29
  393. package/src/config/yamlConfig.ts +0 -761
  394. package/src/functions/pathResolution.ts +0 -227
  395. package/src/functions/templates/count-docs-in-collection/package.json +0 -25
  396. package/src/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
  397. package/src/functions/templates/hono-typescript/package.json +0 -26
  398. package/src/functions/templates/hono-typescript/tsconfig.json +0 -20
  399. package/src/functions/templates/typescript-node/package.json +0 -25
  400. package/src/functions/templates/typescript-node/tsconfig.json +0 -28
  401. package/src/shared/attributeMapper.ts +0 -229
  402. package/src/shared/errorUtils.ts +0 -110
  403. package/src/shared/functionManager.ts +0 -537
  404. package/src/shared/jsonSchemaGenerator.ts +0 -383
  405. package/src/shared/logging.ts +0 -149
  406. package/src/shared/messageFormatter.ts +0 -208
  407. package/src/shared/pydanticModelGenerator.ts +0 -618
  408. package/src/shared/schemaGenerator.ts +0 -644
  409. package/src/utils/ClientFactory.ts +0 -240
  410. package/src/utils/configDiscovery.ts +0 -557
  411. package/src/utils/constantsGenerator.ts +0 -369
  412. package/src/utils/dataConverters.ts +0 -159
  413. package/src/utils/directoryUtils.ts +0 -61
  414. package/src/utils/getClientFromConfig.ts +0 -257
  415. package/src/utils/helperFunctions.ts +0 -228
  416. package/src/utils/pathResolvers.ts +0 -81
  417. package/src/utils/projectConfig.ts +0 -340
  418. package/src/utils/retryFailedPromises.ts +0 -29
  419. package/src/utils/sessionAuth.ts +0 -230
  420. package/src/utils/typeGuards.ts +0 -65
  421. package/src/utils/validationRules.ts +0 -88
  422. package/src/utils/versionDetection.ts +0 -292
  423. package/src/utils/yamlConverter.ts +0 -542
  424. package/src/utils/yamlLoader.ts +0 -371
  425. package/tmp-sync-test/.appwrite/collections/TestCollection.yaml +0 -7
@@ -1,873 +0,0 @@
1
- import { Client, Databases, Query, Storage, Users, } from "node-appwrite";
2
- import {} from "appwrite-utils";
3
- import { findAppwriteConfig, findFunctionsDir, } from "./utils/loadConfigs.js";
4
- import { normalizeFunctionName, validateFunctionDirectory } from './functions/pathResolution.js';
5
- import { UsersController } from "./users/methods.js";
6
- import { AppwriteToX } from "./migrations/appwriteToX.js";
7
- import { ImportController } from "./migrations/importController.js";
8
- import { ImportDataActions } from "./migrations/importDataActions.js";
9
- import { ensureDatabasesExist, wipeOtherDatabases, ensureCollectionsExist, } from "./databases/setup.js";
10
- import { createOrUpdateCollections, createOrUpdateCollectionsViaAdapter, wipeDatabase, generateSchemas, fetchAllCollections, wipeCollection, } from "./collections/methods.js";
11
- import { wipeAllTables, wipeTableRows } from "./collections/methods.js";
12
- import { backupDatabase, ensureDatabaseConfigBucketsExist, wipeDocumentStorage, } from "./storage/methods.js";
13
- import path from "path";
14
- import { converterFunctions, validationRules, } from "appwrite-utils";
15
- import { afterImportActions } from "./migrations/afterImportActions.js";
16
- import { transferDatabaseLocalToLocal, transferDatabaseLocalToRemote, transferStorageLocalToLocal, transferStorageLocalToRemote, transferUsersLocalToRemote, } from "./migrations/transfer.js";
17
- import { getClient, getClientWithAuth } from "./utils/getClientFromConfig.js";
18
- import { getAdapterFromConfig } from "./utils/getClientFromConfig.js";
19
- import { hasSessionAuth, findSessionByEndpointAndProject, isValidSessionCookie } from "./utils/sessionAuth.js";
20
- import { fetchAllDatabases } from "./databases/methods.js";
21
- import { listFunctions, updateFunctionSpecifications, } from "./functions/methods.js";
22
- import chalk from "chalk";
23
- import { deployLocalFunction } from "./functions/deployments.js";
24
- import fs from "node:fs";
25
- import { configureLogging, updateLogger, logger } from "./shared/logging.js";
26
- import { MessageFormatter, Messages } from "./shared/messageFormatter.js";
27
- import { SchemaGenerator } from "./shared/schemaGenerator.js";
28
- import { findYamlConfig } from "./config/yamlConfig.js";
29
- import { createImportSchemas } from "./migrations/yaml/generateImportSchemas.js";
30
- import { validateCollectionsTablesConfig, reportValidationResults, validateWithStrictMode } from "./config/configValidation.js";
31
- import { ConfigManager } from "./config/ConfigManager.js";
32
- import { ClientFactory } from "./utils/ClientFactory.js";
33
- import { clearProcessingState, processQueue } from "./shared/operationQueue.js";
34
- export class UtilsController {
35
- // ──────────────────────────────────────────────────
36
- // SINGLETON PATTERN
37
- // ──────────────────────────────────────────────────
38
- static instance = null;
39
- isInitialized = false;
40
- /**
41
- * Get the UtilsController singleton instance
42
- */
43
- static getInstance(currentUserDir, directConfig) {
44
- // Clear instance if currentUserDir has changed
45
- if (UtilsController.instance &&
46
- UtilsController.instance.currentUserDir !== currentUserDir) {
47
- logger.debug(`Clearing singleton: currentUserDir changed from ${UtilsController.instance.currentUserDir} to ${currentUserDir}`, { prefix: "UtilsController" });
48
- UtilsController.clearInstance();
49
- }
50
- // Clear instance if directConfig endpoint or project has changed
51
- if (UtilsController.instance && directConfig) {
52
- const existingConfig = UtilsController.instance.config;
53
- if (existingConfig) {
54
- const endpointChanged = directConfig.appwriteEndpoint &&
55
- existingConfig.appwriteEndpoint !== directConfig.appwriteEndpoint;
56
- const projectChanged = directConfig.appwriteProject &&
57
- existingConfig.appwriteProject !== directConfig.appwriteProject;
58
- if (endpointChanged || projectChanged) {
59
- logger.debug("Clearing singleton: endpoint or project changed", { prefix: "UtilsController" });
60
- UtilsController.clearInstance();
61
- }
62
- }
63
- }
64
- if (!UtilsController.instance) {
65
- UtilsController.instance = new UtilsController(currentUserDir, directConfig);
66
- }
67
- return UtilsController.instance;
68
- }
69
- /**
70
- * Clear the singleton instance (useful for testing)
71
- */
72
- static clearInstance() {
73
- UtilsController.instance = null;
74
- }
75
- // ──────────────────────────────────────────────────
76
- // INSTANCE FIELDS
77
- // ──────────────────────────────────────────────────
78
- appwriteFolderPath;
79
- appwriteConfigPath;
80
- currentUserDir;
81
- config;
82
- appwriteServer;
83
- database;
84
- storage;
85
- adapter;
86
- converterDefinitions = converterFunctions;
87
- validityRuleDefinitions = validationRules;
88
- afterImportActionsDefinitions = afterImportActions;
89
- constructor(currentUserDir, directConfig) {
90
- this.currentUserDir = currentUserDir;
91
- const basePath = currentUserDir;
92
- if (directConfig) {
93
- let hasErrors = false;
94
- if (!directConfig.appwriteEndpoint) {
95
- MessageFormatter.error("Appwrite endpoint is required", undefined, { prefix: "Config" });
96
- hasErrors = true;
97
- }
98
- if (!directConfig.appwriteProject) {
99
- MessageFormatter.error("Appwrite project is required", undefined, { prefix: "Config" });
100
- hasErrors = true;
101
- }
102
- // Check authentication: either API key or session auth is required
103
- const hasValidSession = directConfig.appwriteEndpoint && directConfig.appwriteProject &&
104
- hasSessionAuth(directConfig.appwriteEndpoint, directConfig.appwriteProject);
105
- if (!directConfig.appwriteKey && !hasValidSession) {
106
- MessageFormatter.error("Authentication required: provide an API key or login with 'appwrite login'", undefined, { prefix: "Config" });
107
- hasErrors = true;
108
- }
109
- else if (!directConfig.appwriteKey && hasValidSession) {
110
- MessageFormatter.info("Using session authentication (no API key required)", { prefix: "Auth" });
111
- }
112
- else if (directConfig.appwriteKey && hasValidSession) {
113
- MessageFormatter.info("API key provided, session authentication also available", { prefix: "Auth" });
114
- }
115
- if (!hasErrors) {
116
- // Only set config if we have all required fields
117
- this.appwriteFolderPath = basePath;
118
- this.config = {
119
- appwriteEndpoint: directConfig.appwriteEndpoint,
120
- appwriteProject: directConfig.appwriteProject,
121
- appwriteKey: directConfig.appwriteKey || "",
122
- appwriteClient: null,
123
- apiMode: "auto", // Default to auto-detect for dual API support
124
- authMethod: "auto", // Default to auto-detect authentication method
125
- enableBackups: false,
126
- backupInterval: 0,
127
- backupRetention: 0,
128
- enableBackupCleanup: false,
129
- enableMockData: false,
130
- documentBucketId: "",
131
- usersCollectionName: "",
132
- databases: [],
133
- buckets: [],
134
- functions: [],
135
- logging: {
136
- enabled: false,
137
- level: "info",
138
- console: false,
139
- },
140
- };
141
- }
142
- }
143
- else {
144
- // Try to find config file
145
- const appwriteConfigFound = findAppwriteConfig(basePath);
146
- if (!appwriteConfigFound) {
147
- MessageFormatter.warning("No appwriteConfig.ts found and no direct configuration provided", { prefix: "Config" });
148
- return;
149
- }
150
- this.appwriteConfigPath = appwriteConfigFound;
151
- this.appwriteFolderPath = appwriteConfigFound; // For YAML configs, findAppwriteConfig already returns the correct directory
152
- }
153
- }
154
- async init(options = {}) {
155
- const { validate = false, strictMode = false, preferJson = false } = options;
156
- const configManager = ConfigManager.getInstance();
157
- // Load config if not already loaded
158
- if (!configManager.hasConfig()) {
159
- await configManager.loadConfig({
160
- configDir: this.currentUserDir,
161
- validate,
162
- strictMode,
163
- preferJson,
164
- });
165
- }
166
- const config = configManager.getConfig();
167
- // Configure logging based on config
168
- if (config.logging) {
169
- configureLogging(config.logging);
170
- updateLogger();
171
- }
172
- // Create client and adapter (session already in config from ConfigManager)
173
- const { client, adapter } = await ClientFactory.createFromConfig(config);
174
- this.appwriteServer = client;
175
- this.adapter = adapter;
176
- this.config = config;
177
- // Update config.apiMode from adapter if it's auto or not set
178
- if (adapter && (!config.apiMode || config.apiMode === 'auto')) {
179
- this.config.apiMode = adapter.getApiMode();
180
- logger.debug(`Updated config.apiMode from adapter during init: ${this.config.apiMode}`, { prefix: "UtilsController" });
181
- }
182
- this.database = new Databases(this.appwriteServer);
183
- this.storage = new Storage(this.appwriteServer);
184
- this.config.appwriteClient = this.appwriteServer;
185
- // Log only on FIRST initialization to avoid spam
186
- if (!this.isInitialized) {
187
- const apiMode = adapter.getApiMode();
188
- const configApiMode = this.config.apiMode;
189
- MessageFormatter.info(`Database adapter initialized (apiMode: ${apiMode}, config.apiMode: ${configApiMode})`, { prefix: "Adapter" });
190
- this.isInitialized = true;
191
- }
192
- else {
193
- logger.debug("Adapter reused from cache", { prefix: "UtilsController" });
194
- }
195
- }
196
- async reloadConfig() {
197
- const configManager = ConfigManager.getInstance();
198
- // Session preservation is automatic in ConfigManager
199
- const config = await configManager.reloadConfig();
200
- // Configure logging based on updated config
201
- if (config.logging) {
202
- configureLogging(config.logging);
203
- updateLogger();
204
- }
205
- // Recreate client and adapter
206
- const { client, adapter } = await ClientFactory.createFromConfig(config);
207
- this.appwriteServer = client;
208
- this.adapter = adapter;
209
- this.config = config;
210
- this.database = new Databases(this.appwriteServer);
211
- this.storage = new Storage(this.appwriteServer);
212
- this.config.appwriteClient = this.appwriteServer;
213
- logger.debug("Config reloaded, adapter refreshed", { prefix: "UtilsController" });
214
- }
215
- async ensureDatabaseConfigBucketsExist(databases = []) {
216
- await this.init();
217
- if (!this.storage) {
218
- MessageFormatter.error("Storage not initialized", undefined, { prefix: "Controller" });
219
- return;
220
- }
221
- if (!this.config) {
222
- MessageFormatter.error("Config not initialized", undefined, { prefix: "Controller" });
223
- return;
224
- }
225
- await ensureDatabaseConfigBucketsExist(this.storage, this.config, databases);
226
- }
227
- async ensureDatabasesExist(databases) {
228
- await this.init();
229
- if (!this.config) {
230
- MessageFormatter.error("Config not initialized", undefined, { prefix: "Controller" });
231
- return;
232
- }
233
- await this.ensureDatabaseConfigBucketsExist(databases);
234
- await ensureDatabasesExist(this.config, databases);
235
- }
236
- async ensureCollectionsExist(database, collections) {
237
- await this.init();
238
- if (!this.config) {
239
- MessageFormatter.error("Config not initialized", undefined, { prefix: "Controller" });
240
- return;
241
- }
242
- await ensureCollectionsExist(this.config, database, collections);
243
- }
244
- async getDatabasesByIds(ids) {
245
- await this.init();
246
- if (!this.database) {
247
- MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
248
- return;
249
- }
250
- if (ids.length === 0)
251
- return [];
252
- const dbs = await this.database.list([
253
- Query.limit(500),
254
- Query.equal("$id", ids),
255
- ]);
256
- return dbs.databases;
257
- }
258
- async fetchAllBuckets() {
259
- await this.init();
260
- if (!this.storage) {
261
- MessageFormatter.warning("Storage not initialized - buckets will be empty", { prefix: "Controller" });
262
- return { buckets: [] };
263
- }
264
- try {
265
- const result = await this.storage.listBuckets([
266
- Query.limit(1000) // Increase limit to get all buckets
267
- ]);
268
- MessageFormatter.success(`Found ${result.buckets.length} buckets`, { prefix: "Controller" });
269
- return result;
270
- }
271
- catch (error) {
272
- MessageFormatter.error(`Failed to fetch buckets: ${error.message || error}`, error instanceof Error ? error : undefined, { prefix: "Controller" });
273
- return { buckets: [] };
274
- }
275
- }
276
- async wipeOtherDatabases(databasesToKeep) {
277
- await this.init();
278
- if (!this.database) {
279
- MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
280
- return;
281
- }
282
- await wipeOtherDatabases(this.database, databasesToKeep);
283
- }
284
- async wipeUsers() {
285
- await this.init();
286
- if (!this.config || !this.database) {
287
- MessageFormatter.error("Config or database not initialized", undefined, { prefix: "Controller" });
288
- return;
289
- }
290
- const usersController = new UsersController(this.config, this.database);
291
- await usersController.wipeUsers();
292
- }
293
- async backupDatabase(database, format = 'json') {
294
- await this.init();
295
- if (!this.database || !this.storage || !this.config) {
296
- MessageFormatter.error("Database, storage, or config not initialized", undefined, { prefix: "Controller" });
297
- return;
298
- }
299
- await backupDatabase(this.config, this.database, database.$id, this.storage, format);
300
- }
301
- async listAllFunctions() {
302
- await this.init();
303
- if (!this.appwriteServer) {
304
- MessageFormatter.error("Appwrite server not initialized", undefined, { prefix: "Controller" });
305
- return [];
306
- }
307
- const { functions } = await listFunctions(this.appwriteServer, [
308
- Query.limit(1000),
309
- ]);
310
- return functions;
311
- }
312
- async findFunctionDirectories() {
313
- if (!this.appwriteFolderPath) {
314
- MessageFormatter.error("Failed to get appwriteFolderPath", undefined, { prefix: "Controller" });
315
- return new Map();
316
- }
317
- const functionsDir = findFunctionsDir(this.appwriteFolderPath);
318
- if (!functionsDir) {
319
- MessageFormatter.error("Failed to find functions directory", undefined, { prefix: "Controller" });
320
- return new Map();
321
- }
322
- const functionDirMap = new Map();
323
- const entries = fs.readdirSync(functionsDir, { withFileTypes: true });
324
- for (const entry of entries) {
325
- if (entry.isDirectory()) {
326
- const functionPath = path.join(functionsDir, entry.name);
327
- // Validate it's a function directory
328
- if (!validateFunctionDirectory(functionPath)) {
329
- continue; // Skip invalid directories
330
- }
331
- // Match with config functions using normalized names
332
- if (this.config?.functions) {
333
- const normalizedEntryName = normalizeFunctionName(entry.name);
334
- const matchingFunc = this.config.functions.find((f) => normalizeFunctionName(f.name) === normalizedEntryName);
335
- if (matchingFunc) {
336
- functionDirMap.set(matchingFunc.name, functionPath);
337
- }
338
- }
339
- }
340
- }
341
- return functionDirMap;
342
- }
343
- async deployFunction(functionName, functionPath, functionConfig) {
344
- await this.init();
345
- if (!this.appwriteServer) {
346
- MessageFormatter.error("Appwrite server not initialized", undefined, { prefix: "Controller" });
347
- return;
348
- }
349
- if (!functionConfig) {
350
- functionConfig = this.config?.functions?.find((f) => f.name === functionName);
351
- }
352
- if (!functionConfig) {
353
- MessageFormatter.error(`Function ${functionName} not found in config`, undefined, { prefix: "Controller" });
354
- return;
355
- }
356
- await deployLocalFunction(this.appwriteServer, functionName, functionConfig, functionPath);
357
- }
358
- async syncFunctions() {
359
- await this.init();
360
- if (!this.appwriteServer) {
361
- MessageFormatter.error("Appwrite server not initialized", undefined, { prefix: "Controller" });
362
- return;
363
- }
364
- const localFunctions = this.config?.functions || [];
365
- const remoteFunctions = await listFunctions(this.appwriteServer, [
366
- Query.limit(1000),
367
- ]);
368
- for (const localFunction of localFunctions) {
369
- MessageFormatter.progress(`Syncing function ${localFunction.name}...`, { prefix: "Functions" });
370
- await this.deployFunction(localFunction.name);
371
- }
372
- MessageFormatter.success("All functions synchronized successfully!", { prefix: "Functions" });
373
- }
374
- async wipeDatabase(database, wipeBucket = false) {
375
- await this.init();
376
- if (!this.database || !this.config)
377
- throw new Error("Database not initialized");
378
- try {
379
- // Session is already in config from ConfigManager
380
- const { adapter, apiMode } = await getAdapterFromConfig(this.config, false);
381
- if (apiMode === 'tablesdb') {
382
- await wipeAllTables(adapter, database.$id);
383
- }
384
- else {
385
- await wipeDatabase(this.database, database.$id);
386
- }
387
- }
388
- catch {
389
- await wipeDatabase(this.database, database.$id);
390
- }
391
- if (wipeBucket) {
392
- await this.wipeBucketFromDatabase(database);
393
- }
394
- }
395
- async wipeBucketFromDatabase(database) {
396
- // Check configured bucket in database config
397
- const configuredBucket = this.config?.databases?.find((db) => db.$id === database.$id)?.bucket;
398
- if (configuredBucket?.$id) {
399
- await this.wipeDocumentStorage(configuredBucket.$id);
400
- }
401
- // Also check for document bucket ID pattern
402
- if (this.config?.documentBucketId) {
403
- const documentBucketId = `${this.config.documentBucketId}_${database.$id
404
- .toLowerCase()
405
- .trim()
406
- .replace(/\s+/g, "")}`;
407
- try {
408
- await this.wipeDocumentStorage(documentBucketId);
409
- }
410
- catch (error) {
411
- // Ignore if bucket doesn't exist
412
- if (error?.type !== "storage_bucket_not_found") {
413
- throw error;
414
- }
415
- }
416
- }
417
- }
418
- async wipeCollection(database, collection) {
419
- await this.init();
420
- if (!this.database || !this.config)
421
- throw new Error("Database not initialized");
422
- try {
423
- // Session is already in config from ConfigManager
424
- const { adapter, apiMode } = await getAdapterFromConfig(this.config, false);
425
- if (apiMode === 'tablesdb') {
426
- await wipeTableRows(adapter, database.$id, collection.$id);
427
- }
428
- else {
429
- await wipeCollection(this.database, database.$id, collection.$id);
430
- }
431
- }
432
- catch {
433
- await wipeCollection(this.database, database.$id, collection.$id);
434
- }
435
- }
436
- async wipeDocumentStorage(bucketId) {
437
- await this.init();
438
- if (!this.storage)
439
- throw new Error("Storage not initialized");
440
- await wipeDocumentStorage(this.storage, bucketId);
441
- }
442
- async createOrUpdateCollectionsForDatabases(databases, collections = []) {
443
- await this.init();
444
- if (!this.database || !this.config)
445
- throw new Error("Database or config not initialized");
446
- for (const database of databases) {
447
- await this.createOrUpdateCollections(database, undefined, collections);
448
- }
449
- }
450
- async createOrUpdateCollections(database, deletedCollections, collections = []) {
451
- await this.init();
452
- if (!this.database || !this.config)
453
- throw new Error("Database or config not initialized");
454
- // Ensure apiMode is properly set from adapter
455
- if (this.adapter && (!this.config.apiMode || this.config.apiMode === 'auto')) {
456
- this.config.apiMode = this.adapter.getApiMode();
457
- logger.debug(`Updated config.apiMode from adapter: ${this.config.apiMode}`, { prefix: "UtilsController" });
458
- }
459
- // Ensure we don't carry state between databases in a multi-db push
460
- // This resets processed sets and name->id mapping per database
461
- try {
462
- clearProcessingState();
463
- }
464
- catch { }
465
- // Always prefer adapter path for unified behavior. LegacyAdapter internally translates when needed.
466
- if (this.adapter) {
467
- logger.debug("Using adapter for createOrUpdateCollections (unified path)", {
468
- prefix: "UtilsController",
469
- apiMode: this.adapter.getApiMode()
470
- });
471
- await createOrUpdateCollectionsViaAdapter(this.adapter, database.$id, this.config, deletedCollections, collections);
472
- }
473
- else {
474
- // Fallback if adapter is unavailable for some reason
475
- logger.debug("Adapter unavailable, falling back to legacy Databases path", { prefix: "UtilsController" });
476
- await createOrUpdateCollections(this.database, database.$id, this.config, deletedCollections, collections);
477
- }
478
- // Safety net: Process any remaining queued operations to complete relationship sync
479
- try {
480
- MessageFormatter.info(`🔄 Processing final operation queue for database ${database.$id}`, { prefix: "UtilsController" });
481
- await processQueue(this.adapter || this.database, database.$id);
482
- MessageFormatter.info(`✅ Operation queue processing completed`, { prefix: "UtilsController" });
483
- }
484
- catch (error) {
485
- MessageFormatter.error(`Failed to process operation queue`, error instanceof Error ? error : new Error(String(error)), { prefix: 'UtilsController' });
486
- }
487
- }
488
- async generateSchemas() {
489
- // Schema generation doesn't need Appwrite connection, just config
490
- if (!this.config) {
491
- MessageFormatter.progress("Loading config from ConfigManager...", { prefix: "Config" });
492
- try {
493
- const configManager = ConfigManager.getInstance();
494
- // Load config if not already loaded
495
- if (!configManager.hasConfig()) {
496
- await configManager.loadConfig({
497
- configDir: this.currentUserDir,
498
- validate: false,
499
- strictMode: false,
500
- });
501
- }
502
- this.config = configManager.getConfig();
503
- MessageFormatter.info("Config loaded successfully from ConfigManager", { prefix: "Config" });
504
- }
505
- catch (error) {
506
- MessageFormatter.error("Failed to load config", error instanceof Error ? error : undefined, { prefix: "Config" });
507
- return;
508
- }
509
- }
510
- if (!this.appwriteFolderPath) {
511
- MessageFormatter.error("Failed to get appwriteFolderPath", undefined, { prefix: "Controller" });
512
- return;
513
- }
514
- await generateSchemas(this.config, this.appwriteFolderPath);
515
- }
516
- async importData(options = {}) {
517
- await this.init();
518
- if (!this.database) {
519
- MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
520
- return;
521
- }
522
- if (!this.storage) {
523
- MessageFormatter.error("Storage not initialized", undefined, { prefix: "Controller" });
524
- return;
525
- }
526
- if (!this.config) {
527
- MessageFormatter.error("Config not initialized", undefined, { prefix: "Controller" });
528
- return;
529
- }
530
- if (!this.appwriteFolderPath) {
531
- MessageFormatter.error("Failed to get appwriteFolderPath", undefined, { prefix: "Controller" });
532
- return;
533
- }
534
- const importDataActions = new ImportDataActions(this.database, this.storage, this.config, this.converterDefinitions, this.validityRuleDefinitions, this.afterImportActionsDefinitions);
535
- const importController = new ImportController(this.config, this.database, this.storage, this.appwriteFolderPath, importDataActions, options, options.databases);
536
- await importController.run(options.collections);
537
- }
538
- async synchronizeConfigurations(databases, config, databaseSelections, bucketSelections) {
539
- await this.init();
540
- if (!this.storage) {
541
- MessageFormatter.error("Storage not initialized", undefined, { prefix: "Controller" });
542
- return;
543
- }
544
- const configToUse = config || this.config;
545
- if (!configToUse) {
546
- MessageFormatter.error("Config not initialized", undefined, { prefix: "Controller" });
547
- return;
548
- }
549
- if (!this.appwriteFolderPath) {
550
- MessageFormatter.error("Failed to get appwriteFolderPath", undefined, { prefix: "Controller" });
551
- return;
552
- }
553
- // If selections are provided, filter the databases accordingly
554
- let filteredDatabases = databases;
555
- if (databaseSelections && databaseSelections.length > 0) {
556
- // Convert selections to Models.Database format
557
- filteredDatabases = [];
558
- const allDatabases = databases ? databases : await fetchAllDatabases(this.database);
559
- for (const selection of databaseSelections) {
560
- const database = allDatabases.find(db => db.$id === selection.databaseId);
561
- if (database) {
562
- filteredDatabases.push(database);
563
- }
564
- else {
565
- MessageFormatter.warning(`Database with ID ${selection.databaseId} not found`, { prefix: "Controller" });
566
- }
567
- }
568
- MessageFormatter.info(`Syncing ${filteredDatabases.length} selected databases out of ${allDatabases.length} available`, { prefix: "Controller" });
569
- }
570
- const appwriteToX = new AppwriteToX(configToUse, this.appwriteFolderPath, this.storage);
571
- await appwriteToX.toSchemas(filteredDatabases);
572
- // Update the controller's config with the synchronized collections
573
- this.config = appwriteToX.updatedConfig;
574
- // Write the updated config back to disk
575
- const generator = new SchemaGenerator(this.config, this.appwriteFolderPath);
576
- const yamlConfigPath = findYamlConfig(this.appwriteFolderPath);
577
- const isYamlProject = !!yamlConfigPath;
578
- await generator.updateConfig(this.config, isYamlProject);
579
- // Regenerate JSON schemas to reflect any table terminology fixes
580
- try {
581
- MessageFormatter.progress("Regenerating JSON schemas...", { prefix: "Sync" });
582
- await createImportSchemas(this.appwriteFolderPath);
583
- MessageFormatter.success("JSON schemas regenerated successfully", { prefix: "Sync" });
584
- }
585
- catch (error) {
586
- // Log error but don't fail the sync process
587
- const errorMessage = error instanceof Error ? error.message : String(error);
588
- MessageFormatter.warning(`Failed to regenerate JSON schemas, but sync completed: ${errorMessage}`, { prefix: "Sync" });
589
- logger.warn("Schema regeneration failed during sync:", error);
590
- }
591
- }
592
- async selectivePull(databaseSelections, bucketSelections) {
593
- await this.init();
594
- if (!this.database) {
595
- MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
596
- return;
597
- }
598
- MessageFormatter.progress("Starting selective pull (Appwrite → local config)...", { prefix: "Controller" });
599
- // Convert database selections to Models.Database format
600
- const selectedDatabases = [];
601
- for (const dbSelection of databaseSelections) {
602
- // Get the full database object from the controller
603
- const databases = await fetchAllDatabases(this.database);
604
- const database = databases.find(db => db.$id === dbSelection.databaseId);
605
- if (database) {
606
- selectedDatabases.push(database);
607
- MessageFormatter.info(`Selected database: ${database.name} (${database.$id})`, { prefix: "Controller" });
608
- // Log selected tables for this database
609
- if (dbSelection.tableIds && dbSelection.tableIds.length > 0) {
610
- MessageFormatter.info(` Tables: ${dbSelection.tableIds.join(', ')}`, { prefix: "Controller" });
611
- }
612
- }
613
- else {
614
- MessageFormatter.warning(`Database with ID ${dbSelection.databaseId} not found`, { prefix: "Controller" });
615
- }
616
- }
617
- if (selectedDatabases.length === 0) {
618
- MessageFormatter.warning("No valid databases selected for pull", { prefix: "Controller" });
619
- return;
620
- }
621
- // Log bucket selections if provided
622
- if (bucketSelections && bucketSelections.length > 0) {
623
- MessageFormatter.info(`Selected ${bucketSelections.length} buckets:`, { prefix: "Controller" });
624
- for (const bucketSelection of bucketSelections) {
625
- const dbInfo = bucketSelection.databaseId ? ` (DB: ${bucketSelection.databaseId})` : '';
626
- MessageFormatter.info(` - ${bucketSelection.bucketName} (${bucketSelection.bucketId})${dbInfo}`, { prefix: "Controller" });
627
- }
628
- }
629
- // Perform selective sync using the enhanced synchronizeConfigurations method
630
- await this.synchronizeConfigurations(selectedDatabases, this.config, databaseSelections, bucketSelections);
631
- MessageFormatter.success("Selective pull completed successfully! Remote config pulled to local.", { prefix: "Controller" });
632
- }
633
- async selectivePush(databaseSelections, bucketSelections) {
634
- await this.init();
635
- if (!this.database) {
636
- MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
637
- return;
638
- }
639
- // Always reload config from disk so pushes use current local YAML/Ts definitions
640
- try {
641
- await this.reloadConfig();
642
- MessageFormatter.info("Reloaded config from disk for push", { prefix: "Controller" });
643
- }
644
- catch (e) {
645
- // Non-fatal; continue with existing config
646
- MessageFormatter.warning("Could not reload config; continuing with current in-memory config", { prefix: "Controller" });
647
- }
648
- MessageFormatter.progress("Starting selective push (local config → Appwrite)...", { prefix: "Controller" });
649
- // Convert database selections to Models.Database format
650
- const selectedDatabases = [];
651
- for (const dbSelection of databaseSelections) {
652
- // Get the full database object from the controller
653
- const databases = await fetchAllDatabases(this.database);
654
- const database = databases.find(db => db.$id === dbSelection.databaseId);
655
- if (database) {
656
- selectedDatabases.push(database);
657
- MessageFormatter.info(`Selected database: ${database.name} (${database.$id})`, { prefix: "Controller" });
658
- // Log selected tables for this database
659
- if (dbSelection.tableIds && dbSelection.tableIds.length > 0) {
660
- MessageFormatter.info(` Tables: ${dbSelection.tableIds.join(', ')}`, { prefix: "Controller" });
661
- }
662
- }
663
- else {
664
- MessageFormatter.warning(`Database with ID ${dbSelection.databaseId} not found`, { prefix: "Controller" });
665
- }
666
- }
667
- if (selectedDatabases.length === 0) {
668
- MessageFormatter.warning("No valid databases selected for push", { prefix: "Controller" });
669
- return;
670
- }
671
- // Log bucket selections if provided
672
- if (bucketSelections && bucketSelections.length > 0) {
673
- MessageFormatter.info(`Selected ${bucketSelections.length} buckets:`, { prefix: "Controller" });
674
- for (const bucketSelection of bucketSelections) {
675
- const dbInfo = bucketSelection.databaseId ? ` (DB: ${bucketSelection.databaseId})` : '';
676
- MessageFormatter.info(` - ${bucketSelection.bucketName} (${bucketSelection.bucketId})${dbInfo}`, { prefix: "Controller" });
677
- }
678
- }
679
- // PUSH OPERATION: Push local configuration to Appwrite
680
- // Build database-specific collection mappings from databaseSelections
681
- const databaseCollectionsMap = new Map();
682
- // Get all collections/tables from config (they're at the root level, not nested in databases)
683
- const allCollections = this.config?.collections || this.config?.tables || [];
684
- // Create database-specific collection mapping to preserve relationships
685
- for (const dbSelection of databaseSelections) {
686
- const collectionsForDatabase = [];
687
- MessageFormatter.info(`Processing collections for database: ${dbSelection.databaseId}`, { prefix: "Controller" });
688
- // Filter collections that were selected for THIS specific database
689
- for (const collection of allCollections) {
690
- const collectionId = collection.$id || collection.id;
691
- // Check if this collection was selected for THIS database
692
- if (dbSelection.tableIds.includes(collectionId)) {
693
- collectionsForDatabase.push(collection);
694
- const source = collection._isFromTablesDir ? 'tables/' : 'collections/';
695
- MessageFormatter.info(` - Selected collection: ${collection.name || collectionId} for database ${dbSelection.databaseId} [source: ${source}]`, { prefix: "Controller" });
696
- }
697
- }
698
- databaseCollectionsMap.set(dbSelection.databaseId, collectionsForDatabase);
699
- MessageFormatter.info(`Database ${dbSelection.databaseId}: ${collectionsForDatabase.length} collections selected`, { prefix: "Controller" });
700
- }
701
- // Calculate total collections for logging
702
- const totalSelectedCollections = Array.from(databaseCollectionsMap.values())
703
- .reduce((total, collections) => total + collections.length, 0);
704
- MessageFormatter.info(`Pushing ${totalSelectedCollections} selected tables/collections to ${databaseCollectionsMap.size} databases`, { prefix: "Controller" });
705
- // Ensure databases exist
706
- await this.ensureDatabasesExist(selectedDatabases);
707
- await this.ensureDatabaseConfigBucketsExist(selectedDatabases);
708
- // Create/update collections with database-specific context
709
- for (const database of selectedDatabases) {
710
- const collectionsForThisDatabase = databaseCollectionsMap.get(database.$id) || [];
711
- if (collectionsForThisDatabase.length > 0) {
712
- MessageFormatter.info(`Pushing ${collectionsForThisDatabase.length} collections to database ${database.$id} (${database.name})`, { prefix: "Controller" });
713
- await this.createOrUpdateCollections(database, undefined, collectionsForThisDatabase);
714
- }
715
- else {
716
- MessageFormatter.info(`No collections selected for database ${database.$id} (${database.name})`, { prefix: "Controller" });
717
- }
718
- }
719
- MessageFormatter.success("Selective push completed successfully! Local config pushed to Appwrite.", { prefix: "Controller" });
720
- }
721
- async syncDb(databases = [], collections = []) {
722
- await this.init();
723
- if (!this.database) {
724
- MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
725
- return;
726
- }
727
- if (databases.length === 0) {
728
- const allDatabases = await fetchAllDatabases(this.database);
729
- databases = allDatabases;
730
- }
731
- // Ensure DBs exist
732
- await this.ensureDatabasesExist(databases);
733
- await this.ensureDatabaseConfigBucketsExist(databases);
734
- await this.createOrUpdateCollectionsForDatabases(databases, collections);
735
- }
736
- getAppwriteFolderPath() {
737
- return this.appwriteFolderPath;
738
- }
739
- async transferData(options) {
740
- let sourceClient = this.database;
741
- let targetClient;
742
- let sourceDatabases = [];
743
- let targetDatabases = [];
744
- if (!sourceClient) {
745
- MessageFormatter.error("Source database not initialized", undefined, { prefix: "Controller" });
746
- return;
747
- }
748
- if (options.isRemote) {
749
- if (!options.transferEndpoint ||
750
- !options.transferProject ||
751
- !options.transferKey) {
752
- MessageFormatter.error("Remote transfer options are missing", undefined, { prefix: "Controller" });
753
- return;
754
- }
755
- const remoteClient = getClient(options.transferEndpoint, options.transferProject, options.transferKey);
756
- targetClient = new Databases(remoteClient);
757
- sourceDatabases = await fetchAllDatabases(sourceClient);
758
- targetDatabases = await fetchAllDatabases(targetClient);
759
- }
760
- else {
761
- targetClient = sourceClient;
762
- sourceDatabases = targetDatabases = await fetchAllDatabases(sourceClient);
763
- }
764
- // Always perform database transfer if databases are specified
765
- if (options.fromDb && options.targetDb) {
766
- const fromDb = sourceDatabases.find((db) => db.$id === options.fromDb.$id);
767
- const targetDb = targetDatabases.find((db) => db.$id === options.targetDb.$id);
768
- if (!fromDb || !targetDb) {
769
- MessageFormatter.error("Source or target database not found", undefined, { prefix: "Controller" });
770
- return;
771
- }
772
- if (options.isRemote && targetClient) {
773
- await transferDatabaseLocalToRemote(sourceClient, options.transferEndpoint, options.transferProject, options.transferKey, fromDb.$id, targetDb.$id);
774
- }
775
- else {
776
- await transferDatabaseLocalToLocal(sourceClient, fromDb.$id, targetDb.$id);
777
- }
778
- }
779
- if (options.transferUsers) {
780
- if (!options.isRemote) {
781
- MessageFormatter.warning("User transfer is only supported for remote transfers. Skipping...", { prefix: "Controller" });
782
- }
783
- else if (!this.appwriteServer) {
784
- MessageFormatter.error("Appwrite server not initialized", undefined, { prefix: "Controller" });
785
- return;
786
- }
787
- else {
788
- MessageFormatter.progress("Starting user transfer...", { prefix: "Transfer" });
789
- const localUsers = new Users(this.appwriteServer);
790
- await transferUsersLocalToRemote(localUsers, options.transferEndpoint, options.transferProject, options.transferKey);
791
- MessageFormatter.success("User transfer completed", { prefix: "Transfer" });
792
- }
793
- }
794
- // Handle storage transfer
795
- if (this.storage && (options.sourceBucket || options.fromDb)) {
796
- const sourceBucketId = options.sourceBucket?.$id ||
797
- (options.fromDb &&
798
- this.config?.documentBucketId &&
799
- `${this.config.documentBucketId}_${options.fromDb.$id
800
- .toLowerCase()
801
- .trim()
802
- .replace(/\s+/g, "")}`);
803
- const targetBucketId = options.targetBucket?.$id ||
804
- (options.targetDb &&
805
- this.config?.documentBucketId &&
806
- `${this.config.documentBucketId}_${options.targetDb.$id
807
- .toLowerCase()
808
- .trim()
809
- .replace(/\s+/g, "")}`);
810
- if (sourceBucketId && targetBucketId) {
811
- MessageFormatter.progress(`Starting storage transfer from ${sourceBucketId} to ${targetBucketId}`, { prefix: "Transfer" });
812
- if (options.isRemote) {
813
- await transferStorageLocalToRemote(this.storage, options.transferEndpoint, options.transferProject, options.transferKey, sourceBucketId, targetBucketId);
814
- }
815
- else {
816
- await transferStorageLocalToLocal(this.storage, sourceBucketId, targetBucketId);
817
- }
818
- }
819
- }
820
- MessageFormatter.success("Transfer completed", { prefix: "Transfer" });
821
- }
822
- async updateFunctionSpecifications(functionId, specification) {
823
- await this.init();
824
- if (!this.appwriteServer)
825
- throw new Error("Appwrite server not initialized");
826
- MessageFormatter.progress(`Updating function specifications for ${functionId} to ${specification}`, { prefix: "Functions" });
827
- await updateFunctionSpecifications(this.appwriteServer, functionId, specification);
828
- MessageFormatter.success(`Successfully updated function specifications for ${functionId} to ${specification}`, { prefix: "Functions" });
829
- }
830
- /**
831
- * Validates the current configuration for collections/tables conflicts
832
- */
833
- async validateConfiguration(strictMode = false) {
834
- await this.init();
835
- if (!this.config) {
836
- throw new Error("Configuration not loaded");
837
- }
838
- MessageFormatter.progress("Validating configuration...", { prefix: "Validation" });
839
- const validation = strictMode
840
- ? validateWithStrictMode(this.config, strictMode)
841
- : validateCollectionsTablesConfig(this.config);
842
- reportValidationResults(validation, { verbose: true });
843
- if (validation.isValid) {
844
- MessageFormatter.success("Configuration validation passed", { prefix: "Validation" });
845
- }
846
- else {
847
- MessageFormatter.error(`Configuration validation failed with ${validation.errors.length} errors`, undefined, { prefix: "Validation" });
848
- }
849
- return validation;
850
- }
851
- /**
852
- * Get current session information for debugging/logging purposes
853
- * Delegates to ConfigManager for session info
854
- */
855
- async getSessionInfo() {
856
- const configManager = ConfigManager.getInstance();
857
- try {
858
- const authStatus = await configManager.getAuthStatus();
859
- return {
860
- hasSession: authStatus.hasValidSession,
861
- authMethod: authStatus.authMethod,
862
- email: authStatus.sessionInfo?.email,
863
- expiresAt: authStatus.sessionInfo?.expiresAt
864
- };
865
- }
866
- catch (error) {
867
- // If config not loaded, return empty status
868
- return {
869
- hasSession: false
870
- };
871
- }
872
- }
873
- }