appwrite-utils-cli 1.3.5 → 1.4.1

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 (116) hide show
  1. package/dist/adapters/AdapterFactory.d.ts +87 -0
  2. package/dist/adapters/AdapterFactory.js +217 -0
  3. package/dist/adapters/DatabaseAdapter.d.ts +217 -0
  4. package/dist/adapters/DatabaseAdapter.js +50 -0
  5. package/dist/adapters/LegacyAdapter.d.ts +49 -0
  6. package/dist/adapters/LegacyAdapter.js +382 -0
  7. package/dist/adapters/TablesDBAdapter.d.ts +55 -0
  8. package/dist/adapters/TablesDBAdapter.js +302 -0
  9. package/dist/adapters/index.d.ts +11 -0
  10. package/dist/adapters/index.js +12 -0
  11. package/dist/collections/attributes.js +41 -22
  12. package/dist/collections/methods.d.ts +4 -3
  13. package/dist/collections/methods.js +34 -14
  14. package/dist/config/yamlConfig.d.ts +40 -437
  15. package/dist/config/yamlConfig.js +8 -2
  16. package/dist/databases/setup.js +2 -2
  17. package/dist/main.js +0 -0
  18. package/dist/migrations/appwriteToX.d.ts +26 -37
  19. package/dist/migrations/comprehensiveTransfer.js +4 -4
  20. package/dist/migrations/dataLoader.d.ts +124 -1484
  21. package/dist/migrations/dataLoader.js +2 -1
  22. package/dist/migrations/relationships.d.ts +2 -3
  23. package/dist/migrations/relationships.js +1 -1
  24. package/dist/migrations/services/UserMappingService.js +1 -1
  25. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +24 -279
  26. package/dist/migrations/yaml/YamlImportConfigLoader.js +7 -2
  27. package/dist/schemas/authUser.d.ts +7 -47
  28. package/dist/schemas/authUser.js +1 -1
  29. package/dist/shared/jsonSchemaGenerator.d.ts +0 -2
  30. package/dist/shared/jsonSchemaGenerator.js +4 -17
  31. package/dist/shared/migrationHelpers.d.ts +17 -119
  32. package/dist/shared/operationQueue.js +16 -7
  33. package/dist/shared/schemaGenerator.js +2 -17
  34. package/dist/storage/schemas.d.ts +149 -296
  35. package/dist/users/methods.d.ts +2 -2
  36. package/dist/utils/configMigration.js +0 -1
  37. package/dist/utils/getClientFromConfig.d.ts +26 -0
  38. package/dist/utils/getClientFromConfig.js +37 -0
  39. package/dist/utils/loadConfigs.js +0 -2
  40. package/dist/utils/schemaStrings.js +2 -17
  41. package/dist/utils/setupFiles.js +2 -0
  42. package/dist/utils/versionDetection.d.ts +56 -0
  43. package/dist/utils/versionDetection.js +217 -0
  44. package/dist/utils/yamlConverter.d.ts +0 -1
  45. package/dist/utils/yamlConverter.js +0 -2
  46. package/dist/utilsController.js +2 -0
  47. package/package.json +3 -2
  48. package/src/adapters/AdapterFactory.ts +296 -0
  49. package/src/adapters/DatabaseAdapter.ts +290 -0
  50. package/src/adapters/LegacyAdapter.ts +667 -0
  51. package/src/adapters/TablesDBAdapter.ts +429 -0
  52. package/src/adapters/index.ts +37 -0
  53. package/src/collections/attributes.ts +347 -153
  54. package/src/collections/methods.ts +43 -28
  55. package/src/config/yamlConfig.ts +8 -2
  56. package/src/databases/setup.ts +2 -2
  57. package/src/migrations/afterImportActions.ts +2 -2
  58. package/src/migrations/comprehensiveTransfer.ts +4 -0
  59. package/src/migrations/dataLoader.ts +2 -1
  60. package/src/migrations/relationships.ts +1 -1
  61. package/src/migrations/services/UserMappingService.ts +1 -1
  62. package/src/migrations/yaml/YamlImportConfigLoader.ts +7 -2
  63. package/src/schemas/authUser.ts +1 -1
  64. package/src/shared/jsonSchemaGenerator.ts +4 -19
  65. package/src/shared/operationQueue.ts +20 -13
  66. package/src/shared/schemaGenerator.ts +2 -16
  67. package/src/types/node-appwrite-tablesdb.d.ts +44 -0
  68. package/src/users/methods.ts +2 -2
  69. package/src/utils/configMigration.ts +0 -1
  70. package/src/utils/getClientFromConfig.ts +56 -0
  71. package/src/utils/loadConfigs.ts +0 -2
  72. package/src/utils/schemaStrings.ts +2 -16
  73. package/src/utils/setupFiles.ts +2 -0
  74. package/src/utils/versionDetection.ts +265 -0
  75. package/src/utils/yamlConverter.ts +0 -2
  76. package/src/utilsController.ts +2 -0
  77. package/dist/functions/openapi.d.ts +0 -4
  78. package/dist/functions/openapi.js +0 -60
  79. package/dist/migrations/attributes.d.ts +0 -4
  80. package/dist/migrations/attributes.js +0 -301
  81. package/dist/migrations/backup.d.ts +0 -687
  82. package/dist/migrations/backup.js +0 -175
  83. package/dist/migrations/collections.d.ts +0 -22
  84. package/dist/migrations/collections.js +0 -347
  85. package/dist/migrations/converters.d.ts +0 -46
  86. package/dist/migrations/converters.js +0 -139
  87. package/dist/migrations/databases.d.ts +0 -2
  88. package/dist/migrations/databases.js +0 -28
  89. package/dist/migrations/dbHelpers.d.ts +0 -5
  90. package/dist/migrations/dbHelpers.js +0 -57
  91. package/dist/migrations/helper.d.ts +0 -3
  92. package/dist/migrations/helper.js +0 -21
  93. package/dist/migrations/indexes.d.ts +0 -4
  94. package/dist/migrations/indexes.js +0 -19
  95. package/dist/migrations/logging.d.ts +0 -10
  96. package/dist/migrations/logging.js +0 -46
  97. package/dist/migrations/migrationHelper.d.ts +0 -173
  98. package/dist/migrations/migrationHelper.js +0 -130
  99. package/dist/migrations/openapi.d.ts +0 -4
  100. package/dist/migrations/openapi.js +0 -60
  101. package/dist/migrations/queue.d.ts +0 -13
  102. package/dist/migrations/queue.js +0 -79
  103. package/dist/migrations/schemaStrings.d.ts +0 -14
  104. package/dist/migrations/schemaStrings.js +0 -478
  105. package/dist/migrations/setupDatabase.d.ts +0 -6
  106. package/dist/migrations/setupDatabase.js +0 -115
  107. package/dist/migrations/storage.d.ts +0 -10
  108. package/dist/migrations/storage.js +0 -340
  109. package/dist/migrations/users.d.ts +0 -16
  110. package/dist/migrations/users.js +0 -276
  111. package/dist/migrations/validationRules.d.ts +0 -43
  112. package/dist/migrations/validationRules.js +0 -42
  113. package/dist/shared/attributeManager.d.ts +0 -17
  114. package/dist/shared/attributeManager.js +0 -272
  115. package/src/functions/openapi.ts +0 -83
  116. package/src/shared/attributeManager.ts +0 -428
@@ -0,0 +1,667 @@
1
+ /**
2
+ * LegacyAdapter - Translation Layer for Legacy Appwrite API
3
+ *
4
+ * This adapter translates TablesDB-style calls (object notation) to legacy
5
+ * Appwrite Databases API calls (positional parameters). It ensures all internal
6
+ * code can use modern TablesDB patterns while maintaining compatibility with
7
+ * older Appwrite instances.
8
+ */
9
+
10
+ import {
11
+ BaseAdapter,
12
+ type CreateRowParams,
13
+ type UpdateRowParams,
14
+ type ListRowsParams,
15
+ type DeleteRowParams,
16
+ type CreateTableParams,
17
+ type UpdateTableParams,
18
+ type ListTablesParams,
19
+ type DeleteTableParams,
20
+ type GetTableParams,
21
+ type BulkCreateRowsParams,
22
+ type BulkUpsertRowsParams,
23
+ type BulkDeleteRowsParams,
24
+ type CreateIndexParams,
25
+ type ListIndexesParams,
26
+ type DeleteIndexParams,
27
+ type CreateAttributeParams,
28
+ type UpdateAttributeParams,
29
+ type DeleteAttributeParams,
30
+ type ApiResponse,
31
+ type AdapterMetadata,
32
+ AdapterError,
33
+ UnsupportedOperationError
34
+ } from './DatabaseAdapter.js';
35
+
36
+ /**
37
+ * LegacyAdapter - Translates TablesDB calls to legacy Databases API
38
+ */
39
+ export class LegacyAdapter extends BaseAdapter {
40
+ private databases: any;
41
+
42
+ constructor(client: any) {
43
+ super(client, 'legacy');
44
+ // Assuming Databases service is available on the client
45
+ this.databases = client;
46
+ }
47
+
48
+ // Row (Document) Operations - Translate object notation to positional parameters
49
+
50
+ async listRows(params: ListRowsParams): Promise<ApiResponse> {
51
+ try {
52
+ // TablesDB: listRows({ databaseId, tableId, queries })
53
+ // Legacy: listDocuments(databaseId, collectionId, queries)
54
+ const result = await this.databases.listDocuments(
55
+ params.databaseId,
56
+ params.tableId, // Maps tableId to collectionId
57
+ params.queries || []
58
+ );
59
+
60
+ return {
61
+ data: result.documents,
62
+ rows: result.documents, // Alias for TablesDB compatibility
63
+ documents: result.documents, // Legacy format
64
+ total: result.total
65
+ };
66
+ } catch (error) {
67
+ throw new AdapterError(
68
+ `Failed to list rows (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
69
+ 'LIST_ROWS_FAILED',
70
+ error instanceof Error ? error : undefined
71
+ );
72
+ }
73
+ }
74
+
75
+ async createRow(params: CreateRowParams): Promise<ApiResponse> {
76
+ try {
77
+ // TablesDB: createRow({ databaseId, tableId, id, data, permissions })
78
+ // Legacy: createDocument(databaseId, collectionId, id, data, permissions)
79
+ const result = await this.databases.createDocument(
80
+ params.databaseId,
81
+ params.tableId, // Maps to collectionId
82
+ params.id,
83
+ params.data,
84
+ params.permissions || []
85
+ );
86
+
87
+ return {
88
+ data: result,
89
+ rows: [result],
90
+ documents: [result] // Legacy compatibility
91
+ };
92
+ } catch (error) {
93
+ throw new AdapterError(
94
+ `Failed to create row (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
95
+ 'CREATE_ROW_FAILED',
96
+ error instanceof Error ? error : undefined
97
+ );
98
+ }
99
+ }
100
+
101
+ async updateRow(params: UpdateRowParams): Promise<ApiResponse> {
102
+ try {
103
+ // TablesDB: updateRow({ databaseId, tableId, id, data, permissions })
104
+ // Legacy: updateDocument(databaseId, collectionId, id, data, permissions)
105
+ const result = await this.databases.updateDocument(
106
+ params.databaseId,
107
+ params.tableId,
108
+ params.id,
109
+ params.data,
110
+ params.permissions || []
111
+ );
112
+
113
+ return {
114
+ data: result,
115
+ rows: [result],
116
+ documents: [result]
117
+ };
118
+ } catch (error) {
119
+ throw new AdapterError(
120
+ `Failed to update row (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
121
+ 'UPDATE_ROW_FAILED',
122
+ error instanceof Error ? error : undefined
123
+ );
124
+ }
125
+ }
126
+
127
+ async deleteRow(params: DeleteRowParams): Promise<ApiResponse> {
128
+ try {
129
+ // TablesDB: deleteRow({ databaseId, tableId, id })
130
+ // Legacy: deleteDocument(databaseId, collectionId, id)
131
+ const result = await this.databases.deleteDocument(
132
+ params.databaseId,
133
+ params.tableId,
134
+ params.id
135
+ );
136
+
137
+ return { data: result };
138
+ } catch (error) {
139
+ throw new AdapterError(
140
+ `Failed to delete row (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
141
+ 'DELETE_ROW_FAILED',
142
+ error instanceof Error ? error : undefined
143
+ );
144
+ }
145
+ }
146
+
147
+ async getRow(params: { databaseId: string; tableId: string; id: string }): Promise<ApiResponse> {
148
+ try {
149
+ // TablesDB: getRow({ databaseId, tableId, id })
150
+ // Legacy: getDocument(databaseId, collectionId, id)
151
+ const result = await this.databases.getDocument(
152
+ params.databaseId,
153
+ params.tableId,
154
+ params.id
155
+ );
156
+
157
+ return {
158
+ data: result,
159
+ rows: [result],
160
+ documents: [result]
161
+ };
162
+ } catch (error) {
163
+ throw new AdapterError(
164
+ `Failed to get row (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
165
+ 'GET_ROW_FAILED',
166
+ error instanceof Error ? error : undefined
167
+ );
168
+ }
169
+ }
170
+
171
+ // Table (Collection) Operations
172
+
173
+ async listTables(params: ListTablesParams): Promise<ApiResponse> {
174
+ try {
175
+ // TablesDB: listTables({ databaseId, queries })
176
+ // Legacy: listCollections(databaseId, queries)
177
+ const result = await this.databases.listCollections(
178
+ params.databaseId,
179
+ params.queries || []
180
+ );
181
+
182
+ return {
183
+ data: result.collections,
184
+ tables: result.collections, // Alias for TablesDB compatibility
185
+ collections: result.collections, // Legacy format
186
+ total: result.total
187
+ };
188
+ } catch (error) {
189
+ throw new AdapterError(
190
+ `Failed to list tables (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
191
+ 'LIST_TABLES_FAILED',
192
+ error instanceof Error ? error : undefined
193
+ );
194
+ }
195
+ }
196
+
197
+ async createTable(params: CreateTableParams): Promise<ApiResponse> {
198
+ try {
199
+ // TablesDB: createTable({ databaseId, id, name, permissions, documentSecurity, enabled })
200
+ // Legacy: createCollection(databaseId, id, name, permissions, documentSecurity, enabled)
201
+ const result = await this.databases.createCollection(
202
+ params.databaseId,
203
+ params.id,
204
+ params.name,
205
+ params.permissions || [],
206
+ params.documentSecurity ?? false,
207
+ params.enabled ?? true
208
+ );
209
+
210
+ return {
211
+ data: result,
212
+ tables: [result],
213
+ collections: [result]
214
+ };
215
+ } catch (error) {
216
+ throw new AdapterError(
217
+ `Failed to create table (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
218
+ 'CREATE_TABLE_FAILED',
219
+ error instanceof Error ? error : undefined
220
+ );
221
+ }
222
+ }
223
+
224
+ async updateTable(params: UpdateTableParams): Promise<ApiResponse> {
225
+ try {
226
+ // TablesDB: updateTable({ databaseId, id, name, permissions, documentSecurity, enabled })
227
+ // Legacy: updateCollection(databaseId, id, name, permissions, documentSecurity, enabled)
228
+ const result = await this.databases.updateCollection(
229
+ params.databaseId,
230
+ params.id,
231
+ params.name,
232
+ params.permissions || [],
233
+ params.documentSecurity ?? false,
234
+ params.enabled ?? true
235
+ );
236
+
237
+ return {
238
+ data: result,
239
+ tables: [result],
240
+ collections: [result]
241
+ };
242
+ } catch (error) {
243
+ throw new AdapterError(
244
+ `Failed to update table (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
245
+ 'UPDATE_TABLE_FAILED',
246
+ error instanceof Error ? error : undefined
247
+ );
248
+ }
249
+ }
250
+
251
+ async deleteTable(params: DeleteTableParams): Promise<ApiResponse> {
252
+ try {
253
+ // TablesDB: deleteTable({ databaseId, tableId })
254
+ // Legacy: deleteCollection(databaseId, collectionId)
255
+ const result = await this.databases.deleteCollection(
256
+ params.databaseId,
257
+ params.tableId
258
+ );
259
+
260
+ return { data: result };
261
+ } catch (error) {
262
+ throw new AdapterError(
263
+ `Failed to delete table (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
264
+ 'DELETE_TABLE_FAILED',
265
+ error instanceof Error ? error : undefined
266
+ );
267
+ }
268
+ }
269
+
270
+ async getTable(params: GetTableParams): Promise<ApiResponse> {
271
+ try {
272
+ // TablesDB: getTable({ databaseId, tableId })
273
+ // Legacy: getCollection(databaseId, collectionId)
274
+ const result = await this.databases.getCollection(
275
+ params.databaseId,
276
+ params.tableId
277
+ );
278
+
279
+ return {
280
+ data: result,
281
+ tables: [result],
282
+ collections: [result]
283
+ };
284
+ } catch (error) {
285
+ throw new AdapterError(
286
+ `Failed to get table (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
287
+ 'GET_TABLE_FAILED',
288
+ error instanceof Error ? error : undefined
289
+ );
290
+ }
291
+ }
292
+
293
+ // Index Operations
294
+
295
+ async listIndexes(params: ListIndexesParams): Promise<ApiResponse> {
296
+ try {
297
+ // TablesDB: listIndexes({ databaseId, tableId, queries })
298
+ // Legacy: listIndexes(databaseId, collectionId, queries)
299
+ const result = await this.databases.listIndexes(
300
+ params.databaseId,
301
+ params.tableId,
302
+ params.queries || []
303
+ );
304
+
305
+ return {
306
+ data: result.indexes,
307
+ total: result.total
308
+ };
309
+ } catch (error) {
310
+ throw new AdapterError(
311
+ `Failed to list indexes (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
312
+ 'LIST_INDEXES_FAILED',
313
+ error instanceof Error ? error : undefined
314
+ );
315
+ }
316
+ }
317
+
318
+ async createIndex(params: CreateIndexParams): Promise<ApiResponse> {
319
+ try {
320
+ // TablesDB: createIndex({ databaseId, tableId, key, type, attributes, orders })
321
+ // Legacy: createIndex(databaseId, collectionId, key, type, attributes, orders)
322
+ const result = await this.databases.createIndex(
323
+ params.databaseId,
324
+ params.tableId,
325
+ params.key,
326
+ params.type,
327
+ params.attributes,
328
+ params.orders || []
329
+ );
330
+
331
+ return { data: result };
332
+ } catch (error) {
333
+ throw new AdapterError(
334
+ `Failed to create index (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
335
+ 'CREATE_INDEX_FAILED',
336
+ error instanceof Error ? error : undefined
337
+ );
338
+ }
339
+ }
340
+
341
+ async deleteIndex(params: DeleteIndexParams): Promise<ApiResponse> {
342
+ try {
343
+ // TablesDB: deleteIndex({ databaseId, tableId, key })
344
+ // Legacy: deleteIndex(databaseId, collectionId, key)
345
+ const result = await this.databases.deleteIndex(
346
+ params.databaseId,
347
+ params.tableId,
348
+ params.key
349
+ );
350
+
351
+ return { data: result };
352
+ } catch (error) {
353
+ throw new AdapterError(
354
+ `Failed to delete index (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
355
+ 'DELETE_INDEX_FAILED',
356
+ error instanceof Error ? error : undefined
357
+ );
358
+ }
359
+ }
360
+
361
+ // Attribute Operations
362
+
363
+ async createAttribute(params: CreateAttributeParams): Promise<ApiResponse> {
364
+ try {
365
+ // Legacy attribute creation varies by type, need to map different methods
366
+ let result;
367
+
368
+ switch (params.type.toLowerCase()) {
369
+ case 'string':
370
+ result = await this.databases.createStringAttribute(
371
+ params.databaseId,
372
+ params.tableId,
373
+ params.key,
374
+ params.size || 255,
375
+ params.required ?? false,
376
+ params.default,
377
+ params.array ?? false,
378
+ params.encrypt ?? false
379
+ );
380
+ break;
381
+
382
+ case 'integer':
383
+ result = await this.databases.createIntegerAttribute(
384
+ params.databaseId,
385
+ params.tableId,
386
+ params.key,
387
+ params.required ?? false,
388
+ params.min,
389
+ params.max,
390
+ params.default,
391
+ params.array ?? false
392
+ );
393
+ break;
394
+
395
+ case 'float':
396
+ case 'double':
397
+ result = await this.databases.createFloatAttribute(
398
+ params.databaseId,
399
+ params.tableId,
400
+ params.key,
401
+ params.required ?? false,
402
+ params.min,
403
+ params.max,
404
+ params.default,
405
+ params.array ?? false
406
+ );
407
+ break;
408
+
409
+ case 'boolean':
410
+ result = await this.databases.createBooleanAttribute(
411
+ params.databaseId,
412
+ params.tableId,
413
+ params.key,
414
+ params.required ?? false,
415
+ params.default,
416
+ params.array ?? false
417
+ );
418
+ break;
419
+
420
+ case 'datetime':
421
+ result = await this.databases.createDatetimeAttribute(
422
+ params.databaseId,
423
+ params.tableId,
424
+ params.key,
425
+ params.required ?? false,
426
+ params.default,
427
+ params.array ?? false
428
+ );
429
+ break;
430
+
431
+ case 'email':
432
+ result = await this.databases.createEmailAttribute(
433
+ params.databaseId,
434
+ params.tableId,
435
+ params.key,
436
+ params.required ?? false,
437
+ params.default,
438
+ params.array ?? false
439
+ );
440
+ break;
441
+
442
+ case 'enum':
443
+ result = await this.databases.createEnumAttribute(
444
+ params.databaseId,
445
+ params.tableId,
446
+ params.key,
447
+ params.elements || [],
448
+ params.required ?? false,
449
+ params.default,
450
+ params.array ?? false
451
+ );
452
+ break;
453
+
454
+ case 'ip':
455
+ result = await this.databases.createIpAttribute(
456
+ params.databaseId,
457
+ params.tableId,
458
+ params.key,
459
+ params.required ?? false,
460
+ params.default,
461
+ params.array ?? false
462
+ );
463
+ break;
464
+
465
+ case 'url':
466
+ result = await this.databases.createUrlAttribute(
467
+ params.databaseId,
468
+ params.tableId,
469
+ params.key,
470
+ params.required ?? false,
471
+ params.default,
472
+ params.array ?? false
473
+ );
474
+ break;
475
+
476
+ case 'relationship':
477
+ result = await this.databases.createRelationshipAttribute(
478
+ params.databaseId,
479
+ params.tableId,
480
+ params.key,
481
+ params.relatedCollection || '',
482
+ params.type || 'oneToOne',
483
+ params.twoWay ?? false,
484
+ params.onDelete || 'restrict'
485
+ );
486
+ break;
487
+
488
+ default:
489
+ throw new AdapterError(
490
+ `Unsupported attribute type: ${params.type}`,
491
+ 'UNSUPPORTED_ATTRIBUTE_TYPE'
492
+ );
493
+ }
494
+
495
+ return { data: result };
496
+ } catch (error) {
497
+ throw new AdapterError(
498
+ `Failed to create attribute (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
499
+ 'CREATE_ATTRIBUTE_FAILED',
500
+ error instanceof Error ? error : undefined
501
+ );
502
+ }
503
+ }
504
+
505
+ async updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse> {
506
+ try {
507
+ // TablesDB: updateAttribute({ databaseId, tableId, key, required, default })
508
+ // Legacy: updateStringAttribute, updateIntegerAttribute, etc.
509
+ // Note: Legacy API has type-specific update methods
510
+ const result = await this.databases.updateStringAttribute(
511
+ params.databaseId,
512
+ params.tableId,
513
+ params.key,
514
+ params.required ?? false,
515
+ params.default
516
+ );
517
+
518
+ return { data: result };
519
+ } catch (error) {
520
+ throw new AdapterError(
521
+ `Failed to update attribute (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
522
+ 'UPDATE_ATTRIBUTE_FAILED',
523
+ error instanceof Error ? error : undefined
524
+ );
525
+ }
526
+ }
527
+
528
+ async deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse> {
529
+ try {
530
+ // TablesDB: deleteAttribute({ databaseId, tableId, key })
531
+ // Legacy: deleteAttribute(databaseId, collectionId, key)
532
+ const result = await this.databases.deleteAttribute(
533
+ params.databaseId,
534
+ params.tableId,
535
+ params.key
536
+ );
537
+
538
+ return { data: result };
539
+ } catch (error) {
540
+ throw new AdapterError(
541
+ `Failed to delete attribute (legacy): ${error instanceof Error ? error.message : 'Unknown error'}`,
542
+ 'DELETE_ATTRIBUTE_FAILED',
543
+ error instanceof Error ? error : undefined
544
+ );
545
+ }
546
+ }
547
+
548
+ // Bulk Operations - Not natively supported in legacy, provide fallback
549
+
550
+ async bulkCreateRows(params: BulkCreateRowsParams): Promise<ApiResponse> {
551
+ // Legacy doesn't support bulk operations, fallback to individual creates
552
+ const results = [];
553
+ const errors = [];
554
+
555
+ for (const row of params.rows) {
556
+ try {
557
+ const result = await this.createRow({
558
+ databaseId: params.databaseId,
559
+ tableId: params.tableId,
560
+ id: row.$id || 'unique()', // Generate unique ID if not provided
561
+ data: row,
562
+ permissions: row.$permissions
563
+ });
564
+ results.push(result.data);
565
+ } catch (error) {
566
+ errors.push({
567
+ row,
568
+ error: error instanceof Error ? error.message : 'Unknown error'
569
+ });
570
+ }
571
+ }
572
+
573
+ if (errors.length > 0) {
574
+ console.warn(`Bulk create had ${errors.length} failures out of ${params.rows.length} total rows`);
575
+ }
576
+
577
+ return {
578
+ data: results,
579
+ rows: results,
580
+ total: results.length,
581
+ errors: errors.length > 0 ? errors : undefined
582
+ };
583
+ }
584
+
585
+ async bulkUpsertRows(params: BulkUpsertRowsParams): Promise<ApiResponse> {
586
+ throw new UnsupportedOperationError('bulkUpsertRows', 'legacy');
587
+ }
588
+
589
+ async bulkDeleteRows(params: BulkDeleteRowsParams): Promise<ApiResponse> {
590
+ // Legacy doesn't support bulk operations, fallback to individual deletes
591
+ const results = [];
592
+ const errors = [];
593
+
594
+ for (const rowId of params.rowIds) {
595
+ try {
596
+ await this.deleteRow({
597
+ databaseId: params.databaseId,
598
+ tableId: params.tableId,
599
+ id: rowId
600
+ });
601
+ results.push({ id: rowId, deleted: true });
602
+ } catch (error) {
603
+ errors.push({
604
+ rowId,
605
+ error: error instanceof Error ? error.message : 'Unknown error'
606
+ });
607
+ }
608
+ }
609
+
610
+ return {
611
+ data: results,
612
+ total: results.length,
613
+ errors: errors.length > 0 ? errors : undefined
614
+ };
615
+ }
616
+
617
+ // Metadata and Capabilities
618
+
619
+ getMetadata(): AdapterMetadata {
620
+ return {
621
+ apiMode: 'legacy',
622
+ terminology: {
623
+ container: 'collection',
624
+ item: 'document',
625
+ service: 'Databases'
626
+ },
627
+ capabilities: {
628
+ bulkOperations: false, // Legacy doesn't support native bulk ops
629
+ advancedQueries: true,
630
+ realtime: true,
631
+ transactions: false
632
+ }
633
+ };
634
+ }
635
+
636
+ supportsBulkOperations(): boolean {
637
+ return false; // Legacy uses individual operation fallbacks
638
+ }
639
+
640
+ // Legacy-specific helper methods
641
+
642
+ /**
643
+ * Check if endpoint supports bulk operations via HTTP (for cloud instances)
644
+ */
645
+ private supportsHttpBulkOperations(endpoint: string): boolean {
646
+ return endpoint.includes('cloud.appwrite.io');
647
+ }
648
+
649
+ /**
650
+ * Normalize response format to be consistent with TablesDB
651
+ */
652
+ private normalizeResponse(response: any, type: 'row' | 'table'): ApiResponse {
653
+ if (type === 'row') {
654
+ return {
655
+ data: response,
656
+ rows: Array.isArray(response) ? response : [response],
657
+ documents: Array.isArray(response) ? response : [response]
658
+ };
659
+ } else {
660
+ return {
661
+ data: response,
662
+ tables: Array.isArray(response) ? response : [response],
663
+ collections: Array.isArray(response) ? response : [response]
664
+ };
665
+ }
666
+ }
667
+ }