appwrite-utils-cli 1.9.6 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (426) hide show
  1. package/CONFIG_TODO.md +1189 -1189
  2. package/README.md +1004 -1004
  3. package/SELECTION_DIALOGS.md +145 -145
  4. package/SERVICE_IMPLEMENTATION_REPORT.md +462 -462
  5. package/package.json +6 -3
  6. package/scripts/copy-templates.ts +23 -23
  7. package/src/adapters/index.ts +11 -37
  8. package/src/backups/operations/bucketBackup.ts +277 -277
  9. package/src/backups/operations/collectionBackup.ts +310 -310
  10. package/src/backups/operations/comprehensiveBackup.ts +342 -342
  11. package/src/backups/schemas/bucketManifest.ts +78 -78
  12. package/src/backups/schemas/comprehensiveManifest.ts +76 -76
  13. package/src/backups/tracking/centralizedTracking.ts +352 -352
  14. package/src/cli/commands/configCommands.ts +265 -201
  15. package/src/cli/commands/databaseCommands.ts +931 -879
  16. package/src/cli/commands/functionCommands.ts +333 -332
  17. package/src/cli/commands/importFileCommands.ts +815 -0
  18. package/src/cli/commands/schemaCommands.ts +141 -141
  19. package/src/cli/commands/storageCommands.ts +2 -3
  20. package/src/cli/commands/transferCommands.ts +454 -457
  21. package/src/collections/attributes.ts.backup +1555 -1555
  22. package/src/collections/{attributes.ts → columns.ts} +15 -44
  23. package/src/collections/indexes.ts +350 -352
  24. package/src/collections/methods.ts +714 -815
  25. package/src/collections/tableOperations.ts +57 -21
  26. package/src/collections/transferOperations.ts +376 -377
  27. package/src/collections/wipeOperations.ts +449 -346
  28. package/src/databases/methods.ts +49 -49
  29. package/src/databases/setup.ts +77 -77
  30. package/src/examples/yamlTerminologyExample.ts +346 -346
  31. package/src/functions/deployments.ts +221 -220
  32. package/src/functions/fnConfigDiscovery.ts +2 -2
  33. package/src/functions/methods.ts +284 -284
  34. package/src/functions/templates/count-docs-in-collection/README.md +53 -53
  35. package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -159
  36. package/src/functions/templates/count-docs-in-collection/src/request.ts +8 -8
  37. package/src/functions/templates/hono-typescript/README.md +285 -285
  38. package/src/functions/templates/hono-typescript/src/adapters/request.ts +73 -73
  39. package/src/functions/templates/hono-typescript/src/adapters/response.ts +105 -105
  40. package/src/functions/templates/hono-typescript/src/app.ts +179 -179
  41. package/src/functions/templates/hono-typescript/src/context.ts +102 -102
  42. package/src/functions/templates/hono-typescript/src/{index.ts → main.ts} +53 -53
  43. package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +118 -118
  44. package/src/functions/templates/typescript-node/README.md +31 -31
  45. package/src/functions/templates/typescript-node/src/context.ts +102 -102
  46. package/src/functions/templates/typescript-node/src/{index.ts → main.ts} +29 -29
  47. package/src/functions/templates/uv/README.md +30 -30
  48. package/src/functions/templates/uv/pyproject.toml +29 -29
  49. package/src/functions/templates/uv/src/context.py +124 -124
  50. package/src/functions/templates/uv/src/{index.py → main.py} +45 -45
  51. package/src/init.ts +62 -62
  52. package/src/interactiveCLI.ts +1095 -1030
  53. package/src/main.ts +1517 -1670
  54. package/src/migrations/afterImportActions.ts +579 -580
  55. package/src/migrations/appwriteToX.ts +634 -630
  56. package/src/migrations/comprehensiveTransfer.ts +2149 -2149
  57. package/src/migrations/dataLoader.ts +1729 -1702
  58. package/src/migrations/importController.ts +440 -428
  59. package/src/migrations/importDataActions.ts +315 -315
  60. package/src/migrations/relationships.ts +333 -334
  61. package/src/migrations/services/DataTransformationService.ts +195 -195
  62. package/src/migrations/services/FileHandlerService.ts +310 -310
  63. package/src/migrations/services/ImportOrchestrator.ts +674 -665
  64. package/src/migrations/services/RateLimitManager.ts +362 -362
  65. package/src/migrations/services/RelationshipResolver.ts +460 -460
  66. package/src/migrations/services/UserMappingService.ts +344 -344
  67. package/src/migrations/services/ValidationService.ts +333 -333
  68. package/src/migrations/transfer.ts +987 -942
  69. package/src/migrations/yaml/YamlImportConfigLoader.ts +438 -438
  70. package/src/migrations/yaml/YamlImportIntegration.ts +438 -438
  71. package/src/migrations/yaml/generateImportSchemas.ts +1347 -1347
  72. package/src/schemas/authUser.ts +23 -23
  73. package/src/setup.ts +8 -8
  74. package/src/setupCommands.ts +5 -6
  75. package/src/setupController.ts +42 -42
  76. package/src/shared/backupMetadataSchema.ts +93 -93
  77. package/src/shared/backupTracking.ts +211 -211
  78. package/src/shared/confirmationDialogs.ts +326 -326
  79. package/src/shared/migrationHelpers.ts +232 -232
  80. package/src/shared/operationLogger.ts +20 -20
  81. package/src/shared/operationQueue.ts +326 -327
  82. package/src/shared/operationsTable.ts +338 -338
  83. package/src/shared/operationsTableSchema.ts +60 -60
  84. package/src/shared/progressManager.ts +277 -277
  85. package/src/shared/relationshipExtractor.ts +214 -214
  86. package/src/shared/selectionDialogs.ts +775 -722
  87. package/src/storage/backupCompression.ts +88 -88
  88. package/src/storage/methods.ts +695 -682
  89. package/src/storage/schemas.ts +205 -205
  90. package/src/tables/indexManager.ts +409 -0
  91. package/src/types/node-appwrite-tablesdb.d.ts +43 -43
  92. package/src/types.ts +9 -9
  93. package/src/users/methods.ts +358 -359
  94. package/src/utils/configMigration.ts +347 -347
  95. package/src/utils/index.ts +2 -2
  96. package/src/utils/loadConfigs.ts +457 -449
  97. package/src/utils/setupFiles.ts +1236 -1238
  98. package/src/utilsController.ts +1263 -1213
  99. package/tests/README.md +496 -496
  100. package/tests/adapters/AdapterFactory.test.ts +276 -276
  101. package/tests/integration/syncOperations.test.ts +462 -462
  102. package/tests/jest.config.js +24 -24
  103. package/tests/migration/configMigration.test.ts +545 -545
  104. package/tests/setup.ts +61 -61
  105. package/tests/testUtils.ts +339 -339
  106. package/tests/utils/loadConfigs.test.ts +349 -349
  107. package/tests/validation/configValidation.test.ts +411 -411
  108. package/tsconfig.json +44 -44
  109. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +0 -380
  110. package/.appwrite/.yaml_schemas/collection.schema.json +0 -255
  111. package/.appwrite/collections/Categories.yaml +0 -182
  112. package/.appwrite/collections/ExampleCollection.yaml +0 -36
  113. package/.appwrite/collections/Posts.yaml +0 -227
  114. package/.appwrite/collections/Users.yaml +0 -149
  115. package/.appwrite/config.yaml +0 -109
  116. package/.appwrite/import/README.md +0 -148
  117. package/.appwrite/import/categories-import.yaml +0 -129
  118. package/.appwrite/import/posts-import.yaml +0 -208
  119. package/.appwrite/import/users-import.yaml +0 -130
  120. package/.appwrite/importData/categories.json +0 -194
  121. package/.appwrite/importData/posts.json +0 -270
  122. package/.appwrite/importData/users.json +0 -220
  123. package/.appwrite/schemas/categories.json +0 -128
  124. package/.appwrite/schemas/exampleCollection.json +0 -52
  125. package/.appwrite/schemas/posts.json +0 -173
  126. package/.appwrite/schemas/users.json +0 -125
  127. package/dist/adapters/AdapterFactory.d.ts +0 -94
  128. package/dist/adapters/AdapterFactory.js +0 -405
  129. package/dist/adapters/DatabaseAdapter.d.ts +0 -242
  130. package/dist/adapters/DatabaseAdapter.js +0 -50
  131. package/dist/adapters/LegacyAdapter.d.ts +0 -50
  132. package/dist/adapters/LegacyAdapter.js +0 -612
  133. package/dist/adapters/TablesDBAdapter.d.ts +0 -45
  134. package/dist/adapters/TablesDBAdapter.js +0 -596
  135. package/dist/adapters/index.d.ts +0 -11
  136. package/dist/adapters/index.js +0 -12
  137. package/dist/backups/operations/bucketBackup.d.ts +0 -19
  138. package/dist/backups/operations/bucketBackup.js +0 -197
  139. package/dist/backups/operations/collectionBackup.d.ts +0 -30
  140. package/dist/backups/operations/collectionBackup.js +0 -201
  141. package/dist/backups/operations/comprehensiveBackup.d.ts +0 -25
  142. package/dist/backups/operations/comprehensiveBackup.js +0 -238
  143. package/dist/backups/schemas/bucketManifest.d.ts +0 -93
  144. package/dist/backups/schemas/bucketManifest.js +0 -33
  145. package/dist/backups/schemas/comprehensiveManifest.d.ts +0 -108
  146. package/dist/backups/schemas/comprehensiveManifest.js +0 -32
  147. package/dist/backups/tracking/centralizedTracking.d.ts +0 -34
  148. package/dist/backups/tracking/centralizedTracking.js +0 -274
  149. package/dist/cli/commands/configCommands.d.ts +0 -8
  150. package/dist/cli/commands/configCommands.js +0 -166
  151. package/dist/cli/commands/databaseCommands.d.ts +0 -14
  152. package/dist/cli/commands/databaseCommands.js +0 -644
  153. package/dist/cli/commands/functionCommands.d.ts +0 -7
  154. package/dist/cli/commands/functionCommands.js +0 -330
  155. package/dist/cli/commands/schemaCommands.d.ts +0 -7
  156. package/dist/cli/commands/schemaCommands.js +0 -169
  157. package/dist/cli/commands/storageCommands.d.ts +0 -5
  158. package/dist/cli/commands/storageCommands.js +0 -143
  159. package/dist/cli/commands/transferCommands.d.ts +0 -5
  160. package/dist/cli/commands/transferCommands.js +0 -384
  161. package/dist/collections/attributes.d.ts +0 -13
  162. package/dist/collections/attributes.js +0 -1364
  163. package/dist/collections/indexes.d.ts +0 -12
  164. package/dist/collections/indexes.js +0 -217
  165. package/dist/collections/methods.d.ts +0 -19
  166. package/dist/collections/methods.js +0 -734
  167. package/dist/collections/tableOperations.d.ts +0 -86
  168. package/dist/collections/tableOperations.js +0 -434
  169. package/dist/collections/transferOperations.d.ts +0 -8
  170. package/dist/collections/transferOperations.js +0 -412
  171. package/dist/collections/wipeOperations.d.ts +0 -16
  172. package/dist/collections/wipeOperations.js +0 -233
  173. package/dist/config/ConfigManager.d.ts +0 -450
  174. package/dist/config/ConfigManager.js +0 -625
  175. package/dist/config/configMigration.d.ts +0 -87
  176. package/dist/config/configMigration.js +0 -390
  177. package/dist/config/configValidation.d.ts +0 -66
  178. package/dist/config/configValidation.js +0 -358
  179. package/dist/config/index.d.ts +0 -8
  180. package/dist/config/index.js +0 -7
  181. package/dist/config/services/ConfigDiscoveryService.d.ts +0 -122
  182. package/dist/config/services/ConfigDiscoveryService.js +0 -322
  183. package/dist/config/services/ConfigLoaderService.d.ts +0 -129
  184. package/dist/config/services/ConfigLoaderService.js +0 -535
  185. package/dist/config/services/ConfigMergeService.d.ts +0 -208
  186. package/dist/config/services/ConfigMergeService.js +0 -308
  187. package/dist/config/services/ConfigValidationService.d.ts +0 -214
  188. package/dist/config/services/ConfigValidationService.js +0 -310
  189. package/dist/config/services/SessionAuthService.d.ts +0 -225
  190. package/dist/config/services/SessionAuthService.js +0 -456
  191. package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +0 -1
  192. package/dist/config/services/__tests__/ConfigMergeService.test.js +0 -271
  193. package/dist/config/services/index.d.ts +0 -13
  194. package/dist/config/services/index.js +0 -10
  195. package/dist/config/yamlConfig.d.ts +0 -722
  196. package/dist/config/yamlConfig.js +0 -702
  197. package/dist/databases/methods.d.ts +0 -6
  198. package/dist/databases/methods.js +0 -35
  199. package/dist/databases/setup.d.ts +0 -5
  200. package/dist/databases/setup.js +0 -45
  201. package/dist/examples/yamlTerminologyExample.d.ts +0 -42
  202. package/dist/examples/yamlTerminologyExample.js +0 -272
  203. package/dist/functions/deployments.d.ts +0 -4
  204. package/dist/functions/deployments.js +0 -146
  205. package/dist/functions/fnConfigDiscovery.d.ts +0 -3
  206. package/dist/functions/fnConfigDiscovery.js +0 -108
  207. package/dist/functions/methods.d.ts +0 -16
  208. package/dist/functions/methods.js +0 -174
  209. package/dist/functions/pathResolution.d.ts +0 -37
  210. package/dist/functions/pathResolution.js +0 -185
  211. package/dist/functions/templates/count-docs-in-collection/README.md +0 -54
  212. package/dist/functions/templates/count-docs-in-collection/package.json +0 -25
  213. package/dist/functions/templates/count-docs-in-collection/src/main.ts +0 -159
  214. package/dist/functions/templates/count-docs-in-collection/src/request.ts +0 -9
  215. package/dist/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
  216. package/dist/functions/templates/hono-typescript/README.md +0 -286
  217. package/dist/functions/templates/hono-typescript/package.json +0 -26
  218. package/dist/functions/templates/hono-typescript/src/adapters/request.ts +0 -74
  219. package/dist/functions/templates/hono-typescript/src/adapters/response.ts +0 -106
  220. package/dist/functions/templates/hono-typescript/src/app.ts +0 -180
  221. package/dist/functions/templates/hono-typescript/src/context.ts +0 -103
  222. package/dist/functions/templates/hono-typescript/src/index.ts +0 -54
  223. package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -119
  224. package/dist/functions/templates/hono-typescript/tsconfig.json +0 -20
  225. package/dist/functions/templates/typescript-node/README.md +0 -32
  226. package/dist/functions/templates/typescript-node/package.json +0 -25
  227. package/dist/functions/templates/typescript-node/src/context.ts +0 -103
  228. package/dist/functions/templates/typescript-node/src/index.ts +0 -29
  229. package/dist/functions/templates/typescript-node/tsconfig.json +0 -28
  230. package/dist/functions/templates/uv/README.md +0 -31
  231. package/dist/functions/templates/uv/pyproject.toml +0 -30
  232. package/dist/functions/templates/uv/src/__init__.py +0 -0
  233. package/dist/functions/templates/uv/src/context.py +0 -125
  234. package/dist/functions/templates/uv/src/index.py +0 -46
  235. package/dist/init.d.ts +0 -2
  236. package/dist/init.js +0 -57
  237. package/dist/interactiveCLI.d.ts +0 -31
  238. package/dist/interactiveCLI.js +0 -898
  239. package/dist/main.d.ts +0 -2
  240. package/dist/main.js +0 -1180
  241. package/dist/migrations/afterImportActions.d.ts +0 -17
  242. package/dist/migrations/afterImportActions.js +0 -306
  243. package/dist/migrations/appwriteToX.d.ts +0 -211
  244. package/dist/migrations/appwriteToX.js +0 -491
  245. package/dist/migrations/comprehensiveTransfer.d.ts +0 -147
  246. package/dist/migrations/comprehensiveTransfer.js +0 -1317
  247. package/dist/migrations/dataLoader.d.ts +0 -753
  248. package/dist/migrations/dataLoader.js +0 -1250
  249. package/dist/migrations/importController.d.ts +0 -23
  250. package/dist/migrations/importController.js +0 -268
  251. package/dist/migrations/importDataActions.d.ts +0 -50
  252. package/dist/migrations/importDataActions.js +0 -230
  253. package/dist/migrations/relationships.d.ts +0 -29
  254. package/dist/migrations/relationships.js +0 -204
  255. package/dist/migrations/services/DataTransformationService.d.ts +0 -55
  256. package/dist/migrations/services/DataTransformationService.js +0 -158
  257. package/dist/migrations/services/FileHandlerService.d.ts +0 -75
  258. package/dist/migrations/services/FileHandlerService.js +0 -236
  259. package/dist/migrations/services/ImportOrchestrator.d.ts +0 -97
  260. package/dist/migrations/services/ImportOrchestrator.js +0 -485
  261. package/dist/migrations/services/RateLimitManager.d.ts +0 -138
  262. package/dist/migrations/services/RateLimitManager.js +0 -279
  263. package/dist/migrations/services/RelationshipResolver.d.ts +0 -120
  264. package/dist/migrations/services/RelationshipResolver.js +0 -332
  265. package/dist/migrations/services/UserMappingService.d.ts +0 -109
  266. package/dist/migrations/services/UserMappingService.js +0 -277
  267. package/dist/migrations/services/ValidationService.d.ts +0 -74
  268. package/dist/migrations/services/ValidationService.js +0 -260
  269. package/dist/migrations/transfer.d.ts +0 -26
  270. package/dist/migrations/transfer.js +0 -608
  271. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +0 -131
  272. package/dist/migrations/yaml/YamlImportConfigLoader.js +0 -383
  273. package/dist/migrations/yaml/YamlImportIntegration.d.ts +0 -93
  274. package/dist/migrations/yaml/YamlImportIntegration.js +0 -341
  275. package/dist/migrations/yaml/generateImportSchemas.d.ts +0 -30
  276. package/dist/migrations/yaml/generateImportSchemas.js +0 -1327
  277. package/dist/schemas/authUser.d.ts +0 -24
  278. package/dist/schemas/authUser.js +0 -17
  279. package/dist/setup.d.ts +0 -2
  280. package/dist/setup.js +0 -5
  281. package/dist/setupCommands.d.ts +0 -58
  282. package/dist/setupCommands.js +0 -490
  283. package/dist/setupController.d.ts +0 -9
  284. package/dist/setupController.js +0 -34
  285. package/dist/shared/attributeMapper.d.ts +0 -20
  286. package/dist/shared/attributeMapper.js +0 -203
  287. package/dist/shared/backupMetadataSchema.d.ts +0 -94
  288. package/dist/shared/backupMetadataSchema.js +0 -38
  289. package/dist/shared/backupTracking.d.ts +0 -18
  290. package/dist/shared/backupTracking.js +0 -176
  291. package/dist/shared/confirmationDialogs.d.ts +0 -75
  292. package/dist/shared/confirmationDialogs.js +0 -236
  293. package/dist/shared/errorUtils.d.ts +0 -54
  294. package/dist/shared/errorUtils.js +0 -95
  295. package/dist/shared/functionManager.d.ts +0 -48
  296. package/dist/shared/functionManager.js +0 -348
  297. package/dist/shared/indexManager.d.ts +0 -24
  298. package/dist/shared/indexManager.js +0 -151
  299. package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
  300. package/dist/shared/jsonSchemaGenerator.js +0 -290
  301. package/dist/shared/logging.d.ts +0 -61
  302. package/dist/shared/logging.js +0 -116
  303. package/dist/shared/messageFormatter.d.ts +0 -39
  304. package/dist/shared/messageFormatter.js +0 -162
  305. package/dist/shared/migrationHelpers.d.ts +0 -61
  306. package/dist/shared/migrationHelpers.js +0 -145
  307. package/dist/shared/operationLogger.d.ts +0 -10
  308. package/dist/shared/operationLogger.js +0 -12
  309. package/dist/shared/operationQueue.d.ts +0 -40
  310. package/dist/shared/operationQueue.js +0 -311
  311. package/dist/shared/operationsTable.d.ts +0 -26
  312. package/dist/shared/operationsTable.js +0 -286
  313. package/dist/shared/operationsTableSchema.d.ts +0 -48
  314. package/dist/shared/operationsTableSchema.js +0 -35
  315. package/dist/shared/progressManager.d.ts +0 -62
  316. package/dist/shared/progressManager.js +0 -215
  317. package/dist/shared/pydanticModelGenerator.d.ts +0 -17
  318. package/dist/shared/pydanticModelGenerator.js +0 -615
  319. package/dist/shared/relationshipExtractor.d.ts +0 -56
  320. package/dist/shared/relationshipExtractor.js +0 -138
  321. package/dist/shared/schemaGenerator.d.ts +0 -40
  322. package/dist/shared/schemaGenerator.js +0 -556
  323. package/dist/shared/selectionDialogs.d.ts +0 -214
  324. package/dist/shared/selectionDialogs.js +0 -544
  325. package/dist/storage/backupCompression.d.ts +0 -20
  326. package/dist/storage/backupCompression.js +0 -67
  327. package/dist/storage/methods.d.ts +0 -32
  328. package/dist/storage/methods.js +0 -472
  329. package/dist/storage/schemas.d.ts +0 -842
  330. package/dist/storage/schemas.js +0 -175
  331. package/dist/types.d.ts +0 -4
  332. package/dist/types.js +0 -3
  333. package/dist/users/methods.d.ts +0 -16
  334. package/dist/users/methods.js +0 -277
  335. package/dist/utils/ClientFactory.d.ts +0 -87
  336. package/dist/utils/ClientFactory.js +0 -212
  337. package/dist/utils/configDiscovery.d.ts +0 -78
  338. package/dist/utils/configDiscovery.js +0 -472
  339. package/dist/utils/configMigration.d.ts +0 -1
  340. package/dist/utils/configMigration.js +0 -261
  341. package/dist/utils/constantsGenerator.d.ts +0 -31
  342. package/dist/utils/constantsGenerator.js +0 -321
  343. package/dist/utils/dataConverters.d.ts +0 -46
  344. package/dist/utils/dataConverters.js +0 -139
  345. package/dist/utils/directoryUtils.d.ts +0 -22
  346. package/dist/utils/directoryUtils.js +0 -59
  347. package/dist/utils/getClientFromConfig.d.ts +0 -39
  348. package/dist/utils/getClientFromConfig.js +0 -199
  349. package/dist/utils/helperFunctions.d.ts +0 -63
  350. package/dist/utils/helperFunctions.js +0 -156
  351. package/dist/utils/index.d.ts +0 -2
  352. package/dist/utils/index.js +0 -2
  353. package/dist/utils/loadConfigs.d.ts +0 -50
  354. package/dist/utils/loadConfigs.js +0 -358
  355. package/dist/utils/pathResolvers.d.ts +0 -53
  356. package/dist/utils/pathResolvers.js +0 -72
  357. package/dist/utils/projectConfig.d.ts +0 -122
  358. package/dist/utils/projectConfig.js +0 -206
  359. package/dist/utils/retryFailedPromises.d.ts +0 -2
  360. package/dist/utils/retryFailedPromises.js +0 -23
  361. package/dist/utils/sessionAuth.d.ts +0 -48
  362. package/dist/utils/sessionAuth.js +0 -164
  363. package/dist/utils/setupFiles.d.ts +0 -4
  364. package/dist/utils/setupFiles.js +0 -1192
  365. package/dist/utils/typeGuards.d.ts +0 -35
  366. package/dist/utils/typeGuards.js +0 -57
  367. package/dist/utils/validationRules.d.ts +0 -43
  368. package/dist/utils/validationRules.js +0 -42
  369. package/dist/utils/versionDetection.d.ts +0 -58
  370. package/dist/utils/versionDetection.js +0 -251
  371. package/dist/utils/yamlConverter.d.ts +0 -100
  372. package/dist/utils/yamlConverter.js +0 -428
  373. package/dist/utils/yamlLoader.d.ts +0 -70
  374. package/dist/utils/yamlLoader.js +0 -267
  375. package/dist/utilsController.d.ts +0 -107
  376. package/dist/utilsController.js +0 -873
  377. package/src/adapters/AdapterFactory.ts +0 -510
  378. package/src/adapters/DatabaseAdapter.ts +0 -318
  379. package/src/adapters/LegacyAdapter.ts +0 -841
  380. package/src/adapters/TablesDBAdapter.ts +0 -815
  381. package/src/config/ConfigManager.ts +0 -817
  382. package/src/config/README.md +0 -274
  383. package/src/config/configMigration.ts +0 -575
  384. package/src/config/configValidation.ts +0 -445
  385. package/src/config/index.ts +0 -10
  386. package/src/config/services/ConfigDiscoveryService.ts +0 -410
  387. package/src/config/services/ConfigLoaderService.ts +0 -732
  388. package/src/config/services/ConfigMergeService.ts +0 -388
  389. package/src/config/services/ConfigValidationService.ts +0 -394
  390. package/src/config/services/SessionAuthService.ts +0 -565
  391. package/src/config/services/__tests__/ConfigMergeService.test.ts +0 -351
  392. package/src/config/services/index.ts +0 -29
  393. package/src/config/yamlConfig.ts +0 -761
  394. package/src/functions/pathResolution.ts +0 -227
  395. package/src/functions/templates/count-docs-in-collection/package.json +0 -25
  396. package/src/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
  397. package/src/functions/templates/hono-typescript/package.json +0 -26
  398. package/src/functions/templates/hono-typescript/tsconfig.json +0 -20
  399. package/src/functions/templates/typescript-node/package.json +0 -25
  400. package/src/functions/templates/typescript-node/tsconfig.json +0 -28
  401. package/src/shared/attributeMapper.ts +0 -229
  402. package/src/shared/errorUtils.ts +0 -110
  403. package/src/shared/functionManager.ts +0 -537
  404. package/src/shared/indexManager.ts +0 -254
  405. package/src/shared/jsonSchemaGenerator.ts +0 -383
  406. package/src/shared/logging.ts +0 -149
  407. package/src/shared/messageFormatter.ts +0 -208
  408. package/src/shared/pydanticModelGenerator.ts +0 -618
  409. package/src/shared/schemaGenerator.ts +0 -644
  410. package/src/utils/ClientFactory.ts +0 -240
  411. package/src/utils/configDiscovery.ts +0 -557
  412. package/src/utils/constantsGenerator.ts +0 -369
  413. package/src/utils/dataConverters.ts +0 -159
  414. package/src/utils/directoryUtils.ts +0 -61
  415. package/src/utils/getClientFromConfig.ts +0 -257
  416. package/src/utils/helperFunctions.ts +0 -228
  417. package/src/utils/pathResolvers.ts +0 -81
  418. package/src/utils/projectConfig.ts +0 -340
  419. package/src/utils/retryFailedPromises.ts +0 -29
  420. package/src/utils/sessionAuth.ts +0 -230
  421. package/src/utils/typeGuards.ts +0 -65
  422. package/src/utils/validationRules.ts +0 -88
  423. package/src/utils/versionDetection.ts +0 -292
  424. package/src/utils/yamlConverter.ts +0 -542
  425. package/src/utils/yamlLoader.ts +0 -371
  426. package/tmp-sync-test/.appwrite/collections/TestCollection.yaml +0 -7
@@ -1,815 +0,0 @@
1
- /**
2
- * TablesDBAdapter - Native TablesDB API Implementation
3
- *
4
- * This adapter provides direct access to the new Appwrite TablesDB API
5
- * without any translation layer. It uses object notation parameters
6
- * and returns Models.Row instead of Models.Document.
7
- */
8
-
9
- import { IndexType, Query, RelationMutate, RelationshipType, type Models } from "node-appwrite";
10
- import { chunk } from "es-toolkit";
11
- import {
12
- BaseAdapter,
13
- type DatabaseAdapter,
14
- type CreateRowParams,
15
- type UpdateRowParams,
16
- type ListRowsParams,
17
- type DeleteRowParams,
18
- type CreateTableParams,
19
- type UpdateTableParams,
20
- type ListTablesParams,
21
- type DeleteTableParams,
22
- type GetTableParams,
23
- type BulkCreateRowsParams,
24
- type BulkUpsertRowsParams,
25
- type BulkDeleteRowsParams,
26
- type CreateIndexParams,
27
- type ListIndexesParams,
28
- type DeleteIndexParams,
29
- type CreateAttributeParams,
30
- type UpdateAttributeParams,
31
- type DeleteAttributeParams,
32
- type ApiResponse,
33
- type AdapterMetadata,
34
- AdapterError
35
- } from './DatabaseAdapter.js';
36
- import { TablesDB, Client } from "node-appwrite";
37
-
38
- /**
39
- * TablesDBAdapter implementation for native TablesDB API
40
- */
41
- export class TablesDBAdapter extends BaseAdapter {
42
- private tablesDB: TablesDB;
43
-
44
- constructor(client: Client) {
45
- super(client, 'tablesdb');
46
- // Assuming TablesDB service is available on the client
47
- this.tablesDB = new TablesDB(client);
48
- }
49
-
50
- // Row (Document) Operations
51
- async listRows(params: ListRowsParams): Promise<ApiResponse> {
52
- try {
53
- const result = await this.tablesDB.listRows({
54
- tableId: params.tableId,
55
- databaseId: params.databaseId,
56
- queries: params.queries || [],
57
- });
58
- return {
59
- data: result.rows,
60
- rows: result.rows,
61
- total: result.total
62
- };
63
- } catch (error) {
64
- throw new AdapterError(
65
- `Failed to list rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
66
- 'LIST_ROWS_FAILED',
67
- error instanceof Error ? error : undefined
68
- );
69
- }
70
- }
71
-
72
- async createRow(params: CreateRowParams): Promise<ApiResponse> {
73
- try {
74
- // Remap 'id' to 'rowId' for TablesDB SDK compatibility
75
- const result = await this.tablesDB.createRow({
76
- databaseId: params.databaseId,
77
- tableId: params.tableId,
78
- rowId: params.id,
79
- data: params.data,
80
- permissions: params.permissions
81
- });
82
- return {
83
- data: result,
84
- rows: [result]
85
- };
86
- } catch (error) {
87
- throw new AdapterError(
88
- `Failed to create row: ${error instanceof Error ? error.message : 'Unknown error'}`,
89
- 'CREATE_ROW_FAILED',
90
- error instanceof Error ? error : undefined
91
- );
92
- }
93
- }
94
-
95
- async updateRow(params: UpdateRowParams): Promise<ApiResponse> {
96
- try {
97
- const result = await this.tablesDB.updateRow(
98
- params.databaseId,
99
- params.tableId,
100
- params.id,
101
- params.data,
102
- params.permissions || []
103
- );
104
- return {
105
- data: result,
106
- rows: [result]
107
- };
108
- } catch (error) {
109
- throw new AdapterError(
110
- `Failed to update row: ${error instanceof Error ? error.message : 'Unknown error'}`,
111
- 'UPDATE_ROW_FAILED',
112
- error instanceof Error ? error : undefined
113
- );
114
- }
115
- }
116
-
117
- async deleteRow(params: DeleteRowParams): Promise<ApiResponse> {
118
- try {
119
- const result = await this.tablesDB.deleteRow(
120
- params.databaseId,
121
- params.tableId,
122
- params.id
123
- );
124
- return { data: result };
125
- } catch (error) {
126
- throw new AdapterError(
127
- `Failed to delete row: ${error instanceof Error ? error.message : 'Unknown error'}`,
128
- 'DELETE_ROW_FAILED',
129
- error instanceof Error ? error : undefined
130
- );
131
- }
132
- }
133
-
134
- async getRow(params: { databaseId: string; tableId: string; id: string }): Promise<ApiResponse> {
135
- try {
136
- const result = await this.tablesDB.getRow(
137
- params.databaseId,
138
- params.tableId,
139
- params.id
140
- );
141
- return {
142
- data: result,
143
- rows: [result]
144
- };
145
- } catch (error) {
146
- throw new AdapterError(
147
- `Failed to get row: ${error instanceof Error ? error.message : 'Unknown error'}`,
148
- 'GET_ROW_FAILED',
149
- error instanceof Error ? error : undefined
150
- );
151
- }
152
- }
153
-
154
- // Table (Collection) Operations
155
- async listTables(params: ListTablesParams): Promise<ApiResponse> {
156
- try {
157
- const result = await this.tablesDB.listTables(params);
158
- return {
159
- data: result.tables,
160
- tables: result.tables,
161
- total: result.total
162
- };
163
- } catch (error) {
164
- throw new AdapterError(
165
- `Failed to list tables: ${error instanceof Error ? error.message : 'Unknown error'}`,
166
- 'LIST_TABLES_FAILED',
167
- error instanceof Error ? error : undefined
168
- );
169
- }
170
- }
171
-
172
- async createTable(params: CreateTableParams): Promise<ApiResponse> {
173
- try {
174
- const rowSecurity = params.rowSecurity ?? params.documentSecurity ?? false;
175
- const result = await this.tablesDB.createTable(
176
- params.databaseId,
177
- params.id, // tableId
178
- params.name,
179
- params.permissions || [],
180
- rowSecurity,
181
- params.enabled ?? true
182
- );
183
- return {
184
- data: result,
185
- tables: [result]
186
- };
187
- } catch (error) {
188
- throw new AdapterError(
189
- `Failed to create table: ${error instanceof Error ? error.message : 'Unknown error'}`,
190
- 'CREATE_TABLE_FAILED',
191
- error instanceof Error ? error : undefined
192
- );
193
- }
194
- }
195
-
196
- async updateTable(params: UpdateTableParams): Promise<ApiResponse> {
197
- try {
198
- const rowSecurity = params.rowSecurity ?? params.documentSecurity;
199
- const result = await this.tablesDB.updateTable(
200
- params.databaseId,
201
- params.id, // tableId
202
- params.name,
203
- params.permissions,
204
- rowSecurity,
205
- params.enabled
206
- );
207
- return {
208
- data: result,
209
- tables: [result]
210
- };
211
- } catch (error) {
212
- throw new AdapterError(
213
- `Failed to update table: ${error instanceof Error ? error.message : 'Unknown error'}`,
214
- 'UPDATE_TABLE_FAILED',
215
- error instanceof Error ? error : undefined
216
- );
217
- }
218
- }
219
-
220
- async deleteTable(params: DeleteTableParams): Promise<ApiResponse> {
221
- try {
222
- const result = await this.tablesDB.deleteTable(
223
- params.databaseId,
224
- params.tableId
225
- );
226
- return { data: result };
227
- } catch (error) {
228
- throw new AdapterError(
229
- `Failed to delete table: ${error instanceof Error ? error.message : 'Unknown error'}`,
230
- 'DELETE_TABLE_FAILED',
231
- error instanceof Error ? error : undefined
232
- );
233
- }
234
- }
235
-
236
- async getTable(params: GetTableParams): Promise<ApiResponse> {
237
- try {
238
- const result = await this.tablesDB.getTable(
239
- params.databaseId,
240
- params.tableId
241
- );
242
- return {
243
- data: result,
244
- tables: [result]
245
- };
246
- } catch (error) {
247
- throw new AdapterError(
248
- `Failed to get table: ${error instanceof Error ? error.message : 'Unknown error'}`,
249
- 'GET_TABLE_FAILED',
250
- error instanceof Error ? error : undefined
251
- );
252
- }
253
- }
254
-
255
- // Index Operations
256
- async listIndexes(params: ListIndexesParams): Promise<ApiResponse> {
257
- try {
258
- const result = await this.tablesDB.listIndexes(params);
259
- return {
260
- data: result.indexes,
261
- total: result.total
262
- };
263
- } catch (error) {
264
- throw new AdapterError(
265
- `Failed to list indexes: ${error instanceof Error ? error.message : 'Unknown error'}`,
266
- 'LIST_INDEXES_FAILED',
267
- error instanceof Error ? error : undefined
268
- );
269
- }
270
- }
271
-
272
- async createIndex(params: CreateIndexParams): Promise<ApiResponse> {
273
- try {
274
- const result = await this.tablesDB.createIndex(
275
- params.databaseId,
276
- params.tableId,
277
- params.key,
278
- params.type as IndexType,
279
- params.attributes,
280
- params.orders || []
281
- );
282
- return { data: result };
283
- } catch (error) {
284
- throw new AdapterError(
285
- `Failed to create index: ${error instanceof Error ? error.message : 'Unknown error'}`,
286
- 'CREATE_INDEX_FAILED',
287
- error instanceof Error ? error : undefined
288
- );
289
- }
290
- }
291
-
292
- async deleteIndex(params: DeleteIndexParams): Promise<ApiResponse> {
293
- try {
294
- const result = await this.tablesDB.deleteIndex(
295
- params.databaseId,
296
- params.tableId,
297
- params.key
298
- );
299
- return { data: result };
300
- } catch (error) {
301
- throw new AdapterError(
302
- `Failed to delete index: ${error instanceof Error ? error.message : 'Unknown error'}`,
303
- 'DELETE_INDEX_FAILED',
304
- error instanceof Error ? error : undefined
305
- );
306
- }
307
- }
308
-
309
- // Attribute Operations
310
- async createAttribute(params: CreateAttributeParams): Promise<ApiResponse> {
311
- try {
312
- // TablesDB exposes type-specific column methods
313
- // TablesDB uses type-specific column methods
314
- let result;
315
- const type = (params.type || "").toLowerCase();
316
- const required = params.required ?? false;
317
- const array = params.array ?? false;
318
- const encrypt = params.encrypt ?? false;
319
- const normalizedDefault =
320
- params.default === null || params.default === undefined
321
- ? undefined
322
- : params.default;
323
- const numberDefault =
324
- typeof normalizedDefault === "number" ? normalizedDefault : undefined;
325
- const stringDefault =
326
- typeof normalizedDefault === "string" ? normalizedDefault : undefined;
327
- const booleanDefault =
328
- typeof normalizedDefault === "boolean" ? normalizedDefault : undefined;
329
-
330
- switch (type) {
331
- case 'string':
332
- result = await this.tablesDB.createStringColumn({
333
- databaseId: params.databaseId,
334
- tableId: params.tableId,
335
- key: params.key,
336
- size: params.size || 255,
337
- required: params.required ?? false,
338
- xdefault: params.default,
339
- array: params.array ?? false,
340
- encrypt: params.encrypt ?? false
341
- });
342
- break;
343
-
344
- case 'integer':
345
- result = await this.tablesDB.createIntegerColumn({
346
- databaseId: params.databaseId,
347
- tableId: params.tableId,
348
- key: params.key,
349
- required: params.required ?? false,
350
- min: params.min,
351
- max: params.max,
352
- xdefault: params.default,
353
- array: params.array ?? false
354
- });
355
- break;
356
-
357
- case 'float':
358
- case 'double':
359
- result = await this.tablesDB.createFloatColumn({
360
- databaseId: params.databaseId,
361
- tableId: params.tableId,
362
- key: params.key,
363
- required: params.required ?? false,
364
- min: params.min,
365
- max: params.max,
366
- xdefault: params.default,
367
- array: params.array ?? false
368
- });
369
- break;
370
-
371
- case 'boolean':
372
- result = await this.tablesDB.createBooleanColumn({
373
- databaseId: params.databaseId,
374
- tableId: params.tableId,
375
- key: params.key,
376
- required: params.required ?? false,
377
- xdefault: params.default,
378
- array: params.array ?? false
379
- });
380
- break;
381
-
382
- case 'datetime':
383
- result = await this.tablesDB.createDatetimeColumn({
384
- databaseId: params.databaseId,
385
- tableId: params.tableId,
386
- key: params.key,
387
- required: params.required ?? false,
388
- xdefault: params.default,
389
- array: params.array ?? false
390
- });
391
- break;
392
-
393
- case 'email':
394
- result = await this.tablesDB.createEmailColumn({
395
- databaseId: params.databaseId,
396
- tableId: params.tableId,
397
- key: params.key,
398
- required: params.required ?? false,
399
- xdefault: params.default,
400
- array: params.array ?? false
401
- });
402
- break;
403
-
404
- case 'enum':
405
- // Defensive: require non-empty elements
406
- if (!Array.isArray((params as any).elements) || (params as any).elements.length === 0) {
407
- throw new AdapterError(
408
- `Enum '${params.key}' requires a non-empty 'elements' array`,
409
- 'CREATE_ENUM_ELEMENTS_REQUIRED'
410
- );
411
- }
412
- result = await this.tablesDB.createEnumColumn({
413
- databaseId: params.databaseId,
414
- tableId: params.tableId,
415
- key: params.key,
416
- elements: params.elements!,
417
- required: params.required ?? false,
418
- xdefault: params.default,
419
- array: params.array ?? false
420
- });
421
- break;
422
-
423
- case 'ip':
424
- result = await this.tablesDB.createIpColumn({
425
- databaseId: params.databaseId,
426
- tableId: params.tableId,
427
- key: params.key,
428
- required: params.required ?? false,
429
- xdefault: params.default,
430
- array: params.array ?? false
431
- });
432
- break;
433
-
434
- case 'url':
435
- result = await this.tablesDB.createUrlColumn({
436
- databaseId: params.databaseId,
437
- tableId: params.tableId,
438
- key: params.key,
439
- required: params.required ?? false,
440
- xdefault: params.default,
441
- array: params.array ?? false
442
- });
443
- break;
444
-
445
- case 'relationship':
446
- result = await this.tablesDB.createRelationshipColumn({
447
- databaseId: params.databaseId,
448
- tableId: params.tableId,
449
- key: params.key,
450
- relatedTableId: params.relatedCollection || '',
451
- type: (params.relationType || 'oneToOne') as RelationshipType,
452
- twoWay: params.twoWay ?? false,
453
- twoWayKey: params.twoWayKey,
454
- onDelete: (params.onDelete || 'restrict') as RelationMutate
455
- });
456
- break;
457
-
458
- default:
459
- throw new AdapterError(
460
- `Unsupported attribute type: ${params.type}`,
461
- 'UNSUPPORTED_ATTRIBUTE_TYPE'
462
- );
463
- }
464
-
465
- return { data: result };
466
- } catch (error) {
467
- throw new AdapterError(
468
- `Failed to create attribute: ${error instanceof Error ? error.message : 'Unknown error'}`,
469
- 'CREATE_ATTRIBUTE_FAILED',
470
- error instanceof Error ? error : undefined
471
- );
472
- }
473
- }
474
-
475
- async updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse> {
476
- try {
477
- // TablesDB uses type-specific update methods with object notation
478
- // We need to detect the existing column type to use the correct update method
479
- // For now, we'll need to get the column info first, then use the appropriate update method
480
-
481
- // Get the current table schema to determine the column type
482
- const tableInfo = await this.tablesDB.getTable(params.databaseId, params.tableId);
483
-
484
- // Find the column to determine its type
485
- const column = tableInfo.columns?.find(col => col.key === params.key);
486
- if (!column) {
487
- throw new AdapterError(
488
- `Column '${params.key}' not found in table`,
489
- 'COLUMN_NOT_FOUND'
490
- );
491
- }
492
-
493
- let result;
494
-
495
- // Use the appropriate updateXColumn method based on the column type
496
- // Cast column to proper Models type to access its specific properties
497
- const columnType = (column as any).type;
498
-
499
- switch (columnType) {
500
- case 'string':
501
- const stringColumn = column as Models.ColumnString;
502
- result = await this.tablesDB.updateStringColumn({
503
- databaseId: params.databaseId,
504
- tableId: params.tableId,
505
- key: params.key,
506
- required: params.required !== undefined ? params.required : stringColumn.required,
507
- xdefault: params.default !== undefined ? params.default : stringColumn.default,
508
- size: params.size !== undefined ? params.size : stringColumn.size,
509
- });
510
- break;
511
-
512
- case 'integer':
513
- const integerColumn = column as Models.ColumnInteger;
514
- result = await this.tablesDB.updateIntegerColumn({
515
- databaseId: params.databaseId,
516
- tableId: params.tableId,
517
- key: params.key,
518
- required: params.required !== undefined ? params.required : integerColumn.required,
519
- xdefault: params.default !== undefined ? params.default : integerColumn.default,
520
- // Only send min/max when explicitly provided to avoid resubmitting extreme values
521
- ...(params.min !== undefined ? { min: params.min } : {}),
522
- ...(params.max !== undefined ? { max: params.max } : {}),
523
- });
524
- break;
525
-
526
- case 'float':
527
- case 'double':
528
- const floatColumn = column as Models.ColumnFloat;
529
- result = await this.tablesDB.updateFloatColumn({
530
- databaseId: params.databaseId,
531
- tableId: params.tableId,
532
- key: params.key,
533
- required: params.required !== undefined ? params.required : floatColumn.required,
534
- xdefault: params.default !== undefined ? params.default : floatColumn.default,
535
- ...(params.min !== undefined ? { min: params.min } : {}),
536
- ...(params.max !== undefined ? { max: params.max } : {}),
537
- });
538
- break;
539
-
540
- case 'boolean':
541
- const booleanColumn = column as Models.ColumnBoolean;
542
- result = await this.tablesDB.updateBooleanColumn({
543
- databaseId: params.databaseId,
544
- tableId: params.tableId,
545
- key: params.key,
546
- required: params.required !== undefined ? params.required : booleanColumn.required,
547
- xdefault: params.default !== undefined ? params.default : booleanColumn.default
548
- });
549
- break;
550
-
551
- case 'datetime':
552
- const datetimeColumn = column as Models.ColumnDatetime;
553
- result = await this.tablesDB.updateDatetimeColumn({
554
- databaseId: params.databaseId,
555
- tableId: params.tableId,
556
- key: params.key,
557
- required: params.required !== undefined ? params.required : datetimeColumn.required,
558
- xdefault: params.default !== undefined ? params.default : datetimeColumn.default
559
- });
560
- break;
561
-
562
- case 'email':
563
- const emailColumn = column as Models.ColumnEmail;
564
- result = await this.tablesDB.updateEmailColumn({
565
- databaseId: params.databaseId,
566
- tableId: params.tableId,
567
- key: params.key,
568
- required: params.required !== undefined ? params.required : emailColumn.required,
569
- xdefault: params.default !== undefined ? params.default : emailColumn.default
570
- });
571
- break;
572
-
573
- case 'enum':
574
- const enumColumn = column as Models.ColumnEnum;
575
- // Choose elements to send only when provided, otherwise preserve existing
576
- const provided = (params as any).elements;
577
- const existing = (enumColumn as any)?.elements;
578
- const nextElements = (Array.isArray(provided) && provided.length > 0) ? provided : existing;
579
- result = await this.tablesDB.updateEnumColumn({
580
- databaseId: params.databaseId,
581
- tableId: params.tableId,
582
- key: params.key,
583
- required: params.required !== undefined ? params.required : enumColumn.required,
584
- xdefault: params.default !== undefined ? params.default : enumColumn.default,
585
- elements: nextElements
586
- });
587
- break;
588
-
589
- case 'ip':
590
- const ipColumn = column as Models.ColumnIp;
591
- result = await this.tablesDB.updateIpColumn({
592
- databaseId: params.databaseId,
593
- tableId: params.tableId,
594
- key: params.key,
595
- required: params.required !== undefined ? params.required : ipColumn.required,
596
- xdefault: params.default !== undefined ? params.default : ipColumn.default
597
- });
598
- break;
599
-
600
- case 'url':
601
- const urlColumn = column as Models.ColumnUrl;
602
- result = await this.tablesDB.updateUrlColumn({
603
- databaseId: params.databaseId,
604
- tableId: params.tableId,
605
- key: params.key,
606
- required: params.required !== undefined ? params.required : urlColumn.required,
607
- xdefault: params.default !== undefined ? params.default : urlColumn.default
608
- });
609
- break;
610
-
611
- case 'relationship':
612
- const relationshipColumn = column as Models.ColumnRelationship;
613
- result = await this.tablesDB.updateRelationshipColumn({
614
- databaseId: params.databaseId,
615
- tableId: params.tableId,
616
- key: params.key,
617
- onDelete: (params.onDelete !== undefined ? params.onDelete : relationshipColumn.onDelete) as RelationMutate,
618
- });
619
- break;
620
-
621
- default:
622
- throw new AdapterError(
623
- `Unsupported column type for update: ${columnType}`,
624
- 'UNSUPPORTED_COLUMN_TYPE'
625
- );
626
- }
627
-
628
- return { data: result };
629
- } catch (error) {
630
- throw new AdapterError(
631
- `Failed to update attribute: ${error instanceof Error ? error.message : 'Unknown error'}`,
632
- 'UPDATE_ATTRIBUTE_FAILED',
633
- error instanceof Error ? error : undefined
634
- );
635
- }
636
- }
637
-
638
- async deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse> {
639
- try {
640
- const result = await this.tablesDB.deleteColumn({
641
- databaseId: params.databaseId,
642
- tableId: params.tableId,
643
- key: params.key
644
- });
645
- return { data: result };
646
- } catch (error) {
647
- throw new AdapterError(
648
- `Failed to delete attribute: ${error instanceof Error ? error.message : 'Unknown error'}`,
649
- 'DELETE_ATTRIBUTE_FAILED',
650
- error instanceof Error ? error : undefined
651
- );
652
- }
653
- }
654
-
655
- // Bulk Operations (Native TablesDB Support)
656
- async bulkCreateRows(params: BulkCreateRowsParams): Promise<ApiResponse> {
657
- try {
658
- const result = await this.tablesDB.createRows(params);
659
- return {
660
- data: result.rows,
661
- rows: result.rows,
662
- total: result.rows?.length || 0
663
- };
664
- } catch (error) {
665
- throw new AdapterError(
666
- `Failed to bulk create rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
667
- 'BULK_CREATE_ROWS_FAILED',
668
- error instanceof Error ? error : undefined
669
- );
670
- }
671
- }
672
-
673
- async bulkUpsertRows(params: BulkUpsertRowsParams): Promise<ApiResponse> {
674
- try {
675
- const result = await this.tablesDB.upsertRows(params);
676
- return {
677
- data: result.rows,
678
- rows: result.rows,
679
- total: result.rows?.length || 0
680
- };
681
- } catch (error) {
682
- throw new AdapterError(
683
- `Failed to bulk upsert rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
684
- 'BULK_UPSERT_ROWS_FAILED',
685
- error instanceof Error ? error : undefined
686
- );
687
- }
688
- }
689
-
690
- async bulkDeleteRows(params: BulkDeleteRowsParams): Promise<ApiResponse> {
691
- try {
692
- let queries: string[];
693
-
694
- // Wipe mode: use Query.limit for deleting without fetching
695
- if (params.rowIds.length === 0) {
696
- const batchSize = params.batchSize || 1000;
697
-
698
- // Validation: Ensure table exists before wiping
699
- try {
700
- await this.getTable({
701
- databaseId: params.databaseId,
702
- tableId: params.tableId
703
- });
704
- } catch (error: any) {
705
- const errorMessage = error?.message || String(error);
706
- if (errorMessage.toLowerCase().includes('not found') || error?.code === 404) {
707
- throw new AdapterError(
708
- `Table '${params.tableId}' not found in database '${params.databaseId}'`,
709
- 'TABLE_NOT_FOUND',
710
- error
711
- );
712
- }
713
- throw error; // Re-throw other errors
714
- }
715
-
716
- queries = [Query.limit(batchSize)];
717
- }
718
- // Specific IDs mode: chunk into batches of 80-90 to stay within Appwrite limits
719
- // (max 100 IDs per Query.equal, and queries must be < 4096 chars total)
720
- else {
721
- const ID_BATCH_SIZE = 85; // Safe batch size for Query.equal
722
- const idBatches = chunk(params.rowIds, ID_BATCH_SIZE);
723
- queries = idBatches.map(batch => Query.equal('$id', batch));
724
- }
725
-
726
- const result = await this.tablesDB.deleteRows({
727
- databaseId: params.databaseId,
728
- tableId: params.tableId,
729
- queries: queries
730
- });
731
-
732
- return {
733
- data: result,
734
- total: params.rowIds.length || (result as any).total || 0
735
- };
736
- } catch (error) {
737
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
738
-
739
- // Enhanced error categorization
740
- if (errorMessage.toLowerCase().includes('not found') || (error as any)?.code === 404) {
741
- throw new AdapterError(
742
- `Table or rows not found: ${errorMessage}`,
743
- 'NOT_FOUND',
744
- error instanceof Error ? error : undefined
745
- );
746
- } else if (errorMessage.toLowerCase().includes('permission') || errorMessage.toLowerCase().includes('unauthorized') || (error as any)?.code === 403) {
747
- throw new AdapterError(
748
- `Permission denied for bulk delete: ${errorMessage}`,
749
- 'PERMISSION_DENIED',
750
- error instanceof Error ? error : undefined
751
- );
752
- } else if (errorMessage.toLowerCase().includes('rate limit') || (error as any)?.code === 429) {
753
- throw new AdapterError(
754
- `Rate limit exceeded during bulk delete: ${errorMessage}`,
755
- 'RATE_LIMIT',
756
- error instanceof Error ? error : undefined
757
- );
758
- }
759
-
760
- throw new AdapterError(
761
- `Failed to bulk delete rows: ${errorMessage}`,
762
- 'BULK_DELETE_ROWS_FAILED',
763
- error instanceof Error ? error : undefined
764
- );
765
- }
766
- }
767
-
768
- // Metadata and Capabilities
769
- getMetadata(): AdapterMetadata {
770
- return {
771
- apiMode: 'tablesdb',
772
- terminology: {
773
- container: 'table',
774
- item: 'row',
775
- service: 'TablesDB'
776
- },
777
- capabilities: {
778
- bulkOperations: true,
779
- advancedQueries: true,
780
- realtime: true,
781
- transactions: true // TablesDB may support transactions
782
- }
783
- };
784
- }
785
-
786
- supportsBulkOperations(): boolean {
787
- return true; // TablesDB natively supports bulk operations
788
- }
789
-
790
- // Advanced TablesDB Features
791
-
792
- /**
793
- * Execute a transaction (if supported by TablesDB)
794
- */
795
- async executeTransaction(operations: Array<() => Promise<any>>): Promise<ApiResponse> {
796
- try {
797
- // Create a new transaction first
798
- const transaction = await this.tablesDB.createTransaction();
799
-
800
- // Add operations to the transaction
801
- const result = await this.tablesDB.createOperations({
802
- transactionId: transaction.$id,
803
- operations: operations.map(op => ({ operation: 'execute', fn: op }))
804
- });
805
-
806
- return { data: result };
807
- } catch (error) {
808
- throw new AdapterError(
809
- `Transaction failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
810
- 'TRANSACTION_FAILED',
811
- error instanceof Error ? error : undefined
812
- );
813
- }
814
- }
815
- }