@njdamstra/appwrite-utils-cli 1.8.9 → 1.10.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 (284) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/CONFIG_TODO.md +1189 -0
  3. package/SELECTION_DIALOGS.md +146 -0
  4. package/SERVICE_IMPLEMENTATION_REPORT.md +462 -0
  5. package/dist/adapters/index.d.ts +7 -8
  6. package/dist/adapters/index.js +7 -9
  7. package/dist/backups/operations/bucketBackup.js +2 -2
  8. package/dist/backups/operations/collectionBackup.d.ts +1 -1
  9. package/dist/backups/operations/collectionBackup.js +3 -3
  10. package/dist/backups/operations/comprehensiveBackup.d.ts +1 -1
  11. package/dist/backups/operations/comprehensiveBackup.js +2 -2
  12. package/dist/backups/tracking/centralizedTracking.d.ts +1 -1
  13. package/dist/backups/tracking/centralizedTracking.js +2 -2
  14. package/dist/cli/commands/configCommands.js +51 -7
  15. package/dist/cli/commands/databaseCommands.d.ts +1 -0
  16. package/dist/cli/commands/databaseCommands.js +119 -9
  17. package/dist/cli/commands/functionCommands.js +3 -3
  18. package/dist/cli/commands/importFileCommands.d.ts +7 -0
  19. package/dist/cli/commands/importFileCommands.js +674 -0
  20. package/dist/cli/commands/schemaCommands.js +3 -3
  21. package/dist/cli/commands/storageCommands.js +2 -3
  22. package/dist/cli/commands/transferCommands.js +3 -5
  23. package/dist/collections/attributes.d.ts +1 -1
  24. package/dist/collections/attributes.js +2 -35
  25. package/dist/collections/indexes.js +1 -3
  26. package/dist/collections/methods.d.ts +1 -1
  27. package/dist/collections/methods.js +111 -192
  28. package/dist/collections/tableOperations.d.ts +1 -0
  29. package/dist/collections/tableOperations.js +55 -23
  30. package/dist/collections/transferOperations.d.ts +1 -1
  31. package/dist/collections/transferOperations.js +3 -4
  32. package/dist/collections/wipeOperations.d.ts +4 -3
  33. package/dist/collections/wipeOperations.js +112 -39
  34. package/dist/databases/methods.js +2 -2
  35. package/dist/databases/setup.js +2 -2
  36. package/dist/examples/yamlTerminologyExample.js +2 -2
  37. package/dist/functions/deployments.d.ts +1 -1
  38. package/dist/functions/deployments.js +5 -5
  39. package/dist/functions/fnConfigDiscovery.js +2 -2
  40. package/dist/functions/methods.js +16 -4
  41. package/dist/init.js +1 -1
  42. package/dist/interactiveCLI.d.ts +6 -1
  43. package/dist/interactiveCLI.js +63 -9
  44. package/dist/main.js +130 -177
  45. package/dist/migrations/afterImportActions.js +2 -3
  46. package/dist/migrations/appwriteToX.d.ts +1 -1
  47. package/dist/migrations/appwriteToX.js +9 -7
  48. package/dist/migrations/comprehensiveTransfer.js +3 -5
  49. package/dist/migrations/dataLoader.js +2 -5
  50. package/dist/migrations/importController.js +3 -4
  51. package/dist/migrations/importDataActions.js +3 -3
  52. package/dist/migrations/relationships.js +1 -2
  53. package/dist/migrations/services/DataTransformationService.js +2 -2
  54. package/dist/migrations/services/FileHandlerService.js +1 -1
  55. package/dist/migrations/services/ImportOrchestrator.js +4 -4
  56. package/dist/migrations/services/RateLimitManager.js +1 -1
  57. package/dist/migrations/services/RelationshipResolver.js +1 -1
  58. package/dist/migrations/services/UserMappingService.js +1 -1
  59. package/dist/migrations/services/ValidationService.js +1 -1
  60. package/dist/migrations/transfer.d.ts +8 -4
  61. package/dist/migrations/transfer.js +106 -55
  62. package/dist/migrations/yaml/YamlImportConfigLoader.js +1 -1
  63. package/dist/migrations/yaml/YamlImportIntegration.js +2 -2
  64. package/dist/migrations/yaml/generateImportSchemas.js +1 -1
  65. package/dist/setupCommands.d.ts +1 -1
  66. package/dist/setupCommands.js +5 -6
  67. package/dist/setupController.js +1 -1
  68. package/dist/shared/backupTracking.d.ts +1 -1
  69. package/dist/shared/backupTracking.js +2 -2
  70. package/dist/shared/confirmationDialogs.js +1 -1
  71. package/dist/shared/migrationHelpers.d.ts +1 -1
  72. package/dist/shared/migrationHelpers.js +3 -3
  73. package/dist/shared/operationQueue.d.ts +1 -1
  74. package/dist/shared/operationQueue.js +2 -3
  75. package/dist/shared/operationsTable.d.ts +1 -1
  76. package/dist/shared/operationsTable.js +2 -2
  77. package/dist/shared/progressManager.js +1 -1
  78. package/dist/shared/selectionDialogs.js +9 -8
  79. package/dist/storage/methods.js +4 -4
  80. package/dist/storage/schemas.d.ts +2 -2
  81. package/dist/tables/indexManager.d.ts +65 -0
  82. package/dist/tables/indexManager.js +294 -0
  83. package/dist/types.d.ts +2 -2
  84. package/dist/types.js +1 -1
  85. package/dist/users/methods.js +2 -3
  86. package/dist/utils/configMigration.js +1 -1
  87. package/dist/utils/index.d.ts +1 -1
  88. package/dist/utils/index.js +1 -1
  89. package/dist/utils/loadConfigs.d.ts +2 -2
  90. package/dist/utils/loadConfigs.js +6 -7
  91. package/dist/utils/setupFiles.js +5 -7
  92. package/dist/utilsController.d.ts +15 -8
  93. package/dist/utilsController.js +57 -28
  94. package/package.json +7 -3
  95. package/src/adapters/index.ts +8 -34
  96. package/src/backups/operations/bucketBackup.ts +2 -2
  97. package/src/backups/operations/collectionBackup.ts +4 -4
  98. package/src/backups/operations/comprehensiveBackup.ts +3 -3
  99. package/src/backups/tracking/centralizedTracking.ts +3 -3
  100. package/src/cli/commands/configCommands.ts +72 -8
  101. package/src/cli/commands/databaseCommands.ts +161 -9
  102. package/src/cli/commands/functionCommands.ts +4 -3
  103. package/src/cli/commands/importFileCommands.ts +815 -0
  104. package/src/cli/commands/schemaCommands.ts +3 -3
  105. package/src/cli/commands/storageCommands.ts +2 -3
  106. package/src/cli/commands/transferCommands.ts +3 -6
  107. package/src/collections/attributes.ts +3 -39
  108. package/src/collections/indexes.ts +2 -4
  109. package/src/collections/methods.ts +115 -150
  110. package/src/collections/tableOperations.ts +57 -21
  111. package/src/collections/transferOperations.ts +4 -5
  112. package/src/collections/wipeOperations.ts +154 -51
  113. package/src/databases/methods.ts +2 -2
  114. package/src/databases/setup.ts +2 -2
  115. package/src/examples/yamlTerminologyExample.ts +2 -2
  116. package/src/functions/deployments.ts +6 -5
  117. package/src/functions/fnConfigDiscovery.ts +2 -2
  118. package/src/functions/methods.ts +17 -4
  119. package/src/init.ts +1 -1
  120. package/src/interactiveCLI.ts +75 -10
  121. package/src/main.ts +143 -287
  122. package/src/migrations/afterImportActions.ts +2 -3
  123. package/src/migrations/appwriteToX.ts +12 -8
  124. package/src/migrations/comprehensiveTransfer.ts +6 -6
  125. package/src/migrations/dataLoader.ts +2 -5
  126. package/src/migrations/importController.ts +3 -4
  127. package/src/migrations/importDataActions.ts +3 -3
  128. package/src/migrations/relationships.ts +1 -2
  129. package/src/migrations/services/DataTransformationService.ts +2 -2
  130. package/src/migrations/services/FileHandlerService.ts +1 -1
  131. package/src/migrations/services/ImportOrchestrator.ts +4 -4
  132. package/src/migrations/services/RateLimitManager.ts +1 -1
  133. package/src/migrations/services/RelationshipResolver.ts +1 -1
  134. package/src/migrations/services/UserMappingService.ts +1 -1
  135. package/src/migrations/services/ValidationService.ts +1 -1
  136. package/src/migrations/transfer.ts +126 -83
  137. package/src/migrations/yaml/YamlImportConfigLoader.ts +1 -1
  138. package/src/migrations/yaml/YamlImportIntegration.ts +2 -2
  139. package/src/migrations/yaml/generateImportSchemas.ts +1 -1
  140. package/src/setupCommands.ts +5 -6
  141. package/src/setupController.ts +1 -1
  142. package/src/shared/backupTracking.ts +3 -3
  143. package/src/shared/confirmationDialogs.ts +1 -1
  144. package/src/shared/migrationHelpers.ts +4 -4
  145. package/src/shared/operationQueue.ts +3 -4
  146. package/src/shared/operationsTable.ts +3 -3
  147. package/src/shared/progressManager.ts +1 -1
  148. package/src/shared/selectionDialogs.ts +9 -8
  149. package/src/storage/methods.ts +4 -4
  150. package/src/tables/indexManager.ts +409 -0
  151. package/src/types.ts +2 -2
  152. package/src/users/methods.ts +2 -3
  153. package/src/utils/configMigration.ts +1 -1
  154. package/src/utils/index.ts +1 -1
  155. package/src/utils/loadConfigs.ts +15 -7
  156. package/src/utils/setupFiles.ts +5 -7
  157. package/src/utilsController.ts +86 -32
  158. package/dist/adapters/AdapterFactory.d.ts +0 -94
  159. package/dist/adapters/AdapterFactory.js +0 -405
  160. package/dist/adapters/DatabaseAdapter.d.ts +0 -233
  161. package/dist/adapters/DatabaseAdapter.js +0 -50
  162. package/dist/adapters/LegacyAdapter.d.ts +0 -50
  163. package/dist/adapters/LegacyAdapter.js +0 -612
  164. package/dist/adapters/TablesDBAdapter.d.ts +0 -45
  165. package/dist/adapters/TablesDBAdapter.js +0 -571
  166. package/dist/config/ConfigManager.d.ts +0 -445
  167. package/dist/config/ConfigManager.js +0 -625
  168. package/dist/config/configMigration.d.ts +0 -87
  169. package/dist/config/configMigration.js +0 -390
  170. package/dist/config/configValidation.d.ts +0 -66
  171. package/dist/config/configValidation.js +0 -358
  172. package/dist/config/index.d.ts +0 -8
  173. package/dist/config/index.js +0 -7
  174. package/dist/config/services/ConfigDiscoveryService.d.ts +0 -126
  175. package/dist/config/services/ConfigDiscoveryService.js +0 -374
  176. package/dist/config/services/ConfigLoaderService.d.ts +0 -129
  177. package/dist/config/services/ConfigLoaderService.js +0 -540
  178. package/dist/config/services/ConfigMergeService.d.ts +0 -208
  179. package/dist/config/services/ConfigMergeService.js +0 -308
  180. package/dist/config/services/ConfigValidationService.d.ts +0 -214
  181. package/dist/config/services/ConfigValidationService.js +0 -310
  182. package/dist/config/services/SessionAuthService.d.ts +0 -225
  183. package/dist/config/services/SessionAuthService.js +0 -456
  184. package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +0 -1
  185. package/dist/config/services/__tests__/ConfigMergeService.test.js +0 -271
  186. package/dist/config/services/index.d.ts +0 -13
  187. package/dist/config/services/index.js +0 -10
  188. package/dist/config/yamlConfig.d.ts +0 -722
  189. package/dist/config/yamlConfig.js +0 -702
  190. package/dist/functions/pathResolution.d.ts +0 -37
  191. package/dist/functions/pathResolution.js +0 -185
  192. package/dist/shared/attributeMapper.d.ts +0 -20
  193. package/dist/shared/attributeMapper.js +0 -203
  194. package/dist/shared/errorUtils.d.ts +0 -54
  195. package/dist/shared/errorUtils.js +0 -95
  196. package/dist/shared/functionManager.d.ts +0 -48
  197. package/dist/shared/functionManager.js +0 -336
  198. package/dist/shared/indexManager.d.ts +0 -24
  199. package/dist/shared/indexManager.js +0 -151
  200. package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
  201. package/dist/shared/jsonSchemaGenerator.js +0 -290
  202. package/dist/shared/logging.d.ts +0 -61
  203. package/dist/shared/logging.js +0 -116
  204. package/dist/shared/messageFormatter.d.ts +0 -39
  205. package/dist/shared/messageFormatter.js +0 -162
  206. package/dist/shared/pydanticModelGenerator.d.ts +0 -17
  207. package/dist/shared/pydanticModelGenerator.js +0 -615
  208. package/dist/shared/schemaGenerator.d.ts +0 -40
  209. package/dist/shared/schemaGenerator.js +0 -556
  210. package/dist/utils/ClientFactory.d.ts +0 -87
  211. package/dist/utils/ClientFactory.js +0 -212
  212. package/dist/utils/configDiscovery.d.ts +0 -78
  213. package/dist/utils/configDiscovery.js +0 -472
  214. package/dist/utils/constantsGenerator.d.ts +0 -31
  215. package/dist/utils/constantsGenerator.js +0 -321
  216. package/dist/utils/dataConverters.d.ts +0 -46
  217. package/dist/utils/dataConverters.js +0 -139
  218. package/dist/utils/directoryUtils.d.ts +0 -22
  219. package/dist/utils/directoryUtils.js +0 -59
  220. package/dist/utils/getClientFromConfig.d.ts +0 -39
  221. package/dist/utils/getClientFromConfig.js +0 -199
  222. package/dist/utils/helperFunctions.d.ts +0 -63
  223. package/dist/utils/helperFunctions.js +0 -156
  224. package/dist/utils/pathResolvers.d.ts +0 -53
  225. package/dist/utils/pathResolvers.js +0 -72
  226. package/dist/utils/projectConfig.d.ts +0 -119
  227. package/dist/utils/projectConfig.js +0 -171
  228. package/dist/utils/retryFailedPromises.d.ts +0 -2
  229. package/dist/utils/retryFailedPromises.js +0 -23
  230. package/dist/utils/sessionAuth.d.ts +0 -48
  231. package/dist/utils/sessionAuth.js +0 -164
  232. package/dist/utils/typeGuards.d.ts +0 -35
  233. package/dist/utils/typeGuards.js +0 -57
  234. package/dist/utils/validationRules.d.ts +0 -43
  235. package/dist/utils/validationRules.js +0 -42
  236. package/dist/utils/versionDetection.d.ts +0 -58
  237. package/dist/utils/versionDetection.js +0 -251
  238. package/dist/utils/yamlConverter.d.ts +0 -100
  239. package/dist/utils/yamlConverter.js +0 -428
  240. package/dist/utils/yamlLoader.d.ts +0 -70
  241. package/dist/utils/yamlLoader.js +0 -267
  242. package/src/adapters/AdapterFactory.ts +0 -510
  243. package/src/adapters/DatabaseAdapter.ts +0 -306
  244. package/src/adapters/LegacyAdapter.ts +0 -841
  245. package/src/adapters/TablesDBAdapter.ts +0 -773
  246. package/src/config/ConfigManager.ts +0 -808
  247. package/src/config/README.md +0 -274
  248. package/src/config/configMigration.ts +0 -575
  249. package/src/config/configValidation.ts +0 -445
  250. package/src/config/index.ts +0 -10
  251. package/src/config/services/ConfigDiscoveryService.ts +0 -463
  252. package/src/config/services/ConfigLoaderService.ts +0 -740
  253. package/src/config/services/ConfigMergeService.ts +0 -388
  254. package/src/config/services/ConfigValidationService.ts +0 -394
  255. package/src/config/services/SessionAuthService.ts +0 -565
  256. package/src/config/services/__tests__/ConfigMergeService.test.ts +0 -351
  257. package/src/config/services/index.ts +0 -29
  258. package/src/config/yamlConfig.ts +0 -761
  259. package/src/functions/pathResolution.ts +0 -227
  260. package/src/shared/attributeMapper.ts +0 -229
  261. package/src/shared/errorUtils.ts +0 -110
  262. package/src/shared/functionManager.ts +0 -525
  263. package/src/shared/indexManager.ts +0 -254
  264. package/src/shared/jsonSchemaGenerator.ts +0 -383
  265. package/src/shared/logging.ts +0 -149
  266. package/src/shared/messageFormatter.ts +0 -208
  267. package/src/shared/pydanticModelGenerator.ts +0 -618
  268. package/src/shared/schemaGenerator.ts +0 -644
  269. package/src/utils/ClientFactory.ts +0 -240
  270. package/src/utils/configDiscovery.ts +0 -557
  271. package/src/utils/constantsGenerator.ts +0 -369
  272. package/src/utils/dataConverters.ts +0 -159
  273. package/src/utils/directoryUtils.ts +0 -61
  274. package/src/utils/getClientFromConfig.ts +0 -257
  275. package/src/utils/helperFunctions.ts +0 -228
  276. package/src/utils/pathResolvers.ts +0 -81
  277. package/src/utils/projectConfig.ts +0 -299
  278. package/src/utils/retryFailedPromises.ts +0 -29
  279. package/src/utils/sessionAuth.ts +0 -230
  280. package/src/utils/typeGuards.ts +0 -65
  281. package/src/utils/validationRules.ts +0 -88
  282. package/src/utils/versionDetection.ts +0 -292
  283. package/src/utils/yamlConverter.ts +0 -542
  284. package/src/utils/yamlLoader.ts +0 -371
@@ -1,773 +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.type || 'oneToOne') as RelationshipType,
452
- twoWay: params.twoWay ?? false,
453
- twoWayKey: params.twoWayKey,
454
- onDelete: params.onDelete || 'restrict'
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 || 250;
697
- queries = [Query.limit(batchSize)];
698
- }
699
- // Specific IDs mode: chunk into batches of 80-90 to stay within Appwrite limits
700
- // (max 100 IDs per Query.equal, and queries must be < 4096 chars total)
701
- else {
702
- const ID_BATCH_SIZE = 85; // Safe batch size for Query.equal
703
- const idBatches = chunk(params.rowIds, ID_BATCH_SIZE);
704
- queries = idBatches.map(batch => Query.equal('$id', batch));
705
- }
706
-
707
- const result = await this.tablesDB.deleteRows({
708
- databaseId: params.databaseId,
709
- tableId: params.tableId,
710
- queries: queries
711
- });
712
-
713
- return {
714
- data: result,
715
- total: params.rowIds.length || (result as any).total || 0
716
- };
717
- } catch (error) {
718
- throw new AdapterError(
719
- `Failed to bulk delete rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
720
- 'BULK_DELETE_ROWS_FAILED',
721
- error instanceof Error ? error : undefined
722
- );
723
- }
724
- }
725
-
726
- // Metadata and Capabilities
727
- getMetadata(): AdapterMetadata {
728
- return {
729
- apiMode: 'tablesdb',
730
- terminology: {
731
- container: 'table',
732
- item: 'row',
733
- service: 'TablesDB'
734
- },
735
- capabilities: {
736
- bulkOperations: true,
737
- advancedQueries: true,
738
- realtime: true,
739
- transactions: true // TablesDB may support transactions
740
- }
741
- };
742
- }
743
-
744
- supportsBulkOperations(): boolean {
745
- return true; // TablesDB natively supports bulk operations
746
- }
747
-
748
- // Advanced TablesDB Features
749
-
750
- /**
751
- * Execute a transaction (if supported by TablesDB)
752
- */
753
- async executeTransaction(operations: Array<() => Promise<any>>): Promise<ApiResponse> {
754
- try {
755
- // Create a new transaction first
756
- const transaction = await this.tablesDB.createTransaction();
757
-
758
- // Add operations to the transaction
759
- const result = await this.tablesDB.createOperations({
760
- transactionId: transaction.$id,
761
- operations: operations.map(op => ({ operation: 'execute', fn: op }))
762
- });
763
-
764
- return { data: result };
765
- } catch (error) {
766
- throw new AdapterError(
767
- `Transaction failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
768
- 'TRANSACTION_FAILED',
769
- error instanceof Error ? error : undefined
770
- );
771
- }
772
- }
773
- }