appwrite-utils-cli 1.9.7 → 1.12.0

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