appwrite-utils-cli 1.3.4 → 1.4.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 (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 +43 -24
  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 +351 -157
  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,429 @@
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 {
10
+ BaseAdapter,
11
+ type DatabaseAdapter,
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
+ } from './DatabaseAdapter.js';
34
+
35
+ /**
36
+ * TablesDBAdapter implementation for native TablesDB API
37
+ */
38
+ export class TablesDBAdapter extends BaseAdapter {
39
+ private tablesDB: any;
40
+
41
+ constructor(client: any) {
42
+ super(client, 'tablesdb');
43
+ // Assuming TablesDB service is available on the client
44
+ this.tablesDB = client.tablesDB || client;
45
+ }
46
+
47
+ // Row (Document) Operations
48
+ async listRows(params: ListRowsParams): Promise<ApiResponse> {
49
+ try {
50
+ const result = await this.tablesDB.listRows(params);
51
+ return {
52
+ data: result.rows,
53
+ rows: result.rows,
54
+ total: result.total
55
+ };
56
+ } catch (error) {
57
+ throw new AdapterError(
58
+ `Failed to list rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
59
+ 'LIST_ROWS_FAILED',
60
+ error instanceof Error ? error : undefined
61
+ );
62
+ }
63
+ }
64
+
65
+ async createRow(params: CreateRowParams): Promise<ApiResponse> {
66
+ try {
67
+ const result = await this.tablesDB.createRow(params);
68
+ return {
69
+ data: result,
70
+ rows: [result]
71
+ };
72
+ } catch (error) {
73
+ throw new AdapterError(
74
+ `Failed to create row: ${error instanceof Error ? error.message : 'Unknown error'}`,
75
+ 'CREATE_ROW_FAILED',
76
+ error instanceof Error ? error : undefined
77
+ );
78
+ }
79
+ }
80
+
81
+ async updateRow(params: UpdateRowParams): Promise<ApiResponse> {
82
+ try {
83
+ const result = await this.tablesDB.updateRow(params);
84
+ return {
85
+ data: result,
86
+ rows: [result]
87
+ };
88
+ } catch (error) {
89
+ throw new AdapterError(
90
+ `Failed to update row: ${error instanceof Error ? error.message : 'Unknown error'}`,
91
+ 'UPDATE_ROW_FAILED',
92
+ error instanceof Error ? error : undefined
93
+ );
94
+ }
95
+ }
96
+
97
+ async deleteRow(params: DeleteRowParams): Promise<ApiResponse> {
98
+ try {
99
+ const result = await this.tablesDB.deleteRow(params);
100
+ return { data: result };
101
+ } catch (error) {
102
+ throw new AdapterError(
103
+ `Failed to delete row: ${error instanceof Error ? error.message : 'Unknown error'}`,
104
+ 'DELETE_ROW_FAILED',
105
+ error instanceof Error ? error : undefined
106
+ );
107
+ }
108
+ }
109
+
110
+ async getRow(params: { databaseId: string; tableId: string; id: string }): Promise<ApiResponse> {
111
+ try {
112
+ const result = await this.tablesDB.getRow(params);
113
+ return {
114
+ data: result,
115
+ rows: [result]
116
+ };
117
+ } catch (error) {
118
+ throw new AdapterError(
119
+ `Failed to get row: ${error instanceof Error ? error.message : 'Unknown error'}`,
120
+ 'GET_ROW_FAILED',
121
+ error instanceof Error ? error : undefined
122
+ );
123
+ }
124
+ }
125
+
126
+ // Table (Collection) Operations
127
+ async listTables(params: ListTablesParams): Promise<ApiResponse> {
128
+ try {
129
+ const result = await this.tablesDB.listTables(params);
130
+ return {
131
+ data: result.tables,
132
+ tables: result.tables,
133
+ total: result.total
134
+ };
135
+ } catch (error) {
136
+ throw new AdapterError(
137
+ `Failed to list tables: ${error instanceof Error ? error.message : 'Unknown error'}`,
138
+ 'LIST_TABLES_FAILED',
139
+ error instanceof Error ? error : undefined
140
+ );
141
+ }
142
+ }
143
+
144
+ async createTable(params: CreateTableParams): Promise<ApiResponse> {
145
+ try {
146
+ const result = await this.tablesDB.createTable(params);
147
+ return {
148
+ data: result,
149
+ tables: [result]
150
+ };
151
+ } catch (error) {
152
+ throw new AdapterError(
153
+ `Failed to create table: ${error instanceof Error ? error.message : 'Unknown error'}`,
154
+ 'CREATE_TABLE_FAILED',
155
+ error instanceof Error ? error : undefined
156
+ );
157
+ }
158
+ }
159
+
160
+ async updateTable(params: UpdateTableParams): Promise<ApiResponse> {
161
+ try {
162
+ const result = await this.tablesDB.updateTable(params);
163
+ return {
164
+ data: result,
165
+ tables: [result]
166
+ };
167
+ } catch (error) {
168
+ throw new AdapterError(
169
+ `Failed to update table: ${error instanceof Error ? error.message : 'Unknown error'}`,
170
+ 'UPDATE_TABLE_FAILED',
171
+ error instanceof Error ? error : undefined
172
+ );
173
+ }
174
+ }
175
+
176
+ async deleteTable(params: DeleteTableParams): Promise<ApiResponse> {
177
+ try {
178
+ const result = await this.tablesDB.deleteTable(params);
179
+ return { data: result };
180
+ } catch (error) {
181
+ throw new AdapterError(
182
+ `Failed to delete table: ${error instanceof Error ? error.message : 'Unknown error'}`,
183
+ 'DELETE_TABLE_FAILED',
184
+ error instanceof Error ? error : undefined
185
+ );
186
+ }
187
+ }
188
+
189
+ async getTable(params: GetTableParams): Promise<ApiResponse> {
190
+ try {
191
+ const result = await this.tablesDB.getTable(params);
192
+ return {
193
+ data: result,
194
+ tables: [result]
195
+ };
196
+ } catch (error) {
197
+ throw new AdapterError(
198
+ `Failed to get table: ${error instanceof Error ? error.message : 'Unknown error'}`,
199
+ 'GET_TABLE_FAILED',
200
+ error instanceof Error ? error : undefined
201
+ );
202
+ }
203
+ }
204
+
205
+ // Index Operations
206
+ async listIndexes(params: ListIndexesParams): Promise<ApiResponse> {
207
+ try {
208
+ const result = await this.tablesDB.listIndexes(params);
209
+ return {
210
+ data: result.indexes,
211
+ total: result.total
212
+ };
213
+ } catch (error) {
214
+ throw new AdapterError(
215
+ `Failed to list indexes: ${error instanceof Error ? error.message : 'Unknown error'}`,
216
+ 'LIST_INDEXES_FAILED',
217
+ error instanceof Error ? error : undefined
218
+ );
219
+ }
220
+ }
221
+
222
+ async createIndex(params: CreateIndexParams): Promise<ApiResponse> {
223
+ try {
224
+ const result = await this.tablesDB.createIndex(params);
225
+ return { data: result };
226
+ } catch (error) {
227
+ throw new AdapterError(
228
+ `Failed to create index: ${error instanceof Error ? error.message : 'Unknown error'}`,
229
+ 'CREATE_INDEX_FAILED',
230
+ error instanceof Error ? error : undefined
231
+ );
232
+ }
233
+ }
234
+
235
+ async deleteIndex(params: DeleteIndexParams): Promise<ApiResponse> {
236
+ try {
237
+ const result = await this.tablesDB.deleteIndex(params);
238
+ return { data: result };
239
+ } catch (error) {
240
+ throw new AdapterError(
241
+ `Failed to delete index: ${error instanceof Error ? error.message : 'Unknown error'}`,
242
+ 'DELETE_INDEX_FAILED',
243
+ error instanceof Error ? error : undefined
244
+ );
245
+ }
246
+ }
247
+
248
+ // Attribute Operations
249
+ async createAttribute(params: CreateAttributeParams): Promise<ApiResponse> {
250
+ try {
251
+ // TablesDB may have different method names for attribute operations
252
+ const result = await this.tablesDB.createAttribute(params);
253
+ return { data: result };
254
+ } catch (error) {
255
+ throw new AdapterError(
256
+ `Failed to create attribute: ${error instanceof Error ? error.message : 'Unknown error'}`,
257
+ 'CREATE_ATTRIBUTE_FAILED',
258
+ error instanceof Error ? error : undefined
259
+ );
260
+ }
261
+ }
262
+
263
+ async updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse> {
264
+ try {
265
+ const result = await this.tablesDB.updateAttribute(params);
266
+ return { data: result };
267
+ } catch (error) {
268
+ throw new AdapterError(
269
+ `Failed to update attribute: ${error instanceof Error ? error.message : 'Unknown error'}`,
270
+ 'UPDATE_ATTRIBUTE_FAILED',
271
+ error instanceof Error ? error : undefined
272
+ );
273
+ }
274
+ }
275
+
276
+ async deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse> {
277
+ try {
278
+ const result = await this.tablesDB.deleteAttribute(params);
279
+ return { data: result };
280
+ } catch (error) {
281
+ throw new AdapterError(
282
+ `Failed to delete attribute: ${error instanceof Error ? error.message : 'Unknown error'}`,
283
+ 'DELETE_ATTRIBUTE_FAILED',
284
+ error instanceof Error ? error : undefined
285
+ );
286
+ }
287
+ }
288
+
289
+ // Bulk Operations (Native TablesDB Support)
290
+ async bulkCreateRows(params: BulkCreateRowsParams): Promise<ApiResponse> {
291
+ try {
292
+ const result = await this.tablesDB.bulkCreateRows(params);
293
+ return {
294
+ data: result.rows,
295
+ rows: result.rows,
296
+ total: result.rows?.length || 0
297
+ };
298
+ } catch (error) {
299
+ throw new AdapterError(
300
+ `Failed to bulk create rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
301
+ 'BULK_CREATE_ROWS_FAILED',
302
+ error instanceof Error ? error : undefined
303
+ );
304
+ }
305
+ }
306
+
307
+ async bulkUpsertRows(params: BulkUpsertRowsParams): Promise<ApiResponse> {
308
+ try {
309
+ const result = await this.tablesDB.bulkUpsertRows(params);
310
+ return {
311
+ data: result.rows,
312
+ rows: result.rows,
313
+ total: result.rows?.length || 0
314
+ };
315
+ } catch (error) {
316
+ throw new AdapterError(
317
+ `Failed to bulk upsert rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
318
+ 'BULK_UPSERT_ROWS_FAILED',
319
+ error instanceof Error ? error : undefined
320
+ );
321
+ }
322
+ }
323
+
324
+ async bulkDeleteRows(params: BulkDeleteRowsParams): Promise<ApiResponse> {
325
+ try {
326
+ const result = await this.tablesDB.bulkDeleteRows(params);
327
+ return {
328
+ data: result,
329
+ total: params.rowIds.length
330
+ };
331
+ } catch (error) {
332
+ throw new AdapterError(
333
+ `Failed to bulk delete rows: ${error instanceof Error ? error.message : 'Unknown error'}`,
334
+ 'BULK_DELETE_ROWS_FAILED',
335
+ error instanceof Error ? error : undefined
336
+ );
337
+ }
338
+ }
339
+
340
+ // Metadata and Capabilities
341
+ getMetadata(): AdapterMetadata {
342
+ return {
343
+ apiMode: 'tablesdb',
344
+ terminology: {
345
+ container: 'table',
346
+ item: 'row',
347
+ service: 'TablesDB'
348
+ },
349
+ capabilities: {
350
+ bulkOperations: true,
351
+ advancedQueries: true,
352
+ realtime: true,
353
+ transactions: true // TablesDB may support transactions
354
+ }
355
+ };
356
+ }
357
+
358
+ supportsBulkOperations(): boolean {
359
+ return true; // TablesDB natively supports bulk operations
360
+ }
361
+
362
+ // Advanced TablesDB Features
363
+
364
+ /**
365
+ * Execute a transaction (if supported by TablesDB)
366
+ */
367
+ async executeTransaction(operations: Array<() => Promise<any>>): Promise<ApiResponse> {
368
+ if (!this.tablesDB.transaction) {
369
+ throw new AdapterError(
370
+ 'Transactions are not supported in this TablesDB version',
371
+ 'TRANSACTIONS_NOT_SUPPORTED'
372
+ );
373
+ }
374
+
375
+ try {
376
+ const result = await this.tablesDB.transaction(operations);
377
+ return { data: result };
378
+ } catch (error) {
379
+ throw new AdapterError(
380
+ `Transaction failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
381
+ 'TRANSACTION_FAILED',
382
+ error instanceof Error ? error : undefined
383
+ );
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Subscribe to real-time updates (if supported)
389
+ */
390
+ subscribeToTable(params: { databaseId: string; tableId: string }, callback: (data: any) => void): () => void {
391
+ if (!this.tablesDB.subscribe) {
392
+ throw new AdapterError(
393
+ 'Real-time subscriptions are not supported',
394
+ 'REALTIME_NOT_SUPPORTED'
395
+ );
396
+ }
397
+
398
+ try {
399
+ return this.tablesDB.subscribe(`databases.${params.databaseId}.tables.${params.tableId}.rows`, callback);
400
+ } catch (error) {
401
+ throw new AdapterError(
402
+ `Failed to subscribe to table: ${error instanceof Error ? error.message : 'Unknown error'}`,
403
+ 'SUBSCRIPTION_FAILED',
404
+ error instanceof Error ? error : undefined
405
+ );
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Get table statistics (if available in TablesDB)
411
+ */
412
+ async getTableStats(params: GetTableParams): Promise<ApiResponse> {
413
+ try {
414
+ if (!this.tablesDB.getTableStats) {
415
+ // Fallback to basic table info
416
+ return this.getTable(params);
417
+ }
418
+
419
+ const result = await this.tablesDB.getTableStats(params);
420
+ return { data: result };
421
+ } catch (error) {
422
+ throw new AdapterError(
423
+ `Failed to get table stats: ${error instanceof Error ? error.message : 'Unknown error'}`,
424
+ 'GET_TABLE_STATS_FAILED',
425
+ error instanceof Error ? error : undefined
426
+ );
427
+ }
428
+ }
429
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Adapters Module - Unified Database API for Appwrite
3
+ *
4
+ * This module exports all adapter classes and utilities for working with
5
+ * both legacy Appwrite (collections/documents) and TablesDB (tables/rows) APIs.
6
+ */
7
+
8
+ export { AdapterFactory, type AdapterFactoryConfig, type AdapterFactoryResult } from './AdapterFactory.js';
9
+ export {
10
+ type DatabaseAdapter,
11
+ type CreateRowParams,
12
+ type UpdateRowParams,
13
+ type ListRowsParams,
14
+ type DeleteRowParams,
15
+ type CreateTableParams,
16
+ type UpdateTableParams,
17
+ type ListTablesParams,
18
+ type DeleteTableParams,
19
+ type GetTableParams,
20
+ type BulkCreateRowsParams,
21
+ type BulkUpsertRowsParams,
22
+ type BulkDeleteRowsParams,
23
+ type CreateIndexParams,
24
+ type ListIndexesParams,
25
+ type DeleteIndexParams,
26
+ type CreateAttributeParams,
27
+ type UpdateAttributeParams,
28
+ type DeleteAttributeParams,
29
+ type ApiResponse,
30
+ type AdapterMetadata,
31
+ BaseAdapter
32
+ } from './DatabaseAdapter.js';
33
+ export { TablesDBAdapter } from './TablesDBAdapter.js';
34
+ export { LegacyAdapter } from './LegacyAdapter.js';
35
+
36
+ // Convenience exports
37
+ export { createDatabaseAdapter, getApiCapabilities } from './AdapterFactory.js';