appwrite-utils-cli 1.9.7 → 1.12.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 (376) hide show
  1. package/README.md +1004 -1004
  2. package/dist/adapters/index.d.ts +7 -8
  3. package/dist/adapters/index.js +7 -9
  4. package/dist/backups/operations/bucketBackup.js +2 -2
  5. package/dist/backups/operations/collectionBackup.d.ts +1 -1
  6. package/dist/backups/operations/collectionBackup.js +3 -3
  7. package/dist/backups/operations/comprehensiveBackup.d.ts +1 -1
  8. package/dist/backups/operations/comprehensiveBackup.js +2 -2
  9. package/dist/backups/tracking/centralizedTracking.d.ts +1 -1
  10. package/dist/backups/tracking/centralizedTracking.js +2 -2
  11. package/dist/cli/commands/configCommands.js +51 -7
  12. package/dist/cli/commands/databaseCommands.js +156 -104
  13. package/dist/cli/commands/functionCommands.js +3 -3
  14. package/dist/cli/commands/importFileCommands.d.ts +7 -0
  15. package/dist/cli/commands/importFileCommands.js +674 -0
  16. package/dist/cli/commands/schemaCommands.js +3 -3
  17. package/dist/cli/commands/storageCommands.js +2 -3
  18. package/dist/cli/commands/transferCommands.js +3 -5
  19. package/dist/collections/{attributes.d.ts → columns.d.ts} +1 -1
  20. package/dist/collections/{attributes.js → columns.js} +15 -9
  21. package/dist/collections/indexes.js +1 -3
  22. package/dist/collections/methods.d.ts +1 -1
  23. package/dist/collections/methods.js +38 -20
  24. package/dist/collections/tableOperations.d.ts +1 -0
  25. package/dist/collections/tableOperations.js +30 -11
  26. package/dist/collections/transferOperations.d.ts +1 -1
  27. package/dist/collections/transferOperations.js +3 -4
  28. package/dist/collections/wipeOperations.d.ts +4 -3
  29. package/dist/collections/wipeOperations.js +112 -39
  30. package/dist/databases/methods.js +2 -2
  31. package/dist/databases/setup.js +2 -2
  32. package/dist/examples/yamlTerminologyExample.js +2 -2
  33. package/dist/functions/deployments.d.ts +1 -1
  34. package/dist/functions/deployments.js +6 -6
  35. package/dist/functions/fnConfigDiscovery.js +2 -2
  36. package/dist/functions/methods.js +2 -2
  37. package/dist/functions/templates/count-docs-in-collection/README.md +53 -53
  38. package/dist/functions/templates/count-docs-in-collection/src/main.ts +159 -159
  39. package/dist/functions/templates/count-docs-in-collection/src/request.ts +8 -8
  40. package/dist/functions/templates/hono-typescript/README.md +285 -285
  41. package/dist/functions/templates/hono-typescript/src/adapters/request.ts +73 -73
  42. package/dist/functions/templates/hono-typescript/src/adapters/response.ts +105 -105
  43. package/dist/functions/templates/hono-typescript/src/app.ts +179 -179
  44. package/dist/functions/templates/hono-typescript/src/context.ts +102 -102
  45. package/{src/functions/templates/hono-typescript/src/index.ts → dist/functions/templates/hono-typescript/src/main.ts} +53 -53
  46. package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +118 -118
  47. package/dist/functions/templates/typescript-node/README.md +31 -31
  48. package/dist/functions/templates/typescript-node/src/context.ts +102 -102
  49. package/dist/functions/templates/typescript-node/src/{index.ts → main.ts} +29 -29
  50. package/dist/functions/templates/uv/README.md +30 -30
  51. package/dist/functions/templates/uv/pyproject.toml +29 -29
  52. package/dist/functions/templates/uv/src/context.py +124 -124
  53. package/dist/functions/templates/uv/src/{index.py → main.py} +45 -45
  54. package/dist/init.js +1 -1
  55. package/dist/interactiveCLI.d.ts +6 -1
  56. package/dist/interactiveCLI.js +79 -25
  57. package/dist/main.js +125 -180
  58. package/dist/migrations/afterImportActions.js +2 -3
  59. package/dist/migrations/appwriteToX.d.ts +1 -1
  60. package/dist/migrations/appwriteToX.js +10 -8
  61. package/dist/migrations/comprehensiveTransfer.js +3 -5
  62. package/dist/migrations/dataLoader.d.ts +4 -2
  63. package/dist/migrations/dataLoader.js +42 -20
  64. package/dist/migrations/importController.d.ts +2 -0
  65. package/dist/migrations/importController.js +39 -24
  66. package/dist/migrations/importDataActions.js +3 -3
  67. package/dist/migrations/relationships.js +1 -2
  68. package/dist/migrations/services/DataTransformationService.js +2 -2
  69. package/dist/migrations/services/FileHandlerService.js +1 -1
  70. package/dist/migrations/services/ImportOrchestrator.d.ts +2 -0
  71. package/dist/migrations/services/ImportOrchestrator.js +15 -7
  72. package/dist/migrations/services/RateLimitManager.js +1 -1
  73. package/dist/migrations/services/RelationshipResolver.js +1 -1
  74. package/dist/migrations/services/UserMappingService.js +1 -1
  75. package/dist/migrations/services/ValidationService.js +1 -1
  76. package/dist/migrations/transfer.d.ts +8 -4
  77. package/dist/migrations/transfer.js +108 -55
  78. package/dist/migrations/yaml/YamlImportConfigLoader.js +52 -52
  79. package/dist/migrations/yaml/YamlImportIntegration.js +2 -2
  80. package/dist/migrations/yaml/generateImportSchemas.js +174 -174
  81. package/dist/setupCommands.d.ts +1 -1
  82. package/dist/setupCommands.js +5 -6
  83. package/dist/setupController.js +1 -1
  84. package/dist/shared/backupTracking.d.ts +1 -1
  85. package/dist/shared/backupTracking.js +2 -2
  86. package/dist/shared/confirmationDialogs.js +1 -1
  87. package/dist/shared/migrationHelpers.d.ts +1 -1
  88. package/dist/shared/migrationHelpers.js +4 -4
  89. package/dist/shared/operationQueue.d.ts +1 -1
  90. package/dist/shared/operationQueue.js +3 -4
  91. package/dist/shared/operationsTable.d.ts +1 -1
  92. package/dist/shared/operationsTable.js +35 -34
  93. package/dist/shared/operationsTableSchema.d.ts +3 -3
  94. package/dist/shared/operationsTableSchema.js +2 -2
  95. package/dist/shared/progressManager.js +1 -1
  96. package/dist/shared/selectionDialogs.d.ts +6 -0
  97. package/dist/shared/selectionDialogs.js +56 -12
  98. package/dist/storage/methods.d.ts +12 -0
  99. package/dist/storage/methods.js +92 -89
  100. package/dist/storage/schemas.d.ts +2 -2
  101. package/dist/tables/indexManager.d.ts +1 -1
  102. package/dist/tables/indexManager.js +2 -2
  103. package/dist/types.d.ts +2 -2
  104. package/dist/types.js +1 -1
  105. package/dist/users/methods.js +2 -3
  106. package/dist/utils/configMigration.js +1 -1
  107. package/dist/utils/index.d.ts +1 -1
  108. package/dist/utils/index.js +1 -1
  109. package/dist/utils/loadConfigs.d.ts +2 -2
  110. package/dist/utils/loadConfigs.js +6 -7
  111. package/dist/utils/setupFiles.js +139 -141
  112. package/dist/utilsController.d.ts +16 -9
  113. package/dist/utilsController.js +93 -68
  114. package/package.json +9 -3
  115. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +0 -380
  116. package/.appwrite/.yaml_schemas/collection.schema.json +0 -255
  117. package/.appwrite/collections/Categories.yaml +0 -182
  118. package/.appwrite/collections/ExampleCollection.yaml +0 -36
  119. package/.appwrite/collections/Posts.yaml +0 -227
  120. package/.appwrite/collections/Users.yaml +0 -149
  121. package/.appwrite/config.yaml +0 -109
  122. package/.appwrite/import/README.md +0 -148
  123. package/.appwrite/import/categories-import.yaml +0 -129
  124. package/.appwrite/import/posts-import.yaml +0 -208
  125. package/.appwrite/import/users-import.yaml +0 -130
  126. package/.appwrite/importData/categories.json +0 -194
  127. package/.appwrite/importData/posts.json +0 -270
  128. package/.appwrite/importData/users.json +0 -220
  129. package/.appwrite/schemas/categories.json +0 -128
  130. package/.appwrite/schemas/exampleCollection.json +0 -52
  131. package/.appwrite/schemas/posts.json +0 -173
  132. package/.appwrite/schemas/users.json +0 -125
  133. package/CHANGELOG.md +0 -35
  134. package/CONFIG_TODO.md +0 -1189
  135. package/SELECTION_DIALOGS.md +0 -146
  136. package/SERVICE_IMPLEMENTATION_REPORT.md +0 -462
  137. package/dist/adapters/AdapterFactory.d.ts +0 -94
  138. package/dist/adapters/AdapterFactory.js +0 -420
  139. package/dist/adapters/DatabaseAdapter.d.ts +0 -243
  140. package/dist/adapters/DatabaseAdapter.js +0 -50
  141. package/dist/adapters/LegacyAdapter.d.ts +0 -50
  142. package/dist/adapters/LegacyAdapter.js +0 -615
  143. package/dist/adapters/TablesDBAdapter.d.ts +0 -45
  144. package/dist/adapters/TablesDBAdapter.js +0 -611
  145. package/dist/config/ConfigManager.d.ts +0 -450
  146. package/dist/config/ConfigManager.js +0 -650
  147. package/dist/config/configMigration.d.ts +0 -87
  148. package/dist/config/configMigration.js +0 -390
  149. package/dist/config/configValidation.d.ts +0 -66
  150. package/dist/config/configValidation.js +0 -358
  151. package/dist/config/index.d.ts +0 -8
  152. package/dist/config/index.js +0 -7
  153. package/dist/config/services/ConfigDiscoveryService.d.ts +0 -122
  154. package/dist/config/services/ConfigDiscoveryService.js +0 -322
  155. package/dist/config/services/ConfigLoaderService.d.ts +0 -129
  156. package/dist/config/services/ConfigLoaderService.js +0 -535
  157. package/dist/config/services/ConfigMergeService.d.ts +0 -208
  158. package/dist/config/services/ConfigMergeService.js +0 -308
  159. package/dist/config/services/ConfigValidationService.d.ts +0 -214
  160. package/dist/config/services/ConfigValidationService.js +0 -310
  161. package/dist/config/services/SessionAuthService.d.ts +0 -225
  162. package/dist/config/services/SessionAuthService.js +0 -456
  163. package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +0 -1
  164. package/dist/config/services/__tests__/ConfigMergeService.test.js +0 -271
  165. package/dist/config/services/index.d.ts +0 -13
  166. package/dist/config/services/index.js +0 -10
  167. package/dist/config/yamlConfig.d.ts +0 -722
  168. package/dist/config/yamlConfig.js +0 -702
  169. package/dist/functions/pathResolution.d.ts +0 -37
  170. package/dist/functions/pathResolution.js +0 -185
  171. package/dist/functions/templates/count-docs-in-collection/package.json +0 -25
  172. package/dist/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
  173. package/dist/functions/templates/hono-typescript/package.json +0 -26
  174. package/dist/functions/templates/hono-typescript/src/index.ts +0 -54
  175. package/dist/functions/templates/hono-typescript/tsconfig.json +0 -20
  176. package/dist/functions/templates/typescript-node/package.json +0 -25
  177. package/dist/functions/templates/typescript-node/tsconfig.json +0 -28
  178. package/dist/shared/attributeMapper.d.ts +0 -20
  179. package/dist/shared/attributeMapper.js +0 -203
  180. package/dist/shared/errorUtils.d.ts +0 -54
  181. package/dist/shared/errorUtils.js +0 -95
  182. package/dist/shared/functionManager.d.ts +0 -48
  183. package/dist/shared/functionManager.js +0 -348
  184. package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
  185. package/dist/shared/jsonSchemaGenerator.js +0 -290
  186. package/dist/shared/logging.d.ts +0 -61
  187. package/dist/shared/logging.js +0 -116
  188. package/dist/shared/messageFormatter.d.ts +0 -39
  189. package/dist/shared/messageFormatter.js +0 -162
  190. package/dist/shared/pydanticModelGenerator.d.ts +0 -17
  191. package/dist/shared/pydanticModelGenerator.js +0 -615
  192. package/dist/shared/schemaGenerator.d.ts +0 -40
  193. package/dist/shared/schemaGenerator.js +0 -556
  194. package/dist/utils/ClientFactory.d.ts +0 -87
  195. package/dist/utils/ClientFactory.js +0 -212
  196. package/dist/utils/configDiscovery.d.ts +0 -78
  197. package/dist/utils/configDiscovery.js +0 -472
  198. package/dist/utils/constantsGenerator.d.ts +0 -31
  199. package/dist/utils/constantsGenerator.js +0 -321
  200. package/dist/utils/dataConverters.d.ts +0 -46
  201. package/dist/utils/dataConverters.js +0 -139
  202. package/dist/utils/directoryUtils.d.ts +0 -22
  203. package/dist/utils/directoryUtils.js +0 -59
  204. package/dist/utils/getClientFromConfig.d.ts +0 -39
  205. package/dist/utils/getClientFromConfig.js +0 -199
  206. package/dist/utils/helperFunctions.d.ts +0 -63
  207. package/dist/utils/helperFunctions.js +0 -156
  208. package/dist/utils/pathResolvers.d.ts +0 -53
  209. package/dist/utils/pathResolvers.js +0 -72
  210. package/dist/utils/projectConfig.d.ts +0 -122
  211. package/dist/utils/projectConfig.js +0 -206
  212. package/dist/utils/retryFailedPromises.d.ts +0 -2
  213. package/dist/utils/retryFailedPromises.js +0 -23
  214. package/dist/utils/sessionAuth.d.ts +0 -48
  215. package/dist/utils/sessionAuth.js +0 -164
  216. package/dist/utils/typeGuards.d.ts +0 -35
  217. package/dist/utils/typeGuards.js +0 -57
  218. package/dist/utils/validationRules.d.ts +0 -43
  219. package/dist/utils/validationRules.js +0 -42
  220. package/dist/utils/versionDetection.d.ts +0 -58
  221. package/dist/utils/versionDetection.js +0 -251
  222. package/dist/utils/yamlConverter.d.ts +0 -100
  223. package/dist/utils/yamlConverter.js +0 -428
  224. package/dist/utils/yamlLoader.d.ts +0 -70
  225. package/dist/utils/yamlLoader.js +0 -267
  226. package/scripts/copy-templates.ts +0 -23
  227. package/src/adapters/AdapterFactory.ts +0 -529
  228. package/src/adapters/DatabaseAdapter.ts +0 -319
  229. package/src/adapters/LegacyAdapter.ts +0 -844
  230. package/src/adapters/TablesDBAdapter.ts +0 -823
  231. package/src/adapters/index.ts +0 -37
  232. package/src/backups/operations/bucketBackup.ts +0 -277
  233. package/src/backups/operations/collectionBackup.ts +0 -310
  234. package/src/backups/operations/comprehensiveBackup.ts +0 -342
  235. package/src/backups/schemas/bucketManifest.ts +0 -78
  236. package/src/backups/schemas/comprehensiveManifest.ts +0 -76
  237. package/src/backups/tracking/centralizedTracking.ts +0 -352
  238. package/src/cli/commands/configCommands.ts +0 -201
  239. package/src/cli/commands/databaseCommands.ts +0 -879
  240. package/src/cli/commands/functionCommands.ts +0 -418
  241. package/src/cli/commands/schemaCommands.ts +0 -200
  242. package/src/cli/commands/storageCommands.ts +0 -152
  243. package/src/cli/commands/transferCommands.ts +0 -457
  244. package/src/collections/attributes.ts +0 -2020
  245. package/src/collections/attributes.ts.backup +0 -1555
  246. package/src/collections/indexes.ts +0 -352
  247. package/src/collections/methods.ts +0 -700
  248. package/src/collections/tableOperations.ts +0 -521
  249. package/src/collections/transferOperations.ts +0 -590
  250. package/src/collections/wipeOperations.ts +0 -346
  251. package/src/config/ConfigManager.ts +0 -849
  252. package/src/config/README.md +0 -274
  253. package/src/config/configMigration.ts +0 -575
  254. package/src/config/configValidation.ts +0 -445
  255. package/src/config/index.ts +0 -10
  256. package/src/config/services/ConfigDiscoveryService.ts +0 -410
  257. package/src/config/services/ConfigLoaderService.ts +0 -732
  258. package/src/config/services/ConfigMergeService.ts +0 -388
  259. package/src/config/services/ConfigValidationService.ts +0 -394
  260. package/src/config/services/SessionAuthService.ts +0 -565
  261. package/src/config/services/__tests__/ConfigMergeService.test.ts +0 -351
  262. package/src/config/services/index.ts +0 -29
  263. package/src/config/yamlConfig.ts +0 -761
  264. package/src/databases/methods.ts +0 -49
  265. package/src/databases/setup.ts +0 -77
  266. package/src/examples/yamlTerminologyExample.ts +0 -346
  267. package/src/functions/deployments.ts +0 -220
  268. package/src/functions/fnConfigDiscovery.ts +0 -103
  269. package/src/functions/methods.ts +0 -284
  270. package/src/functions/pathResolution.ts +0 -227
  271. package/src/functions/templates/count-docs-in-collection/README.md +0 -54
  272. package/src/functions/templates/count-docs-in-collection/package.json +0 -25
  273. package/src/functions/templates/count-docs-in-collection/src/main.ts +0 -159
  274. package/src/functions/templates/count-docs-in-collection/src/request.ts +0 -9
  275. package/src/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
  276. package/src/functions/templates/hono-typescript/README.md +0 -286
  277. package/src/functions/templates/hono-typescript/package.json +0 -26
  278. package/src/functions/templates/hono-typescript/src/adapters/request.ts +0 -74
  279. package/src/functions/templates/hono-typescript/src/adapters/response.ts +0 -106
  280. package/src/functions/templates/hono-typescript/src/app.ts +0 -180
  281. package/src/functions/templates/hono-typescript/src/context.ts +0 -103
  282. package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -119
  283. package/src/functions/templates/hono-typescript/tsconfig.json +0 -20
  284. package/src/functions/templates/typescript-node/README.md +0 -32
  285. package/src/functions/templates/typescript-node/package.json +0 -25
  286. package/src/functions/templates/typescript-node/src/context.ts +0 -103
  287. package/src/functions/templates/typescript-node/src/index.ts +0 -29
  288. package/src/functions/templates/typescript-node/tsconfig.json +0 -28
  289. package/src/functions/templates/uv/README.md +0 -31
  290. package/src/functions/templates/uv/pyproject.toml +0 -30
  291. package/src/functions/templates/uv/src/__init__.py +0 -0
  292. package/src/functions/templates/uv/src/context.py +0 -125
  293. package/src/functions/templates/uv/src/index.py +0 -46
  294. package/src/init.ts +0 -62
  295. package/src/interactiveCLI.ts +0 -1136
  296. package/src/main.ts +0 -1670
  297. package/src/migrations/afterImportActions.ts +0 -580
  298. package/src/migrations/appwriteToX.ts +0 -664
  299. package/src/migrations/comprehensiveTransfer.ts +0 -2285
  300. package/src/migrations/dataLoader.ts +0 -1702
  301. package/src/migrations/importController.ts +0 -428
  302. package/src/migrations/importDataActions.ts +0 -315
  303. package/src/migrations/relationships.ts +0 -334
  304. package/src/migrations/services/DataTransformationService.ts +0 -196
  305. package/src/migrations/services/FileHandlerService.ts +0 -311
  306. package/src/migrations/services/ImportOrchestrator.ts +0 -666
  307. package/src/migrations/services/RateLimitManager.ts +0 -363
  308. package/src/migrations/services/RelationshipResolver.ts +0 -461
  309. package/src/migrations/services/UserMappingService.ts +0 -345
  310. package/src/migrations/services/ValidationService.ts +0 -349
  311. package/src/migrations/transfer.ts +0 -1068
  312. package/src/migrations/yaml/YamlImportConfigLoader.ts +0 -439
  313. package/src/migrations/yaml/YamlImportIntegration.ts +0 -446
  314. package/src/migrations/yaml/generateImportSchemas.ts +0 -1354
  315. package/src/schemas/authUser.ts +0 -23
  316. package/src/setup.ts +0 -8
  317. package/src/setupCommands.ts +0 -603
  318. package/src/setupController.ts +0 -43
  319. package/src/shared/attributeMapper.ts +0 -229
  320. package/src/shared/backupMetadataSchema.ts +0 -93
  321. package/src/shared/backupTracking.ts +0 -211
  322. package/src/shared/confirmationDialogs.ts +0 -327
  323. package/src/shared/errorUtils.ts +0 -110
  324. package/src/shared/functionManager.ts +0 -537
  325. package/src/shared/jsonSchemaGenerator.ts +0 -383
  326. package/src/shared/logging.ts +0 -149
  327. package/src/shared/messageFormatter.ts +0 -208
  328. package/src/shared/migrationHelpers.ts +0 -232
  329. package/src/shared/operationLogger.ts +0 -20
  330. package/src/shared/operationQueue.ts +0 -377
  331. package/src/shared/operationsTable.ts +0 -338
  332. package/src/shared/operationsTableSchema.ts +0 -60
  333. package/src/shared/progressManager.ts +0 -278
  334. package/src/shared/pydanticModelGenerator.ts +0 -618
  335. package/src/shared/relationshipExtractor.ts +0 -214
  336. package/src/shared/schemaGenerator.ts +0 -644
  337. package/src/shared/selectionDialogs.ts +0 -749
  338. package/src/storage/backupCompression.ts +0 -88
  339. package/src/storage/methods.ts +0 -698
  340. package/src/storage/schemas.ts +0 -205
  341. package/src/tables/indexManager.ts +0 -409
  342. package/src/types/node-appwrite-tablesdb.d.ts +0 -44
  343. package/src/types.ts +0 -9
  344. package/src/users/methods.ts +0 -359
  345. package/src/utils/ClientFactory.ts +0 -240
  346. package/src/utils/configDiscovery.ts +0 -557
  347. package/src/utils/configMigration.ts +0 -348
  348. package/src/utils/constantsGenerator.ts +0 -369
  349. package/src/utils/dataConverters.ts +0 -159
  350. package/src/utils/directoryUtils.ts +0 -61
  351. package/src/utils/getClientFromConfig.ts +0 -257
  352. package/src/utils/helperFunctions.ts +0 -228
  353. package/src/utils/index.ts +0 -2
  354. package/src/utils/loadConfigs.ts +0 -449
  355. package/src/utils/pathResolvers.ts +0 -81
  356. package/src/utils/projectConfig.ts +0 -340
  357. package/src/utils/retryFailedPromises.ts +0 -29
  358. package/src/utils/sessionAuth.ts +0 -230
  359. package/src/utils/setupFiles.ts +0 -1238
  360. package/src/utils/typeGuards.ts +0 -65
  361. package/src/utils/validationRules.ts +0 -88
  362. package/src/utils/versionDetection.ts +0 -292
  363. package/src/utils/yamlConverter.ts +0 -542
  364. package/src/utils/yamlLoader.ts +0 -371
  365. package/src/utilsController.ts +0 -1213
  366. package/tests/README.md +0 -497
  367. package/tests/adapters/AdapterFactory.test.ts +0 -277
  368. package/tests/integration/syncOperations.test.ts +0 -463
  369. package/tests/jest.config.js +0 -25
  370. package/tests/migration/configMigration.test.ts +0 -546
  371. package/tests/setup.ts +0 -62
  372. package/tests/testUtils.ts +0 -340
  373. package/tests/utils/loadConfigs.test.ts +0 -350
  374. package/tests/validation/configValidation.test.ts +0 -412
  375. package/tmp-sync-test/.appwrite/collections/TestCollection.yaml +0 -7
  376. package/tsconfig.json +0 -44
@@ -1,1238 +0,0 @@
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
- };