appwrite-utils-cli 1.9.6 → 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 (426) 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 -44
  23. package/src/collections/indexes.ts +350 -352
  24. package/src/collections/methods.ts +714 -815
  25. package/src/collections/tableOperations.ts +57 -21
  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 +409 -0
  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 -405
  129. package/dist/adapters/DatabaseAdapter.d.ts +0 -242
  130. package/dist/adapters/DatabaseAdapter.js +0 -50
  131. package/dist/adapters/LegacyAdapter.d.ts +0 -50
  132. package/dist/adapters/LegacyAdapter.js +0 -612
  133. package/dist/adapters/TablesDBAdapter.d.ts +0 -45
  134. package/dist/adapters/TablesDBAdapter.js +0 -596
  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 -1364
  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 -734
  167. package/dist/collections/tableOperations.d.ts +0 -86
  168. package/dist/collections/tableOperations.js +0 -434
  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 -625
  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/indexManager.d.ts +0 -24
  298. package/dist/shared/indexManager.js +0 -151
  299. package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
  300. package/dist/shared/jsonSchemaGenerator.js +0 -290
  301. package/dist/shared/logging.d.ts +0 -61
  302. package/dist/shared/logging.js +0 -116
  303. package/dist/shared/messageFormatter.d.ts +0 -39
  304. package/dist/shared/messageFormatter.js +0 -162
  305. package/dist/shared/migrationHelpers.d.ts +0 -61
  306. package/dist/shared/migrationHelpers.js +0 -145
  307. package/dist/shared/operationLogger.d.ts +0 -10
  308. package/dist/shared/operationLogger.js +0 -12
  309. package/dist/shared/operationQueue.d.ts +0 -40
  310. package/dist/shared/operationQueue.js +0 -311
  311. package/dist/shared/operationsTable.d.ts +0 -26
  312. package/dist/shared/operationsTable.js +0 -286
  313. package/dist/shared/operationsTableSchema.d.ts +0 -48
  314. package/dist/shared/operationsTableSchema.js +0 -35
  315. package/dist/shared/progressManager.d.ts +0 -62
  316. package/dist/shared/progressManager.js +0 -215
  317. package/dist/shared/pydanticModelGenerator.d.ts +0 -17
  318. package/dist/shared/pydanticModelGenerator.js +0 -615
  319. package/dist/shared/relationshipExtractor.d.ts +0 -56
  320. package/dist/shared/relationshipExtractor.js +0 -138
  321. package/dist/shared/schemaGenerator.d.ts +0 -40
  322. package/dist/shared/schemaGenerator.js +0 -556
  323. package/dist/shared/selectionDialogs.d.ts +0 -214
  324. package/dist/shared/selectionDialogs.js +0 -544
  325. package/dist/storage/backupCompression.d.ts +0 -20
  326. package/dist/storage/backupCompression.js +0 -67
  327. package/dist/storage/methods.d.ts +0 -32
  328. package/dist/storage/methods.js +0 -472
  329. package/dist/storage/schemas.d.ts +0 -842
  330. package/dist/storage/schemas.js +0 -175
  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 -510
  378. package/src/adapters/DatabaseAdapter.ts +0 -318
  379. package/src/adapters/LegacyAdapter.ts +0 -841
  380. package/src/adapters/TablesDBAdapter.ts +0 -815
  381. package/src/config/ConfigManager.ts +0 -817
  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/indexManager.ts +0 -254
  405. package/src/shared/jsonSchemaGenerator.ts +0 -383
  406. package/src/shared/logging.ts +0 -149
  407. package/src/shared/messageFormatter.ts +0 -208
  408. package/src/shared/pydanticModelGenerator.ts +0 -618
  409. package/src/shared/schemaGenerator.ts +0 -644
  410. package/src/utils/ClientFactory.ts +0 -240
  411. package/src/utils/configDiscovery.ts +0 -557
  412. package/src/utils/constantsGenerator.ts +0 -369
  413. package/src/utils/dataConverters.ts +0 -159
  414. package/src/utils/directoryUtils.ts +0 -61
  415. package/src/utils/getClientFromConfig.ts +0 -257
  416. package/src/utils/helperFunctions.ts +0 -228
  417. package/src/utils/pathResolvers.ts +0 -81
  418. package/src/utils/projectConfig.ts +0 -340
  419. package/src/utils/retryFailedPromises.ts +0 -29
  420. package/src/utils/sessionAuth.ts +0 -230
  421. package/src/utils/typeGuards.ts +0 -65
  422. package/src/utils/validationRules.ts +0 -88
  423. package/src/utils/versionDetection.ts +0 -292
  424. package/src/utils/yamlConverter.ts +0 -542
  425. package/src/utils/yamlLoader.ts +0 -371
  426. package/tmp-sync-test/.appwrite/collections/TestCollection.yaml +0 -7
@@ -1,1238 +1,1236 @@
1
- import { mkdirSync, writeFileSync, existsSync } from "node:fs";
2
- import path from "node:path";
3
- import type { AppwriteConfig } from "appwrite-utils";
4
- import { findAppwriteConfig } from "./loadConfigs.js";
5
- import { loadYamlConfig } from "../config/yamlConfig.js";
6
- import { fetchServerVersion, isVersionAtLeast } from "./versionDetection.js";
7
- import { findYamlConfig } from "../config/yamlConfig.js";
8
- import { ID } from "node-appwrite";
9
- import { ulid } from "ulidx";
10
- import { generateYamlConfigTemplate } from "../config/yamlConfig.js";
11
- import { loadAppwriteProjectConfig, findAppwriteProjectConfig, getProjectDirectoryName, isTablesDBProject } from "./projectConfig.js";
12
- import { hasSessionAuth, getSessionAuth } from "./sessionAuth.js";
13
- import { MessageFormatter } from "../shared/messageFormatter.js";
14
-
15
- // Example base configuration using types from appwrite-utils
16
- const baseConfig: AppwriteConfig = {
17
- appwriteEndpoint: "https://cloud.appwrite.io/v1",
18
- appwriteProject: "YOUR_PROJECT_ID",
19
- appwriteKey: "YOUR_API_KEY",
20
- appwriteClient: null,
21
- apiMode: "auto", // Enable dual API support - auto-detect TablesDB vs legacy
22
- authMethod: "auto", // Default to auto-detect authentication method
23
- logging: {
24
- enabled: false,
25
- level: "info",
26
- console: false,
27
- },
28
- enableBackups: true,
29
- backupInterval: 3600,
30
- backupRetention: 30,
31
- enableBackupCleanup: true,
32
- enableMockData: false,
33
- documentBucketId: "documents",
34
- usersCollectionName: "Members",
35
- databases: [
36
- {
37
- $id: "main",
38
- name: "Main",
39
- bucket: {
40
- $id: "main_bucket",
41
- name: "Main Bucket",
42
- enabled: true,
43
- maximumFileSize: 30000000,
44
- allowedFileExtensions: [],
45
- encryption: true,
46
- antivirus: true,
47
- },
48
- },
49
- {
50
- $id: "staging",
51
- name: "Staging",
52
- bucket: {
53
- $id: "staging_bucket",
54
- name: "Staging Bucket",
55
- enabled: true,
56
- maximumFileSize: 30000000,
57
- allowedFileExtensions: [],
58
- encryption: true,
59
- antivirus: true,
60
- },
61
- },
62
- {
63
- $id: "dev",
64
- name: "Development",
65
- bucket: {
66
- $id: "dev_bucket",
67
- name: "Development Bucket",
68
- enabled: true,
69
- maximumFileSize: 30000000,
70
- allowedFileExtensions: [],
71
- encryption: true,
72
- antivirus: true,
73
- },
74
- },
75
- ],
76
- buckets: [
77
- {
78
- $id: "global_bucket",
79
- name: "Global Bucket",
80
- enabled: true,
81
- maximumFileSize: 30000000,
82
- allowedFileExtensions: [],
83
- encryption: true,
84
- antivirus: true,
85
- },
86
- ],
87
- };
88
-
89
- const collectionsConfig: { name: string; content: string }[] = [
90
- {
91
- name: "ExampleCollection",
92
- content: `import type { CollectionCreate } from "appwrite-utils";
93
-
94
- const ExampleCollection: Partial<CollectionCreate> = {
95
- name: 'ExampleCollection',
96
- $id: '${ulid()}',
97
- documentSecurity: false,
98
- enabled: true,
99
- $permissions: [
100
- { permission: 'read', target: 'any' },
101
- { permission: 'create', target: 'users' },
102
- { permission: 'update', target: 'users' },
103
- { permission: 'delete', target: 'users' }
104
- ],
105
- attributes: [
106
- { key: 'alterEgoName', type: 'string', size: 255, required: false },
107
- // Add more attributes here
108
- ],
109
- indexes: [
110
- { key: 'alterEgoName_search', type: 'fulltext', attributes: ['alterEgoName'] }
111
- ],
112
- importDefs: [
113
- // Define import definitions here
114
- ]
115
- };
116
-
117
- export default ExampleCollection;`,
118
- },
119
- // Add more collections here
120
- ];
121
-
122
- // Define our YAML files
123
- // Define our YAML files
124
- const configFileExample = `d`;
125
-
126
- export const customDefinitionsFile = `import type { ConverterFunctions, ValidationRules, AfterImportActions } from "appwrite-utils";
127
-
128
- export const customConverterFunctions: ConverterFunctions = {
129
- // Add your custom converter functions here
130
- }
131
- export const customValidationRules: ValidationRules = {
132
- // Add your custom validation rules here
133
- }
134
- export const customAfterImportActions: AfterImportActions = {
135
- // Add your custom after import actions here
136
- }`;
137
-
138
- export const createEmptyCollection = (collectionName: string) => {
139
- const currentDir = process.cwd();
140
-
141
- // Check for YAML config first (preferred)
142
- const yamlConfigPath = findYamlConfig(currentDir);
143
- const tsConfigPath = findAppwriteConfig(currentDir);
144
-
145
- let configDir: string;
146
- let isYamlProject = false;
147
-
148
- if (yamlConfigPath) {
149
- configDir = path.dirname(yamlConfigPath);
150
- isYamlProject = true;
151
- } else if (tsConfigPath) {
152
- configDir = path.dirname(tsConfigPath);
153
- isYamlProject = false;
154
- } else {
155
- // No config found - assume .appwrite directory and use YAML as default
156
- configDir = path.join(currentDir, ".appwrite");
157
- isYamlProject = true;
158
-
159
- // Create .appwrite directory if it doesn't exist
160
- if (!existsSync(configDir)) {
161
- mkdirSync(configDir, { recursive: true });
162
- }
163
- }
164
-
165
- const collectionsFolder = path.join(configDir, "collections");
166
- if (!existsSync(collectionsFolder)) {
167
- mkdirSync(collectionsFolder, { recursive: true });
168
- }
169
-
170
- if (isYamlProject) {
171
- // Create YAML collection
172
- const yamlCollection = `# yaml-language-server: $schema=../.yaml_schemas/collection.schema.json
173
- # Collection Definition: ${collectionName}
174
- name: ${collectionName}
175
- id: ${ulid()}
176
- documentSecurity: false
177
- enabled: true
178
- permissions:
179
- - permission: read
180
- target: any
181
- - permission: create
182
- target: users
183
- - permission: update
184
- target: users
185
- - permission: delete
186
- target: users
187
- attributes:
188
- # Add your attributes here
189
- # Example:
190
- # - key: title
191
- # type: string
192
- # size: 255
193
- # required: true
194
- # description: "The title of the item"
195
- indexes:
196
- # Add your indexes here
197
- # Example:
198
- # - key: title_search
199
- # type: fulltext
200
- # attributes:
201
- # - title
202
- importDefs: []
203
- `;
204
-
205
- const collectionFilePath = path.join(collectionsFolder, `${collectionName}.yaml`);
206
- writeFileSync(collectionFilePath, yamlCollection);
207
- MessageFormatter.success(`Created YAML collection: ${collectionFilePath}`, { prefix: "Setup" });
208
- } else {
209
- // Create TypeScript collection
210
- const emptyCollection = `import type { CollectionCreate } from "appwrite-utils";
211
-
212
- const ${collectionName}: Partial<CollectionCreate> = {
213
- $id: '${ulid()}',
214
- documentSecurity: false,
215
- enabled: true,
216
- name: '${collectionName}',
217
- $permissions: [
218
- { permission: 'read', target: 'any' },
219
- { permission: 'create', target: 'users' },
220
- { permission: 'update', target: 'users' },
221
- { permission: 'delete', target: 'users' }
222
- ],
223
- attributes: [
224
- // Add more attributes here
225
- ],
226
- indexes: [
227
- // Add more indexes here
228
- ],
229
- };
230
-
231
- export default ${collectionName};`;
232
-
233
- const collectionFilePath = path.join(collectionsFolder, `${collectionName}.ts`);
234
- writeFileSync(collectionFilePath, emptyCollection);
235
- MessageFormatter.success(`Created TypeScript collection: ${collectionFilePath}`, { prefix: "Setup" });
236
- }
237
- };
238
-
239
- export const generateYamlConfig = (currentDir?: string, useAppwriteDir: boolean = true) => {
240
- const basePath = currentDir || process.cwd();
241
- const configDir = useAppwriteDir ? path.join(basePath, ".appwrite") : basePath;
242
-
243
- if (!existsSync(configDir)) {
244
- mkdirSync(configDir, { recursive: true });
245
- }
246
-
247
- const configPath = path.join(configDir, "config.yaml");
248
- generateYamlConfigTemplate(configPath);
249
-
250
- MessageFormatter.success(`Generated YAML config template at: ${configPath}`, { prefix: "Setup" });
251
- MessageFormatter.info("Please update the configuration with your Appwrite project details.", { prefix: "Setup" });
252
-
253
- return configPath;
254
- };
255
-
256
- export const setupDirsFiles = async (
257
- example: boolean = false,
258
- currentDir?: string,
259
- useYaml: boolean = true
260
- ) => {
261
- const basePath = currentDir || process.cwd();
262
-
263
- // Create .appwrite folder directly in project root
264
- const appwriteFolder = path.join(basePath, ".appwrite");
265
- const appwriteConfigFile = path.join(appwriteFolder, "appwriteConfig.ts");
266
- const appwriteCustomDefsFile = path.join(
267
- appwriteFolder,
268
- "customDefinitions.ts"
269
- );
270
- const appwriteSchemaFolder = path.join(appwriteFolder, "schemas");
271
- const appwriteYamlSchemaFolder = path.join(appwriteFolder, ".yaml_schemas");
272
- const appwriteDataFolder = path.join(appwriteFolder, "importData");
273
- // Enhanced version detection with multiple sources
274
- let useTables = false;
275
- let detectionSource = "default";
276
-
277
- try {
278
- // Priority 1: Check for existing appwrite.json project config
279
- const projectConfigPath = findAppwriteProjectConfig(basePath);
280
- if (projectConfigPath) {
281
- const projectConfig = loadAppwriteProjectConfig(projectConfigPath);
282
- if (projectConfig) {
283
- useTables = isTablesDBProject(projectConfig);
284
- detectionSource = "appwrite.json";
285
- MessageFormatter.info(`Detected ${useTables ? 'TablesDB' : 'Collections'} project from ${projectConfigPath}`, { prefix: "Setup" });
286
- }
287
- }
288
-
289
- // Priority 2: Try reading existing YAML config for version detection
290
- if (!useTables && detectionSource === "default") {
291
- const yamlPath = findYamlConfig(basePath);
292
- if (yamlPath) {
293
- const cfg = await loadYamlConfig(yamlPath);
294
- if (cfg) {
295
- // Try session auth first, then API key for version detection
296
- let endpoint = cfg.appwriteEndpoint;
297
- let projectId = cfg.appwriteProject;
298
-
299
- if (hasSessionAuth(endpoint, projectId)) {
300
- MessageFormatter.info("Using session authentication for version detection", { prefix: "Setup" });
301
- }
302
-
303
- const ver = await fetchServerVersion(endpoint);
304
- if (isVersionAtLeast(ver || undefined, '1.8.0')) {
305
- useTables = true;
306
- detectionSource = "server-version";
307
- MessageFormatter.info(`Detected TablesDB support (Appwrite ${ver})`, { prefix: "Setup" });
308
- } else {
309
- MessageFormatter.info(`Using Collections API (Appwrite ${ver || 'unknown'})`, { prefix: "Setup" });
310
- }
311
- }
312
- }
313
- }
314
- } catch (error) {
315
- MessageFormatter.warning(`Version detection failed, defaulting to Collections API: ${error instanceof Error ? error.message : String(error)}`, { prefix: "Setup" });
316
- }
317
-
318
- const targetFolderName = useTables ? "tables" : "collections";
319
- const collectionsFolder = path.join(appwriteFolder, targetFolderName);
320
-
321
- // Create directory structure
322
- if (!existsSync(appwriteFolder)) {
323
- mkdirSync(appwriteFolder, { recursive: true });
324
- }
325
-
326
- if (!existsSync(collectionsFolder)) {
327
- mkdirSync(collectionsFolder, { recursive: true });
328
- }
329
-
330
- // Handle configuration file creation - YAML is now default
331
- if (useYaml) {
332
- // Generate YAML config in .appwrite directory
333
- const configPath = path.join(appwriteFolder, "config.yaml");
334
- generateYamlConfigTemplate(configPath);
335
- } else if (!existsSync(appwriteConfigFile)) {
336
- if (example) {
337
- writeFileSync(appwriteConfigFile, configFileExample);
338
- } else {
339
- const baseConfigContent = `import { type AppwriteConfig } from "appwrite-utils";
340
-
341
- const appwriteConfig: AppwriteConfig = ${JSON.stringify(baseConfig, null, 2)};
342
-
343
- export default appwriteConfig;
344
- `;
345
- writeFileSync(appwriteConfigFile, baseConfigContent);
346
- }
347
- }
348
-
349
- // Create TypeScript files for each collection only if not using YAML
350
- if (!useYaml) {
351
- collectionsConfig.forEach((collection) => {
352
- const collectionFilePath = path.join(
353
- collectionsFolder,
354
- `${collection.name}.ts`
355
- );
356
- writeFileSync(collectionFilePath, collection.content);
357
- });
358
- }
359
-
360
- // Create YAML collection/table example if using YAML config
361
- if (useYaml) {
362
- const terminology = useTables
363
- ? {
364
- container: "table",
365
- fields: "columns",
366
- security: "rowSecurity",
367
- schemaRef: "table.schema.json",
368
- containerName: "Table",
369
- fieldName: "Column"
370
- }
371
- : {
372
- container: "collection",
373
- fields: "attributes",
374
- security: "documentSecurity",
375
- schemaRef: "collection.schema.json",
376
- containerName: "Collection",
377
- fieldName: "Attribute"
378
- };
379
-
380
- const yamlExample = `# yaml-language-server: $schema=../.yaml_schemas/${terminology.schemaRef}
381
- # Example ${terminology.containerName} Definition
382
- name: Example${terminology.containerName}
383
- id: example_${terminology.container}_${Date.now()}
384
- ${terminology.security}: false
385
- enabled: true
386
- permissions:
387
- - permission: read
388
- target: any
389
- - permission: create
390
- target: users
391
- - permission: update
392
- target: users
393
- - permission: delete
394
- target: users
395
- ${terminology.fields}:
396
- - key: title
397
- type: string
398
- size: 255
399
- required: true
400
- description: "The title of the item"
401
- - key: description
402
- type: string
403
- size: 1000
404
- required: false
405
- description: "A longer description"
406
- - key: isActive
407
- type: boolean
408
- required: false
409
- default: true${useTables ? `
410
- - key: uniqueCode
411
- type: string
412
- size: 50
413
- required: false
414
- unique: true
415
- description: "Unique identifier code (TablesDB feature)"` : ''}
416
- indexes:
417
- - key: title_search
418
- type: fulltext
419
- attributes:
420
- - title
421
- importDefs: []
422
- `;
423
- const yamlExamplePath = path.join(collectionsFolder, `Example${terminology.containerName}.yaml`);
424
- writeFileSync(yamlExamplePath, yamlExample);
425
-
426
- MessageFormatter.info(`Created example ${terminology.container} definition with ${terminology.fields} terminology`, { prefix: "Setup" });
427
-
428
- // Create JSON schema for collection/table definitions
429
- const containerJsonSchema = useTables ? {
430
- "$schema": "https://json-schema.org/draft/2020-12/schema",
431
- "$id": "https://appwrite-utils.dev/schemas/table.schema.json",
432
- "title": "Appwrite Table Definition",
433
- "description": "Schema for defining Appwrite tables in YAML (TablesDB API)",
434
- "type": "object",
435
- "properties": {
436
- "name": {
437
- "type": "string",
438
- "description": "The name of the table"
439
- },
440
- "id": {
441
- "type": "string",
442
- "description": "The ID of the table (optional, auto-generated if not provided)",
443
- "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
444
- },
445
- "rowSecurity": {
446
- "type": "boolean",
447
- "default": false,
448
- "description": "Enable row-level permissions"
449
- },
450
- "enabled": {
451
- "type": "boolean",
452
- "default": true,
453
- "description": "Whether the table is enabled"
454
- },
455
- "permissions": {
456
- "type": "array",
457
- "description": "Table-level permissions",
458
- "items": {
459
- "type": "object",
460
- "properties": {
461
- "permission": {
462
- "type": "string",
463
- "enum": ["read", "create", "update", "delete"],
464
- "description": "The permission type"
465
- },
466
- "target": {
467
- "type": "string",
468
- "description": "Permission target (e.g., 'any', 'users', 'users/verified', 'label:admin')"
469
- }
470
- },
471
- "required": ["permission", "target"],
472
- "additionalProperties": false
473
- }
474
- },
475
- "columns": {
476
- "type": "array",
477
- "description": "Table columns (fields)",
478
- "items": {
479
- "type": "object",
480
- "properties": {
481
- "key": {
482
- "type": "string",
483
- "description": "Column name",
484
- "pattern": "^[a-zA-Z][a-zA-Z0-9]*$"
485
- },
486
- "type": {
487
- "type": "string",
488
- "enum": ["string", "integer", "double", "boolean", "datetime", "email", "ip", "url", "enum", "relationship"],
489
- "description": "Column data type"
490
- },
491
- "size": {
492
- "type": "number",
493
- "description": "Maximum size for string columns",
494
- "minimum": 1,
495
- "maximum": 1073741824
496
- },
497
- "required": {
498
- "type": "boolean",
499
- "default": false,
500
- "description": "Whether the column is required"
501
- },
502
- "array": {
503
- "type": "boolean",
504
- "default": false,
505
- "description": "Whether the column is an array"
506
- },
507
- "unique": {
508
- "type": "boolean",
509
- "default": false,
510
- "description": "Whether the column values must be unique (TablesDB feature)"
511
- },
512
- "default": {
513
- "description": "Default value for the column"
514
- },
515
- "description": {
516
- "type": "string",
517
- "description": "Column description"
518
- },
519
- "encrypt": {
520
- "type": "boolean",
521
- "description": "Whether the column should be encrypted"
522
- },
523
- "format": {
524
- "type": "string",
525
- "description": "Format for string columns"
526
- },
527
- "min": {
528
- "type": "number",
529
- "description": "Minimum value for numeric columns"
530
- },
531
- "max": {
532
- "type": "number",
533
- "description": "Maximum value for numeric columns"
534
- },
535
- "elements": {
536
- "type": "array",
537
- "items": {
538
- "type": "string"
539
- },
540
- "description": "Allowed values for enum columns"
541
- },
542
- "relatedCollection": {
543
- "type": "string",
544
- "description": "Related table name for relationship columns"
545
- },
546
- "relationType": {
547
- "type": "string",
548
- "enum": ["oneToOne", "oneToMany", "manyToOne", "manyToMany"],
549
- "description": "Type of relationship"
550
- },
551
- "twoWay": {
552
- "type": "boolean",
553
- "description": "Whether the relationship is bidirectional"
554
- },
555
- "twoWayKey": {
556
- "type": "string",
557
- "description": "Key name for the reverse relationship"
558
- },
559
- "onDelete": {
560
- "type": "string",
561
- "enum": ["cascade", "restrict", "setNull"],
562
- "description": "Action to take when related row is deleted"
563
- },
564
- "side": {
565
- "type": "string",
566
- "enum": ["parent", "child"],
567
- "description": "Side of the relationship"
568
- }
569
- },
570
- "required": ["key", "type"],
571
- "additionalProperties": false,
572
- "allOf": [
573
- {
574
- "if": {
575
- "properties": { "type": { "const": "enum" } }
576
- },
577
- "then": {
578
- "required": ["elements"]
579
- }
580
- },
581
- {
582
- "if": {
583
- "properties": { "type": { "const": "relationship" } }
584
- },
585
- "then": {
586
- "required": ["relatedCollection", "relationType"]
587
- }
588
- }
589
- ]
590
- }
591
- },
592
- "indexes": {
593
- "type": "array",
594
- "description": "Database indexes for the table",
595
- "items": {
596
- "type": "object",
597
- "properties": {
598
- "key": {
599
- "type": "string",
600
- "description": "Index name"
601
- },
602
- "type": {
603
- "type": "string",
604
- "enum": ["key", "fulltext", "unique"],
605
- "description": "Index type"
606
- },
607
- "attributes": {
608
- "type": "array",
609
- "items": {
610
- "type": "string"
611
- },
612
- "description": "Columns to index",
613
- "minItems": 1
614
- },
615
- "orders": {
616
- "type": "array",
617
- "items": {
618
- "type": "string",
619
- "enum": ["ASC", "DESC"]
620
- },
621
- "description": "Sort order for each column"
622
- }
623
- },
624
- "required": ["key", "type", "attributes"],
625
- "additionalProperties": false
626
- }
627
- },
628
- "importDefs": {
629
- "type": "array",
630
- "description": "Import definitions for data migration",
631
- "default": []
632
- }
633
- },
634
- "required": ["name"],
635
- "additionalProperties": false
636
- } : {
637
- "$schema": "https://json-schema.org/draft/2020-12/schema",
638
- "$id": "https://appwrite-utils.dev/schemas/collection.schema.json",
639
- "title": "Appwrite Collection Definition",
640
- "description": "Schema for defining Appwrite collections in YAML",
641
- "type": "object",
642
- "properties": {
643
- "name": {
644
- "type": "string",
645
- "description": "The name of the collection"
646
- },
647
- "id": {
648
- "type": "string",
649
- "description": "The ID of the collection (optional, auto-generated if not provided)",
650
- "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
651
- },
652
- "documentSecurity": {
653
- "type": "boolean",
654
- "default": false,
655
- "description": "Enable document-level permissions"
656
- },
657
- "enabled": {
658
- "type": "boolean",
659
- "default": true,
660
- "description": "Whether the collection is enabled"
661
- },
662
- "permissions": {
663
- "type": "array",
664
- "description": "Collection-level permissions",
665
- "items": {
666
- "type": "object",
667
- "properties": {
668
- "permission": {
669
- "type": "string",
670
- "enum": ["read", "create", "update", "delete"],
671
- "description": "The permission type"
672
- },
673
- "target": {
674
- "type": "string",
675
- "description": "Permission target (e.g., 'any', 'users', 'users/verified', 'label:admin')"
676
- }
677
- },
678
- "required": ["permission", "target"],
679
- "additionalProperties": false
680
- }
681
- },
682
- "attributes": {
683
- "type": "array",
684
- "description": "Collection attributes (fields)",
685
- "items": {
686
- "type": "object",
687
- "properties": {
688
- "key": {
689
- "type": "string",
690
- "description": "Attribute name",
691
- "pattern": "^[a-zA-Z][a-zA-Z0-9]*$"
692
- },
693
- "type": {
694
- "type": "string",
695
- "enum": ["string", "integer", "double", "boolean", "datetime", "email", "ip", "url", "enum", "relationship"],
696
- "description": "Attribute data type"
697
- },
698
- "size": {
699
- "type": "number",
700
- "description": "Maximum size for string attributes",
701
- "minimum": 1,
702
- "maximum": 1073741824
703
- },
704
- "required": {
705
- "type": "boolean",
706
- "default": false,
707
- "description": "Whether the attribute is required"
708
- },
709
- "array": {
710
- "type": "boolean",
711
- "default": false,
712
- "description": "Whether the attribute is an array"
713
- },
714
- "default": {
715
- "description": "Default value for the attribute"
716
- },
717
- "description": {
718
- "type": "string",
719
- "description": "Attribute description"
720
- },
721
- "encrypt": {
722
- "type": "boolean",
723
- "description": "Whether the attribute should be encrypted"
724
- },
725
- "format": {
726
- "type": "string",
727
- "description": "Format for string attributes"
728
- },
729
- "min": {
730
- "type": "number",
731
- "description": "Minimum value for numeric attributes"
732
- },
733
- "max": {
734
- "type": "number",
735
- "description": "Maximum value for numeric attributes"
736
- },
737
- "elements": {
738
- "type": "array",
739
- "items": {
740
- "type": "string"
741
- },
742
- "description": "Allowed values for enum attributes"
743
- },
744
- "relatedCollection": {
745
- "type": "string",
746
- "description": "Related collection name for relationship attributes"
747
- },
748
- "relationType": {
749
- "type": "string",
750
- "enum": ["oneToOne", "oneToMany", "manyToOne", "manyToMany"],
751
- "description": "Type of relationship"
752
- },
753
- "twoWay": {
754
- "type": "boolean",
755
- "description": "Whether the relationship is bidirectional"
756
- },
757
- "twoWayKey": {
758
- "type": "string",
759
- "description": "Key name for the reverse relationship"
760
- },
761
- "onDelete": {
762
- "type": "string",
763
- "enum": ["cascade", "restrict", "setNull"],
764
- "description": "Action to take when related document is deleted"
765
- },
766
- "side": {
767
- "type": "string",
768
- "enum": ["parent", "child"],
769
- "description": "Side of the relationship"
770
- }
771
- },
772
- "required": ["key", "type"],
773
- "additionalProperties": false,
774
- "allOf": [
775
- {
776
- "if": {
777
- "properties": { "type": { "const": "enum" } }
778
- },
779
- "then": {
780
- "required": ["elements"]
781
- }
782
- },
783
- {
784
- "if": {
785
- "properties": { "type": { "const": "relationship" } }
786
- },
787
- "then": {
788
- "required": ["relatedCollection", "relationType"]
789
- }
790
- }
791
- ]
792
- }
793
- },
794
- "indexes": {
795
- "type": "array",
796
- "description": "Database indexes for the collection",
797
- "items": {
798
- "type": "object",
799
- "properties": {
800
- "key": {
801
- "type": "string",
802
- "description": "Index name"
803
- },
804
- "type": {
805
- "type": "string",
806
- "enum": ["key", "fulltext", "unique"],
807
- "description": "Index type"
808
- },
809
- "attributes": {
810
- "type": "array",
811
- "items": {
812
- "type": "string"
813
- },
814
- "description": "Attributes to index",
815
- "minItems": 1
816
- },
817
- "orders": {
818
- "type": "array",
819
- "items": {
820
- "type": "string",
821
- "enum": ["ASC", "DESC"]
822
- },
823
- "description": "Sort order for each attribute"
824
- }
825
- },
826
- "required": ["key", "type", "attributes"],
827
- "additionalProperties": false
828
- }
829
- },
830
- "importDefs": {
831
- "type": "array",
832
- "description": "Import definitions for data migration",
833
- "default": []
834
- }
835
- },
836
- "required": ["name"],
837
- "additionalProperties": false
838
- };
839
-
840
- // Ensure YAML schemas directory exists before writing schema
841
- if (!existsSync(appwriteYamlSchemaFolder)) {
842
- mkdirSync(appwriteYamlSchemaFolder, { recursive: true });
843
- }
844
-
845
- const schemaFileName = useTables ? "table.schema.json" : "collection.schema.json";
846
- const containerSchemaPath = path.join(appwriteYamlSchemaFolder, schemaFileName);
847
- writeFileSync(containerSchemaPath, JSON.stringify(containerJsonSchema, null, 2));
848
-
849
- // Create JSON schema for appwriteConfig.yaml
850
- const configJsonSchema = {
851
- "$schema": "https://json-schema.org/draft/2020-12/schema",
852
- "$id": "https://appwrite-utils.dev/schemas/appwrite-config.schema.json",
853
- "title": "Appwrite Configuration",
854
- "description": "Schema for Appwrite project configuration in YAML",
855
- "type": "object",
856
- "properties": {
857
- "appwrite": {
858
- "type": "object",
859
- "description": "Appwrite connection settings",
860
- "properties": {
861
- "endpoint": {
862
- "type": "string",
863
- "default": "https://cloud.appwrite.io/v1",
864
- "description": "Appwrite server endpoint URL"
865
- },
866
- "project": {
867
- "type": "string",
868
- "description": "Appwrite project ID"
869
- },
870
- "key": {
871
- "type": "string",
872
- "description": "Appwrite API key with appropriate permissions"
873
- }
874
- },
875
- "required": ["project", "key"],
876
- "additionalProperties": false
877
- },
878
- "logging": {
879
- "type": "object",
880
- "description": "Logging configuration",
881
- "properties": {
882
- "enabled": {
883
- "type": "boolean",
884
- "default": false,
885
- "description": "Enable file logging"
886
- },
887
- "level": {
888
- "type": "string",
889
- "enum": ["error", "warn", "info", "debug"],
890
- "default": "info",
891
- "description": "Logging level"
892
- },
893
- "directory": {
894
- "type": "string",
895
- "description": "Custom log directory path (optional)"
896
- },
897
- "console": {
898
- "type": "boolean",
899
- "default": false,
900
- "description": "Enable console logging"
901
- }
902
- },
903
- "additionalProperties": false
904
- },
905
- "backups": {
906
- "type": "object",
907
- "description": "Backup configuration",
908
- "properties": {
909
- "enabled": {
910
- "type": "boolean",
911
- "default": true,
912
- "description": "Enable automatic backups"
913
- },
914
- "interval": {
915
- "type": "number",
916
- "default": 3600,
917
- "description": "Backup interval in seconds"
918
- },
919
- "retention": {
920
- "type": "number",
921
- "default": 30,
922
- "description": "Backup retention in days"
923
- },
924
- "cleanup": {
925
- "type": "boolean",
926
- "default": true,
927
- "description": "Enable automatic backup cleanup"
928
- }
929
- },
930
- "additionalProperties": false
931
- },
932
- "data": {
933
- "type": "object",
934
- "description": "Data management settings",
935
- "properties": {
936
- "enableMockData": {
937
- "type": "boolean",
938
- "default": false,
939
- "description": "Enable mock data generation"
940
- },
941
- "documentBucketId": {
942
- "type": "string",
943
- "default": "documents",
944
- "description": "Default bucket ID for document attachments"
945
- },
946
- "usersCollectionName": {
947
- "type": "string",
948
- "default": "Members",
949
- "description": "Name of the users/members collection"
950
- },
951
- "importDirectory": {
952
- "type": "string",
953
- "default": "importData",
954
- "description": "Directory containing import data files"
955
- }
956
- },
957
- "additionalProperties": false
958
- },
959
- "schemas": {
960
- "type": "object",
961
- "description": "Schema generation settings",
962
- "properties": {
963
- "outputDirectory": {
964
- "type": "string",
965
- "default": "schemas",
966
- "description": "Directory where generated schemas are saved"
967
- },
968
- "yamlSchemaDirectory": {
969
- "type": "string",
970
- "default": ".yaml_schemas",
971
- "description": "Directory containing YAML validation schemas"
972
- }
973
- },
974
- "additionalProperties": false
975
- },
976
- "migrations": {
977
- "type": "object",
978
- "description": "Migration settings",
979
- "properties": {
980
- "enabled": {
981
- "type": "boolean",
982
- "default": true,
983
- "description": "Enable migration tracking database"
984
- }
985
- },
986
- "additionalProperties": false
987
- },
988
- "databases": {
989
- "type": "array",
990
- "description": "Database configurations",
991
- "items": {
992
- "type": "object",
993
- "properties": {
994
- "id": {
995
- "type": "string",
996
- "description": "Database ID",
997
- "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
998
- },
999
- "name": {
1000
- "type": "string",
1001
- "description": "Database display name"
1002
- },
1003
- "bucket": {
1004
- "type": "object",
1005
- "description": "Associated storage bucket",
1006
- "properties": {
1007
- "id": {
1008
- "type": "string",
1009
- "description": "Bucket ID"
1010
- },
1011
- "name": {
1012
- "type": "string",
1013
- "description": "Bucket display name"
1014
- },
1015
- "permissions": {
1016
- "type": "array",
1017
- "items": {
1018
- "type": "string"
1019
- },
1020
- "description": "Bucket permissions"
1021
- },
1022
- "fileSecurity": {
1023
- "type": "boolean",
1024
- "description": "Enable file-level security"
1025
- },
1026
- "enabled": {
1027
- "type": "boolean",
1028
- "default": true,
1029
- "description": "Enable the bucket"
1030
- },
1031
- "maximumFileSize": {
1032
- "type": "number",
1033
- "default": 30000000,
1034
- "description": "Maximum file size in bytes"
1035
- },
1036
- "allowedFileExtensions": {
1037
- "type": "array",
1038
- "items": {
1039
- "type": "string"
1040
- },
1041
- "description": "Allowed file extensions (empty = all allowed)"
1042
- },
1043
- "compression": {
1044
- "type": "string",
1045
- "enum": ["none", "gzip", "zstd"],
1046
- "default": "none",
1047
- "description": "Compression algorithm"
1048
- },
1049
- "encryption": {
1050
- "type": "boolean",
1051
- "default": false,
1052
- "description": "Enable file encryption"
1053
- },
1054
- "antivirus": {
1055
- "type": "boolean",
1056
- "default": false,
1057
- "description": "Enable antivirus scanning"
1058
- }
1059
- },
1060
- "required": ["id", "name"],
1061
- "additionalProperties": false
1062
- }
1063
- },
1064
- "required": ["id", "name"],
1065
- "additionalProperties": false
1066
- }
1067
- },
1068
- "buckets": {
1069
- "type": "array",
1070
- "description": "Global storage buckets",
1071
- "items": {
1072
- "type": "object",
1073
- "properties": {
1074
- "id": {
1075
- "type": "string",
1076
- "description": "Bucket ID"
1077
- },
1078
- "name": {
1079
- "type": "string",
1080
- "description": "Bucket display name"
1081
- },
1082
- "permissions": {
1083
- "type": "array",
1084
- "items": {
1085
- "type": "string"
1086
- },
1087
- "description": "Bucket permissions"
1088
- },
1089
- "fileSecurity": {
1090
- "type": "boolean",
1091
- "description": "Enable file-level security"
1092
- },
1093
- "enabled": {
1094
- "type": "boolean",
1095
- "default": true,
1096
- "description": "Enable the bucket"
1097
- },
1098
- "maximumFileSize": {
1099
- "type": "number",
1100
- "default": 30000000,
1101
- "description": "Maximum file size in bytes"
1102
- },
1103
- "allowedFileExtensions": {
1104
- "type": "array",
1105
- "items": {
1106
- "type": "string"
1107
- },
1108
- "description": "Allowed file extensions (empty = all allowed)"
1109
- },
1110
- "compression": {
1111
- "type": "string",
1112
- "enum": ["none", "gzip", "zstd"],
1113
- "default": "none",
1114
- "description": "Compression algorithm"
1115
- },
1116
- "encryption": {
1117
- "type": "boolean",
1118
- "default": false,
1119
- "description": "Enable file encryption"
1120
- },
1121
- "antivirus": {
1122
- "type": "boolean",
1123
- "default": false,
1124
- "description": "Enable antivirus scanning"
1125
- }
1126
- },
1127
- "required": ["id", "name"],
1128
- "additionalProperties": false
1129
- }
1130
- },
1131
- "functions": {
1132
- "type": "array",
1133
- "description": "Appwrite Functions",
1134
- "items": {
1135
- "type": "object",
1136
- "properties": {
1137
- "id": {
1138
- "type": "string",
1139
- "description": "Function ID"
1140
- },
1141
- "name": {
1142
- "type": "string",
1143
- "description": "Function name"
1144
- },
1145
- "runtime": {
1146
- "type": "string",
1147
- "description": "Runtime environment"
1148
- },
1149
- "execute": {
1150
- "type": "array",
1151
- "items": {
1152
- "type": "string"
1153
- },
1154
- "description": "Execution permissions"
1155
- },
1156
- "events": {
1157
- "type": "array",
1158
- "items": {
1159
- "type": "string"
1160
- },
1161
- "description": "Event triggers"
1162
- },
1163
- "schedule": {
1164
- "type": "string",
1165
- "description": "Cron schedule"
1166
- },
1167
- "timeout": {
1168
- "type": "number",
1169
- "default": 15,
1170
- "description": "Execution timeout in seconds"
1171
- },
1172
- "enabled": {
1173
- "type": "boolean",
1174
- "default": true,
1175
- "description": "Enable the function"
1176
- },
1177
- "logging": {
1178
- "type": "boolean",
1179
- "default": true,
1180
- "description": "Enable function logging"
1181
- },
1182
- "entrypoint": {
1183
- "type": "string",
1184
- "description": "Function entrypoint file"
1185
- },
1186
- "commands": {
1187
- "type": "string",
1188
- "description": "Build commands"
1189
- }
1190
- },
1191
- "required": ["id", "name", "runtime"],
1192
- "additionalProperties": false
1193
- }
1194
- }
1195
- },
1196
- "required": ["appwrite"],
1197
- "additionalProperties": false
1198
- };
1199
-
1200
- const configSchemaPath = path.join(appwriteYamlSchemaFolder, "appwrite-config.schema.json");
1201
- writeFileSync(configSchemaPath, JSON.stringify(configJsonSchema, null, 2));
1202
- }
1203
-
1204
- if (!existsSync(appwriteSchemaFolder)) {
1205
- mkdirSync(appwriteSchemaFolder, { recursive: true });
1206
- }
1207
-
1208
- if (!existsSync(appwriteDataFolder)) {
1209
- mkdirSync(appwriteDataFolder, { recursive: true });
1210
- }
1211
-
1212
- // Remove the nested .appwrite folder creation since we're using .appwrite as the main folder
1213
-
1214
- const configType = useYaml ? "YAML" : "TypeScript";
1215
- const terminology = useTables ? "tables" : "collections";
1216
- const containerType = useTables ? "TablesDB" : "Collections";
1217
-
1218
- MessageFormatter.success(`Created ${configType} config and setup files/directories in .appwrite/ folder.`, { prefix: "Setup" });
1219
- MessageFormatter.info(`Project configured for ${containerType} API (${detectionSource} detection)`, { prefix: "Setup" });
1220
-
1221
- if (useYaml) {
1222
- MessageFormatter.info("You can now configure your project in .appwrite/config.yaml", { prefix: "Setup" });
1223
- MessageFormatter.info(`${useTables ? 'Tables' : 'Collections'} can be defined in .appwrite/${terminology}/ as .ts or .yaml files`, { prefix: "Setup" });
1224
- MessageFormatter.info("Schemas will be generated in .appwrite/schemas/", { prefix: "Setup" });
1225
- MessageFormatter.info("Import data can be placed in .appwrite/importData/", { prefix: "Setup" });
1226
- if (useTables) {
1227
- MessageFormatter.info("TablesDB features: unique constraints, enhanced performance, row-level security", { prefix: "Setup" });
1228
- }
1229
- } else {
1230
- MessageFormatter.info("You can now configure logging in your .appwrite/appwriteConfig.ts file:", { prefix: "Setup" });
1231
- MessageFormatter.info(" logging: {", { prefix: "Setup" });
1232
- MessageFormatter.info(" enabled: true,", { prefix: "Setup" });
1233
- MessageFormatter.info(" level: 'info',", { prefix: "Setup" });
1234
- MessageFormatter.info(" console: true,", { prefix: "Setup" });
1235
- MessageFormatter.info(" logDirectory: './logs' // optional custom directory", { prefix: "Setup" });
1236
- MessageFormatter.info(" }", { prefix: "Setup" });
1237
- }
1238
- };
1
+ import { mkdirSync, writeFileSync, existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import type { AppwriteConfig } from "appwrite-utils";
4
+ import { findAppwriteConfig } from "./loadConfigs.js";
5
+ import { loadYamlConfig, findYamlConfig, generateYamlConfigTemplate } from "appwrite-utils-helpers";
6
+ import { fetchServerVersion, isVersionAtLeast } from 'appwrite-utils-helpers';
7
+ import { ID } from "node-appwrite";
8
+ import { ulid } from "ulidx";
9
+ import { loadAppwriteProjectConfig, findAppwriteProjectConfig, getProjectDirectoryName, isTablesDBProject } from 'appwrite-utils-helpers';
10
+ import { hasSessionAuth, getSessionAuth } from 'appwrite-utils-helpers';
11
+ import { MessageFormatter } from "appwrite-utils-helpers";
12
+
13
+ // Example base configuration using types from appwrite-utils
14
+ const baseConfig: AppwriteConfig = {
15
+ appwriteEndpoint: "https://cloud.appwrite.io/v1",
16
+ appwriteProject: "YOUR_PROJECT_ID",
17
+ appwriteKey: "YOUR_API_KEY",
18
+ appwriteClient: null,
19
+ apiMode: "auto", // Enable dual API support - auto-detect TablesDB vs legacy
20
+ authMethod: "auto", // Default to auto-detect authentication method
21
+ logging: {
22
+ enabled: false,
23
+ level: "info",
24
+ console: false,
25
+ },
26
+ enableBackups: true,
27
+ backupInterval: 3600,
28
+ backupRetention: 30,
29
+ enableBackupCleanup: true,
30
+ enableMockData: false,
31
+ documentBucketId: "documents",
32
+ usersCollectionName: "Members",
33
+ databases: [
34
+ {
35
+ $id: "main",
36
+ name: "Main",
37
+ bucket: {
38
+ $id: "main_bucket",
39
+ name: "Main Bucket",
40
+ enabled: true,
41
+ maximumFileSize: 30000000,
42
+ allowedFileExtensions: [],
43
+ encryption: true,
44
+ antivirus: true,
45
+ },
46
+ },
47
+ {
48
+ $id: "staging",
49
+ name: "Staging",
50
+ bucket: {
51
+ $id: "staging_bucket",
52
+ name: "Staging Bucket",
53
+ enabled: true,
54
+ maximumFileSize: 30000000,
55
+ allowedFileExtensions: [],
56
+ encryption: true,
57
+ antivirus: true,
58
+ },
59
+ },
60
+ {
61
+ $id: "dev",
62
+ name: "Development",
63
+ bucket: {
64
+ $id: "dev_bucket",
65
+ name: "Development Bucket",
66
+ enabled: true,
67
+ maximumFileSize: 30000000,
68
+ allowedFileExtensions: [],
69
+ encryption: true,
70
+ antivirus: true,
71
+ },
72
+ },
73
+ ],
74
+ buckets: [
75
+ {
76
+ $id: "global_bucket",
77
+ name: "Global Bucket",
78
+ enabled: true,
79
+ maximumFileSize: 30000000,
80
+ allowedFileExtensions: [],
81
+ encryption: true,
82
+ antivirus: true,
83
+ },
84
+ ],
85
+ };
86
+
87
+ const collectionsConfig: { name: string; content: string }[] = [
88
+ {
89
+ name: "ExampleCollection",
90
+ content: `import type { CollectionCreate } from "appwrite-utils";
91
+
92
+ const ExampleCollection: Partial<CollectionCreate> = {
93
+ name: 'ExampleCollection',
94
+ $id: '${ulid()}',
95
+ documentSecurity: false,
96
+ enabled: true,
97
+ $permissions: [
98
+ { permission: 'read', target: 'any' },
99
+ { permission: 'create', target: 'users' },
100
+ { permission: 'update', target: 'users' },
101
+ { permission: 'delete', target: 'users' }
102
+ ],
103
+ attributes: [
104
+ { key: 'alterEgoName', type: 'string', size: 255, required: false },
105
+ // Add more attributes here
106
+ ],
107
+ indexes: [
108
+ { key: 'alterEgoName_search', type: 'fulltext', attributes: ['alterEgoName'] }
109
+ ],
110
+ importDefs: [
111
+ // Define import definitions here
112
+ ]
113
+ };
114
+
115
+ export default ExampleCollection;`,
116
+ },
117
+ // Add more collections here
118
+ ];
119
+
120
+ // Define our YAML files
121
+ // Define our YAML files
122
+ const configFileExample = `d`;
123
+
124
+ export const customDefinitionsFile = `import type { ConverterFunctions, ValidationRules, AfterImportActions } from "appwrite-utils";
125
+
126
+ export const customConverterFunctions: ConverterFunctions = {
127
+ // Add your custom converter functions here
128
+ }
129
+ export const customValidationRules: ValidationRules = {
130
+ // Add your custom validation rules here
131
+ }
132
+ export const customAfterImportActions: AfterImportActions = {
133
+ // Add your custom after import actions here
134
+ }`;
135
+
136
+ export const createEmptyCollection = (collectionName: string) => {
137
+ const currentDir = process.cwd();
138
+
139
+ // Check for YAML config first (preferred)
140
+ const yamlConfigPath = findYamlConfig(currentDir);
141
+ const tsConfigPath = findAppwriteConfig(currentDir);
142
+
143
+ let configDir: string;
144
+ let isYamlProject = false;
145
+
146
+ if (yamlConfigPath) {
147
+ configDir = path.dirname(yamlConfigPath);
148
+ isYamlProject = true;
149
+ } else if (tsConfigPath) {
150
+ configDir = path.dirname(tsConfigPath);
151
+ isYamlProject = false;
152
+ } else {
153
+ // No config found - assume .appwrite directory and use YAML as default
154
+ configDir = path.join(currentDir, ".appwrite");
155
+ isYamlProject = true;
156
+
157
+ // Create .appwrite directory if it doesn't exist
158
+ if (!existsSync(configDir)) {
159
+ mkdirSync(configDir, { recursive: true });
160
+ }
161
+ }
162
+
163
+ const collectionsFolder = path.join(configDir, "collections");
164
+ if (!existsSync(collectionsFolder)) {
165
+ mkdirSync(collectionsFolder, { recursive: true });
166
+ }
167
+
168
+ if (isYamlProject) {
169
+ // Create YAML collection
170
+ const yamlCollection = `# yaml-language-server: $schema=../.yaml_schemas/collection.schema.json
171
+ # Collection Definition: ${collectionName}
172
+ name: ${collectionName}
173
+ id: ${ulid()}
174
+ documentSecurity: false
175
+ enabled: true
176
+ permissions:
177
+ - permission: read
178
+ target: any
179
+ - permission: create
180
+ target: users
181
+ - permission: update
182
+ target: users
183
+ - permission: delete
184
+ target: users
185
+ attributes:
186
+ # Add your attributes here
187
+ # Example:
188
+ # - key: title
189
+ # type: string
190
+ # size: 255
191
+ # required: true
192
+ # description: "The title of the item"
193
+ indexes:
194
+ # Add your indexes here
195
+ # Example:
196
+ # - key: title_search
197
+ # type: fulltext
198
+ # attributes:
199
+ # - title
200
+ importDefs: []
201
+ `;
202
+
203
+ const collectionFilePath = path.join(collectionsFolder, `${collectionName}.yaml`);
204
+ writeFileSync(collectionFilePath, yamlCollection);
205
+ MessageFormatter.success(`Created YAML collection: ${collectionFilePath}`, { prefix: "Setup" });
206
+ } else {
207
+ // Create TypeScript collection
208
+ const emptyCollection = `import type { CollectionCreate } from "appwrite-utils";
209
+
210
+ const ${collectionName}: Partial<CollectionCreate> = {
211
+ $id: '${ulid()}',
212
+ documentSecurity: false,
213
+ enabled: true,
214
+ name: '${collectionName}',
215
+ $permissions: [
216
+ { permission: 'read', target: 'any' },
217
+ { permission: 'create', target: 'users' },
218
+ { permission: 'update', target: 'users' },
219
+ { permission: 'delete', target: 'users' }
220
+ ],
221
+ attributes: [
222
+ // Add more attributes here
223
+ ],
224
+ indexes: [
225
+ // Add more indexes here
226
+ ],
227
+ };
228
+
229
+ export default ${collectionName};`;
230
+
231
+ const collectionFilePath = path.join(collectionsFolder, `${collectionName}.ts`);
232
+ writeFileSync(collectionFilePath, emptyCollection);
233
+ MessageFormatter.success(`Created TypeScript collection: ${collectionFilePath}`, { prefix: "Setup" });
234
+ }
235
+ };
236
+
237
+ export const generateYamlConfig = (currentDir?: string, useAppwriteDir: boolean = true) => {
238
+ const basePath = currentDir || process.cwd();
239
+ const configDir = useAppwriteDir ? path.join(basePath, ".appwrite") : basePath;
240
+
241
+ if (!existsSync(configDir)) {
242
+ mkdirSync(configDir, { recursive: true });
243
+ }
244
+
245
+ const configPath = path.join(configDir, "config.yaml");
246
+ generateYamlConfigTemplate(configPath);
247
+
248
+ MessageFormatter.success(`Generated YAML config template at: ${configPath}`, { prefix: "Setup" });
249
+ MessageFormatter.info("Please update the configuration with your Appwrite project details.", { prefix: "Setup" });
250
+
251
+ return configPath;
252
+ };
253
+
254
+ export const setupDirsFiles = async (
255
+ example: boolean = false,
256
+ currentDir?: string,
257
+ useYaml: boolean = true
258
+ ) => {
259
+ const basePath = currentDir || process.cwd();
260
+
261
+ // Create .appwrite folder directly in project root
262
+ const appwriteFolder = path.join(basePath, ".appwrite");
263
+ const appwriteConfigFile = path.join(appwriteFolder, "appwriteConfig.ts");
264
+ const appwriteCustomDefsFile = path.join(
265
+ appwriteFolder,
266
+ "customDefinitions.ts"
267
+ );
268
+ const appwriteSchemaFolder = path.join(appwriteFolder, "schemas");
269
+ const appwriteYamlSchemaFolder = path.join(appwriteFolder, ".yaml_schemas");
270
+ const appwriteDataFolder = path.join(appwriteFolder, "importData");
271
+ // Enhanced version detection with multiple sources
272
+ let useTables = false;
273
+ let detectionSource = "default";
274
+
275
+ try {
276
+ // Priority 1: Check for existing appwrite.json project config
277
+ const projectConfigPath = findAppwriteProjectConfig(basePath);
278
+ if (projectConfigPath) {
279
+ const projectConfig = loadAppwriteProjectConfig(projectConfigPath);
280
+ if (projectConfig) {
281
+ useTables = isTablesDBProject(projectConfig);
282
+ detectionSource = "appwrite.json";
283
+ MessageFormatter.info(`Detected ${useTables ? 'TablesDB' : 'Collections'} project from ${projectConfigPath}`, { prefix: "Setup" });
284
+ }
285
+ }
286
+
287
+ // Priority 2: Try reading existing YAML config for version detection
288
+ if (!useTables && detectionSource === "default") {
289
+ const yamlPath = findYamlConfig(basePath);
290
+ if (yamlPath) {
291
+ const cfg = await loadYamlConfig(yamlPath);
292
+ if (cfg) {
293
+ // Try session auth first, then API key for version detection
294
+ let endpoint = cfg.appwriteEndpoint;
295
+ let projectId = cfg.appwriteProject;
296
+
297
+ if (hasSessionAuth(endpoint, projectId)) {
298
+ MessageFormatter.info("Using session authentication for version detection", { prefix: "Setup" });
299
+ }
300
+
301
+ const ver = await fetchServerVersion(endpoint);
302
+ if (isVersionAtLeast(ver || undefined, '1.8.0')) {
303
+ useTables = true;
304
+ detectionSource = "server-version";
305
+ MessageFormatter.info(`Detected TablesDB support (Appwrite ${ver})`, { prefix: "Setup" });
306
+ } else {
307
+ MessageFormatter.info(`Using Collections API (Appwrite ${ver || 'unknown'})`, { prefix: "Setup" });
308
+ }
309
+ }
310
+ }
311
+ }
312
+ } catch (error) {
313
+ MessageFormatter.warning(`Version detection failed, defaulting to Collections API: ${error instanceof Error ? error.message : String(error)}`, { prefix: "Setup" });
314
+ }
315
+
316
+ const targetFolderName = useTables ? "tables" : "collections";
317
+ const collectionsFolder = path.join(appwriteFolder, targetFolderName);
318
+
319
+ // Create directory structure
320
+ if (!existsSync(appwriteFolder)) {
321
+ mkdirSync(appwriteFolder, { recursive: true });
322
+ }
323
+
324
+ if (!existsSync(collectionsFolder)) {
325
+ mkdirSync(collectionsFolder, { recursive: true });
326
+ }
327
+
328
+ // Handle configuration file creation - YAML is now default
329
+ if (useYaml) {
330
+ // Generate YAML config in .appwrite directory
331
+ const configPath = path.join(appwriteFolder, "config.yaml");
332
+ generateYamlConfigTemplate(configPath);
333
+ } else if (!existsSync(appwriteConfigFile)) {
334
+ if (example) {
335
+ writeFileSync(appwriteConfigFile, configFileExample);
336
+ } else {
337
+ const baseConfigContent = `import { type AppwriteConfig } from "appwrite-utils";
338
+
339
+ const appwriteConfig: AppwriteConfig = ${JSON.stringify(baseConfig, null, 2)};
340
+
341
+ export default appwriteConfig;
342
+ `;
343
+ writeFileSync(appwriteConfigFile, baseConfigContent);
344
+ }
345
+ }
346
+
347
+ // Create TypeScript files for each collection only if not using YAML
348
+ if (!useYaml) {
349
+ collectionsConfig.forEach((collection) => {
350
+ const collectionFilePath = path.join(
351
+ collectionsFolder,
352
+ `${collection.name}.ts`
353
+ );
354
+ writeFileSync(collectionFilePath, collection.content);
355
+ });
356
+ }
357
+
358
+ // Create YAML collection/table example if using YAML config
359
+ if (useYaml) {
360
+ const terminology = useTables
361
+ ? {
362
+ container: "table",
363
+ fields: "columns",
364
+ security: "rowSecurity",
365
+ schemaRef: "table.schema.json",
366
+ containerName: "Table",
367
+ fieldName: "Column"
368
+ }
369
+ : {
370
+ container: "collection",
371
+ fields: "attributes",
372
+ security: "documentSecurity",
373
+ schemaRef: "collection.schema.json",
374
+ containerName: "Collection",
375
+ fieldName: "Attribute"
376
+ };
377
+
378
+ const yamlExample = `# yaml-language-server: $schema=../.yaml_schemas/${terminology.schemaRef}
379
+ # Example ${terminology.containerName} Definition
380
+ name: Example${terminology.containerName}
381
+ id: example_${terminology.container}_${Date.now()}
382
+ ${terminology.security}: false
383
+ enabled: true
384
+ permissions:
385
+ - permission: read
386
+ target: any
387
+ - permission: create
388
+ target: users
389
+ - permission: update
390
+ target: users
391
+ - permission: delete
392
+ target: users
393
+ ${terminology.fields}:
394
+ - key: title
395
+ type: string
396
+ size: 255
397
+ required: true
398
+ description: "The title of the item"
399
+ - key: description
400
+ type: string
401
+ size: 1000
402
+ required: false
403
+ description: "A longer description"
404
+ - key: isActive
405
+ type: boolean
406
+ required: false
407
+ default: true${useTables ? `
408
+ - key: uniqueCode
409
+ type: string
410
+ size: 50
411
+ required: false
412
+ unique: true
413
+ description: "Unique identifier code (TablesDB feature)"` : ''}
414
+ indexes:
415
+ - key: title_search
416
+ type: fulltext
417
+ attributes:
418
+ - title
419
+ importDefs: []
420
+ `;
421
+ const yamlExamplePath = path.join(collectionsFolder, `Example${terminology.containerName}.yaml`);
422
+ writeFileSync(yamlExamplePath, yamlExample);
423
+
424
+ MessageFormatter.info(`Created example ${terminology.container} definition with ${terminology.fields} terminology`, { prefix: "Setup" });
425
+
426
+ // Create JSON schema for collection/table definitions
427
+ const containerJsonSchema = useTables ? {
428
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
429
+ "$id": "https://appwrite-utils.dev/schemas/table.schema.json",
430
+ "title": "Appwrite Table Definition",
431
+ "description": "Schema for defining Appwrite tables in YAML (TablesDB API)",
432
+ "type": "object",
433
+ "properties": {
434
+ "name": {
435
+ "type": "string",
436
+ "description": "The name of the table"
437
+ },
438
+ "id": {
439
+ "type": "string",
440
+ "description": "The ID of the table (optional, auto-generated if not provided)",
441
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
442
+ },
443
+ "rowSecurity": {
444
+ "type": "boolean",
445
+ "default": false,
446
+ "description": "Enable row-level permissions"
447
+ },
448
+ "enabled": {
449
+ "type": "boolean",
450
+ "default": true,
451
+ "description": "Whether the table is enabled"
452
+ },
453
+ "permissions": {
454
+ "type": "array",
455
+ "description": "Table-level permissions",
456
+ "items": {
457
+ "type": "object",
458
+ "properties": {
459
+ "permission": {
460
+ "type": "string",
461
+ "enum": ["read", "create", "update", "delete"],
462
+ "description": "The permission type"
463
+ },
464
+ "target": {
465
+ "type": "string",
466
+ "description": "Permission target (e.g., 'any', 'users', 'users/verified', 'label:admin')"
467
+ }
468
+ },
469
+ "required": ["permission", "target"],
470
+ "additionalProperties": false
471
+ }
472
+ },
473
+ "columns": {
474
+ "type": "array",
475
+ "description": "Table columns (fields)",
476
+ "items": {
477
+ "type": "object",
478
+ "properties": {
479
+ "key": {
480
+ "type": "string",
481
+ "description": "Column name",
482
+ "pattern": "^[a-zA-Z][a-zA-Z0-9]*$"
483
+ },
484
+ "type": {
485
+ "type": "string",
486
+ "enum": ["string", "integer", "double", "boolean", "datetime", "email", "ip", "url", "enum", "relationship"],
487
+ "description": "Column data type"
488
+ },
489
+ "size": {
490
+ "type": "number",
491
+ "description": "Maximum size for string columns",
492
+ "minimum": 1,
493
+ "maximum": 1073741824
494
+ },
495
+ "required": {
496
+ "type": "boolean",
497
+ "default": false,
498
+ "description": "Whether the column is required"
499
+ },
500
+ "array": {
501
+ "type": "boolean",
502
+ "default": false,
503
+ "description": "Whether the column is an array"
504
+ },
505
+ "unique": {
506
+ "type": "boolean",
507
+ "default": false,
508
+ "description": "Whether the column values must be unique (TablesDB feature)"
509
+ },
510
+ "default": {
511
+ "description": "Default value for the column"
512
+ },
513
+ "description": {
514
+ "type": "string",
515
+ "description": "Column description"
516
+ },
517
+ "encrypt": {
518
+ "type": "boolean",
519
+ "description": "Whether the column should be encrypted"
520
+ },
521
+ "format": {
522
+ "type": "string",
523
+ "description": "Format for string columns"
524
+ },
525
+ "min": {
526
+ "type": "number",
527
+ "description": "Minimum value for numeric columns"
528
+ },
529
+ "max": {
530
+ "type": "number",
531
+ "description": "Maximum value for numeric columns"
532
+ },
533
+ "elements": {
534
+ "type": "array",
535
+ "items": {
536
+ "type": "string"
537
+ },
538
+ "description": "Allowed values for enum columns"
539
+ },
540
+ "relatedCollection": {
541
+ "type": "string",
542
+ "description": "Related table name for relationship columns"
543
+ },
544
+ "relationType": {
545
+ "type": "string",
546
+ "enum": ["oneToOne", "oneToMany", "manyToOne", "manyToMany"],
547
+ "description": "Type of relationship"
548
+ },
549
+ "twoWay": {
550
+ "type": "boolean",
551
+ "description": "Whether the relationship is bidirectional"
552
+ },
553
+ "twoWayKey": {
554
+ "type": "string",
555
+ "description": "Key name for the reverse relationship"
556
+ },
557
+ "onDelete": {
558
+ "type": "string",
559
+ "enum": ["cascade", "restrict", "setNull"],
560
+ "description": "Action to take when related row is deleted"
561
+ },
562
+ "side": {
563
+ "type": "string",
564
+ "enum": ["parent", "child"],
565
+ "description": "Side of the relationship"
566
+ }
567
+ },
568
+ "required": ["key", "type"],
569
+ "additionalProperties": false,
570
+ "allOf": [
571
+ {
572
+ "if": {
573
+ "properties": { "type": { "const": "enum" } }
574
+ },
575
+ "then": {
576
+ "required": ["elements"]
577
+ }
578
+ },
579
+ {
580
+ "if": {
581
+ "properties": { "type": { "const": "relationship" } }
582
+ },
583
+ "then": {
584
+ "required": ["relatedCollection", "relationType"]
585
+ }
586
+ }
587
+ ]
588
+ }
589
+ },
590
+ "indexes": {
591
+ "type": "array",
592
+ "description": "Database indexes for the table",
593
+ "items": {
594
+ "type": "object",
595
+ "properties": {
596
+ "key": {
597
+ "type": "string",
598
+ "description": "Index name"
599
+ },
600
+ "type": {
601
+ "type": "string",
602
+ "enum": ["key", "fulltext", "unique"],
603
+ "description": "Index type"
604
+ },
605
+ "attributes": {
606
+ "type": "array",
607
+ "items": {
608
+ "type": "string"
609
+ },
610
+ "description": "Columns to index",
611
+ "minItems": 1
612
+ },
613
+ "orders": {
614
+ "type": "array",
615
+ "items": {
616
+ "type": "string",
617
+ "enum": ["ASC", "DESC"]
618
+ },
619
+ "description": "Sort order for each column"
620
+ }
621
+ },
622
+ "required": ["key", "type", "attributes"],
623
+ "additionalProperties": false
624
+ }
625
+ },
626
+ "importDefs": {
627
+ "type": "array",
628
+ "description": "Import definitions for data migration",
629
+ "default": []
630
+ }
631
+ },
632
+ "required": ["name"],
633
+ "additionalProperties": false
634
+ } : {
635
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
636
+ "$id": "https://appwrite-utils.dev/schemas/collection.schema.json",
637
+ "title": "Appwrite Collection Definition",
638
+ "description": "Schema for defining Appwrite collections in YAML",
639
+ "type": "object",
640
+ "properties": {
641
+ "name": {
642
+ "type": "string",
643
+ "description": "The name of the collection"
644
+ },
645
+ "id": {
646
+ "type": "string",
647
+ "description": "The ID of the collection (optional, auto-generated if not provided)",
648
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
649
+ },
650
+ "documentSecurity": {
651
+ "type": "boolean",
652
+ "default": false,
653
+ "description": "Enable document-level permissions"
654
+ },
655
+ "enabled": {
656
+ "type": "boolean",
657
+ "default": true,
658
+ "description": "Whether the collection is enabled"
659
+ },
660
+ "permissions": {
661
+ "type": "array",
662
+ "description": "Collection-level permissions",
663
+ "items": {
664
+ "type": "object",
665
+ "properties": {
666
+ "permission": {
667
+ "type": "string",
668
+ "enum": ["read", "create", "update", "delete"],
669
+ "description": "The permission type"
670
+ },
671
+ "target": {
672
+ "type": "string",
673
+ "description": "Permission target (e.g., 'any', 'users', 'users/verified', 'label:admin')"
674
+ }
675
+ },
676
+ "required": ["permission", "target"],
677
+ "additionalProperties": false
678
+ }
679
+ },
680
+ "attributes": {
681
+ "type": "array",
682
+ "description": "Collection attributes (fields)",
683
+ "items": {
684
+ "type": "object",
685
+ "properties": {
686
+ "key": {
687
+ "type": "string",
688
+ "description": "Attribute name",
689
+ "pattern": "^[a-zA-Z][a-zA-Z0-9]*$"
690
+ },
691
+ "type": {
692
+ "type": "string",
693
+ "enum": ["string", "integer", "double", "boolean", "datetime", "email", "ip", "url", "enum", "relationship"],
694
+ "description": "Attribute data type"
695
+ },
696
+ "size": {
697
+ "type": "number",
698
+ "description": "Maximum size for string attributes",
699
+ "minimum": 1,
700
+ "maximum": 1073741824
701
+ },
702
+ "required": {
703
+ "type": "boolean",
704
+ "default": false,
705
+ "description": "Whether the attribute is required"
706
+ },
707
+ "array": {
708
+ "type": "boolean",
709
+ "default": false,
710
+ "description": "Whether the attribute is an array"
711
+ },
712
+ "default": {
713
+ "description": "Default value for the attribute"
714
+ },
715
+ "description": {
716
+ "type": "string",
717
+ "description": "Attribute description"
718
+ },
719
+ "encrypt": {
720
+ "type": "boolean",
721
+ "description": "Whether the attribute should be encrypted"
722
+ },
723
+ "format": {
724
+ "type": "string",
725
+ "description": "Format for string attributes"
726
+ },
727
+ "min": {
728
+ "type": "number",
729
+ "description": "Minimum value for numeric attributes"
730
+ },
731
+ "max": {
732
+ "type": "number",
733
+ "description": "Maximum value for numeric attributes"
734
+ },
735
+ "elements": {
736
+ "type": "array",
737
+ "items": {
738
+ "type": "string"
739
+ },
740
+ "description": "Allowed values for enum attributes"
741
+ },
742
+ "relatedCollection": {
743
+ "type": "string",
744
+ "description": "Related collection name for relationship attributes"
745
+ },
746
+ "relationType": {
747
+ "type": "string",
748
+ "enum": ["oneToOne", "oneToMany", "manyToOne", "manyToMany"],
749
+ "description": "Type of relationship"
750
+ },
751
+ "twoWay": {
752
+ "type": "boolean",
753
+ "description": "Whether the relationship is bidirectional"
754
+ },
755
+ "twoWayKey": {
756
+ "type": "string",
757
+ "description": "Key name for the reverse relationship"
758
+ },
759
+ "onDelete": {
760
+ "type": "string",
761
+ "enum": ["cascade", "restrict", "setNull"],
762
+ "description": "Action to take when related document is deleted"
763
+ },
764
+ "side": {
765
+ "type": "string",
766
+ "enum": ["parent", "child"],
767
+ "description": "Side of the relationship"
768
+ }
769
+ },
770
+ "required": ["key", "type"],
771
+ "additionalProperties": false,
772
+ "allOf": [
773
+ {
774
+ "if": {
775
+ "properties": { "type": { "const": "enum" } }
776
+ },
777
+ "then": {
778
+ "required": ["elements"]
779
+ }
780
+ },
781
+ {
782
+ "if": {
783
+ "properties": { "type": { "const": "relationship" } }
784
+ },
785
+ "then": {
786
+ "required": ["relatedCollection", "relationType"]
787
+ }
788
+ }
789
+ ]
790
+ }
791
+ },
792
+ "indexes": {
793
+ "type": "array",
794
+ "description": "Database indexes for the collection",
795
+ "items": {
796
+ "type": "object",
797
+ "properties": {
798
+ "key": {
799
+ "type": "string",
800
+ "description": "Index name"
801
+ },
802
+ "type": {
803
+ "type": "string",
804
+ "enum": ["key", "fulltext", "unique"],
805
+ "description": "Index type"
806
+ },
807
+ "attributes": {
808
+ "type": "array",
809
+ "items": {
810
+ "type": "string"
811
+ },
812
+ "description": "Attributes to index",
813
+ "minItems": 1
814
+ },
815
+ "orders": {
816
+ "type": "array",
817
+ "items": {
818
+ "type": "string",
819
+ "enum": ["ASC", "DESC"]
820
+ },
821
+ "description": "Sort order for each attribute"
822
+ }
823
+ },
824
+ "required": ["key", "type", "attributes"],
825
+ "additionalProperties": false
826
+ }
827
+ },
828
+ "importDefs": {
829
+ "type": "array",
830
+ "description": "Import definitions for data migration",
831
+ "default": []
832
+ }
833
+ },
834
+ "required": ["name"],
835
+ "additionalProperties": false
836
+ };
837
+
838
+ // Ensure YAML schemas directory exists before writing schema
839
+ if (!existsSync(appwriteYamlSchemaFolder)) {
840
+ mkdirSync(appwriteYamlSchemaFolder, { recursive: true });
841
+ }
842
+
843
+ const schemaFileName = useTables ? "table.schema.json" : "collection.schema.json";
844
+ const containerSchemaPath = path.join(appwriteYamlSchemaFolder, schemaFileName);
845
+ writeFileSync(containerSchemaPath, JSON.stringify(containerJsonSchema, null, 2));
846
+
847
+ // Create JSON schema for appwriteConfig.yaml
848
+ const configJsonSchema = {
849
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
850
+ "$id": "https://appwrite-utils.dev/schemas/appwrite-config.schema.json",
851
+ "title": "Appwrite Configuration",
852
+ "description": "Schema for Appwrite project configuration in YAML",
853
+ "type": "object",
854
+ "properties": {
855
+ "appwrite": {
856
+ "type": "object",
857
+ "description": "Appwrite connection settings",
858
+ "properties": {
859
+ "endpoint": {
860
+ "type": "string",
861
+ "default": "https://cloud.appwrite.io/v1",
862
+ "description": "Appwrite server endpoint URL"
863
+ },
864
+ "project": {
865
+ "type": "string",
866
+ "description": "Appwrite project ID"
867
+ },
868
+ "key": {
869
+ "type": "string",
870
+ "description": "Appwrite API key with appropriate permissions"
871
+ }
872
+ },
873
+ "required": ["project", "key"],
874
+ "additionalProperties": false
875
+ },
876
+ "logging": {
877
+ "type": "object",
878
+ "description": "Logging configuration",
879
+ "properties": {
880
+ "enabled": {
881
+ "type": "boolean",
882
+ "default": false,
883
+ "description": "Enable file logging"
884
+ },
885
+ "level": {
886
+ "type": "string",
887
+ "enum": ["error", "warn", "info", "debug"],
888
+ "default": "info",
889
+ "description": "Logging level"
890
+ },
891
+ "directory": {
892
+ "type": "string",
893
+ "description": "Custom log directory path (optional)"
894
+ },
895
+ "console": {
896
+ "type": "boolean",
897
+ "default": false,
898
+ "description": "Enable console logging"
899
+ }
900
+ },
901
+ "additionalProperties": false
902
+ },
903
+ "backups": {
904
+ "type": "object",
905
+ "description": "Backup configuration",
906
+ "properties": {
907
+ "enabled": {
908
+ "type": "boolean",
909
+ "default": true,
910
+ "description": "Enable automatic backups"
911
+ },
912
+ "interval": {
913
+ "type": "number",
914
+ "default": 3600,
915
+ "description": "Backup interval in seconds"
916
+ },
917
+ "retention": {
918
+ "type": "number",
919
+ "default": 30,
920
+ "description": "Backup retention in days"
921
+ },
922
+ "cleanup": {
923
+ "type": "boolean",
924
+ "default": true,
925
+ "description": "Enable automatic backup cleanup"
926
+ }
927
+ },
928
+ "additionalProperties": false
929
+ },
930
+ "data": {
931
+ "type": "object",
932
+ "description": "Data management settings",
933
+ "properties": {
934
+ "enableMockData": {
935
+ "type": "boolean",
936
+ "default": false,
937
+ "description": "Enable mock data generation"
938
+ },
939
+ "documentBucketId": {
940
+ "type": "string",
941
+ "default": "documents",
942
+ "description": "Default bucket ID for document attachments"
943
+ },
944
+ "usersCollectionName": {
945
+ "type": "string",
946
+ "default": "Members",
947
+ "description": "Name of the users/members collection"
948
+ },
949
+ "importDirectory": {
950
+ "type": "string",
951
+ "default": "importData",
952
+ "description": "Directory containing import data files"
953
+ }
954
+ },
955
+ "additionalProperties": false
956
+ },
957
+ "schemas": {
958
+ "type": "object",
959
+ "description": "Schema generation settings",
960
+ "properties": {
961
+ "outputDirectory": {
962
+ "type": "string",
963
+ "default": "schemas",
964
+ "description": "Directory where generated schemas are saved"
965
+ },
966
+ "yamlSchemaDirectory": {
967
+ "type": "string",
968
+ "default": ".yaml_schemas",
969
+ "description": "Directory containing YAML validation schemas"
970
+ }
971
+ },
972
+ "additionalProperties": false
973
+ },
974
+ "migrations": {
975
+ "type": "object",
976
+ "description": "Migration settings",
977
+ "properties": {
978
+ "enabled": {
979
+ "type": "boolean",
980
+ "default": true,
981
+ "description": "Enable migration tracking database"
982
+ }
983
+ },
984
+ "additionalProperties": false
985
+ },
986
+ "databases": {
987
+ "type": "array",
988
+ "description": "Database configurations",
989
+ "items": {
990
+ "type": "object",
991
+ "properties": {
992
+ "id": {
993
+ "type": "string",
994
+ "description": "Database ID",
995
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
996
+ },
997
+ "name": {
998
+ "type": "string",
999
+ "description": "Database display name"
1000
+ },
1001
+ "bucket": {
1002
+ "type": "object",
1003
+ "description": "Associated storage bucket",
1004
+ "properties": {
1005
+ "id": {
1006
+ "type": "string",
1007
+ "description": "Bucket ID"
1008
+ },
1009
+ "name": {
1010
+ "type": "string",
1011
+ "description": "Bucket display name"
1012
+ },
1013
+ "permissions": {
1014
+ "type": "array",
1015
+ "items": {
1016
+ "type": "string"
1017
+ },
1018
+ "description": "Bucket permissions"
1019
+ },
1020
+ "fileSecurity": {
1021
+ "type": "boolean",
1022
+ "description": "Enable file-level security"
1023
+ },
1024
+ "enabled": {
1025
+ "type": "boolean",
1026
+ "default": true,
1027
+ "description": "Enable the bucket"
1028
+ },
1029
+ "maximumFileSize": {
1030
+ "type": "number",
1031
+ "default": 30000000,
1032
+ "description": "Maximum file size in bytes"
1033
+ },
1034
+ "allowedFileExtensions": {
1035
+ "type": "array",
1036
+ "items": {
1037
+ "type": "string"
1038
+ },
1039
+ "description": "Allowed file extensions (empty = all allowed)"
1040
+ },
1041
+ "compression": {
1042
+ "type": "string",
1043
+ "enum": ["none", "gzip", "zstd"],
1044
+ "default": "none",
1045
+ "description": "Compression algorithm"
1046
+ },
1047
+ "encryption": {
1048
+ "type": "boolean",
1049
+ "default": false,
1050
+ "description": "Enable file encryption"
1051
+ },
1052
+ "antivirus": {
1053
+ "type": "boolean",
1054
+ "default": false,
1055
+ "description": "Enable antivirus scanning"
1056
+ }
1057
+ },
1058
+ "required": ["id", "name"],
1059
+ "additionalProperties": false
1060
+ }
1061
+ },
1062
+ "required": ["id", "name"],
1063
+ "additionalProperties": false
1064
+ }
1065
+ },
1066
+ "buckets": {
1067
+ "type": "array",
1068
+ "description": "Global storage buckets",
1069
+ "items": {
1070
+ "type": "object",
1071
+ "properties": {
1072
+ "id": {
1073
+ "type": "string",
1074
+ "description": "Bucket ID"
1075
+ },
1076
+ "name": {
1077
+ "type": "string",
1078
+ "description": "Bucket display name"
1079
+ },
1080
+ "permissions": {
1081
+ "type": "array",
1082
+ "items": {
1083
+ "type": "string"
1084
+ },
1085
+ "description": "Bucket permissions"
1086
+ },
1087
+ "fileSecurity": {
1088
+ "type": "boolean",
1089
+ "description": "Enable file-level security"
1090
+ },
1091
+ "enabled": {
1092
+ "type": "boolean",
1093
+ "default": true,
1094
+ "description": "Enable the bucket"
1095
+ },
1096
+ "maximumFileSize": {
1097
+ "type": "number",
1098
+ "default": 30000000,
1099
+ "description": "Maximum file size in bytes"
1100
+ },
1101
+ "allowedFileExtensions": {
1102
+ "type": "array",
1103
+ "items": {
1104
+ "type": "string"
1105
+ },
1106
+ "description": "Allowed file extensions (empty = all allowed)"
1107
+ },
1108
+ "compression": {
1109
+ "type": "string",
1110
+ "enum": ["none", "gzip", "zstd"],
1111
+ "default": "none",
1112
+ "description": "Compression algorithm"
1113
+ },
1114
+ "encryption": {
1115
+ "type": "boolean",
1116
+ "default": false,
1117
+ "description": "Enable file encryption"
1118
+ },
1119
+ "antivirus": {
1120
+ "type": "boolean",
1121
+ "default": false,
1122
+ "description": "Enable antivirus scanning"
1123
+ }
1124
+ },
1125
+ "required": ["id", "name"],
1126
+ "additionalProperties": false
1127
+ }
1128
+ },
1129
+ "functions": {
1130
+ "type": "array",
1131
+ "description": "Appwrite Functions",
1132
+ "items": {
1133
+ "type": "object",
1134
+ "properties": {
1135
+ "id": {
1136
+ "type": "string",
1137
+ "description": "Function ID"
1138
+ },
1139
+ "name": {
1140
+ "type": "string",
1141
+ "description": "Function name"
1142
+ },
1143
+ "runtime": {
1144
+ "type": "string",
1145
+ "description": "Runtime environment"
1146
+ },
1147
+ "execute": {
1148
+ "type": "array",
1149
+ "items": {
1150
+ "type": "string"
1151
+ },
1152
+ "description": "Execution permissions"
1153
+ },
1154
+ "events": {
1155
+ "type": "array",
1156
+ "items": {
1157
+ "type": "string"
1158
+ },
1159
+ "description": "Event triggers"
1160
+ },
1161
+ "schedule": {
1162
+ "type": "string",
1163
+ "description": "Cron schedule"
1164
+ },
1165
+ "timeout": {
1166
+ "type": "number",
1167
+ "default": 15,
1168
+ "description": "Execution timeout in seconds"
1169
+ },
1170
+ "enabled": {
1171
+ "type": "boolean",
1172
+ "default": true,
1173
+ "description": "Enable the function"
1174
+ },
1175
+ "logging": {
1176
+ "type": "boolean",
1177
+ "default": true,
1178
+ "description": "Enable function logging"
1179
+ },
1180
+ "entrypoint": {
1181
+ "type": "string",
1182
+ "description": "Function entrypoint file"
1183
+ },
1184
+ "commands": {
1185
+ "type": "string",
1186
+ "description": "Build commands"
1187
+ }
1188
+ },
1189
+ "required": ["id", "name", "runtime"],
1190
+ "additionalProperties": false
1191
+ }
1192
+ }
1193
+ },
1194
+ "required": ["appwrite"],
1195
+ "additionalProperties": false
1196
+ };
1197
+
1198
+ const configSchemaPath = path.join(appwriteYamlSchemaFolder, "appwrite-config.schema.json");
1199
+ writeFileSync(configSchemaPath, JSON.stringify(configJsonSchema, null, 2));
1200
+ }
1201
+
1202
+ if (!existsSync(appwriteSchemaFolder)) {
1203
+ mkdirSync(appwriteSchemaFolder, { recursive: true });
1204
+ }
1205
+
1206
+ if (!existsSync(appwriteDataFolder)) {
1207
+ mkdirSync(appwriteDataFolder, { recursive: true });
1208
+ }
1209
+
1210
+ // Remove the nested .appwrite folder creation since we're using .appwrite as the main folder
1211
+
1212
+ const configType = useYaml ? "YAML" : "TypeScript";
1213
+ const terminology = useTables ? "tables" : "collections";
1214
+ const containerType = useTables ? "TablesDB" : "Collections";
1215
+
1216
+ MessageFormatter.success(`Created ${configType} config and setup files/directories in .appwrite/ folder.`, { prefix: "Setup" });
1217
+ MessageFormatter.info(`Project configured for ${containerType} API (${detectionSource} detection)`, { prefix: "Setup" });
1218
+
1219
+ if (useYaml) {
1220
+ MessageFormatter.info("You can now configure your project in .appwrite/config.yaml", { prefix: "Setup" });
1221
+ MessageFormatter.info(`${useTables ? 'Tables' : 'Collections'} can be defined in .appwrite/${terminology}/ as .ts or .yaml files`, { prefix: "Setup" });
1222
+ MessageFormatter.info("Schemas will be generated in .appwrite/schemas/", { prefix: "Setup" });
1223
+ MessageFormatter.info("Import data can be placed in .appwrite/importData/", { prefix: "Setup" });
1224
+ if (useTables) {
1225
+ MessageFormatter.info("TablesDB features: unique constraints, enhanced performance, row-level security", { prefix: "Setup" });
1226
+ }
1227
+ } else {
1228
+ MessageFormatter.info("You can now configure logging in your .appwrite/appwriteConfig.ts file:", { prefix: "Setup" });
1229
+ MessageFormatter.info(" logging: {", { prefix: "Setup" });
1230
+ MessageFormatter.info(" enabled: true,", { prefix: "Setup" });
1231
+ MessageFormatter.info(" level: 'info',", { prefix: "Setup" });
1232
+ MessageFormatter.info(" console: true,", { prefix: "Setup" });
1233
+ MessageFormatter.info(" logDirectory: './logs' // optional custom directory", { prefix: "Setup" });
1234
+ MessageFormatter.info(" }", { prefix: "Setup" });
1235
+ }
1236
+ };