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