@njdamstra/appwrite-utils-cli 1.8.9

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