appwrite-utils-cli 1.3.5 → 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 +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,87 @@
1
+ /**
2
+ * AdapterFactory - Unified Client Creation with Automatic API Detection
3
+ *
4
+ * This factory creates the appropriate database adapter (TablesDB or Legacy)
5
+ * based on version detection and configuration. It handles dynamic SDK imports
6
+ * and provides a single entry point for all database operations.
7
+ */
8
+ import type { AppwriteConfig } from "appwrite-utils";
9
+ import { type ApiMode, type VersionDetectionResult } from "../utils/versionDetection.js";
10
+ import type { DatabaseAdapter } from './DatabaseAdapter.js';
11
+ export interface AdapterFactoryConfig {
12
+ appwriteEndpoint: string;
13
+ appwriteProject: string;
14
+ appwriteKey: string;
15
+ apiMode?: 'auto' | 'legacy' | 'tablesdb';
16
+ forceRefresh?: boolean;
17
+ }
18
+ export interface AdapterFactoryResult {
19
+ adapter: DatabaseAdapter;
20
+ apiMode: ApiMode;
21
+ detectionResult?: VersionDetectionResult;
22
+ client: any;
23
+ }
24
+ /**
25
+ * AdapterFactory - Main factory class for creating database adapters
26
+ */
27
+ export declare class AdapterFactory {
28
+ private static cache;
29
+ private static readonly CACHE_DURATION;
30
+ /**
31
+ * Create a database adapter based on configuration and detection
32
+ */
33
+ static create(config: AdapterFactoryConfig): Promise<AdapterFactoryResult>;
34
+ /**
35
+ * Create adapter from AppwriteConfig (convenience method)
36
+ */
37
+ static createFromConfig(config: AppwriteConfig, forceRefresh?: boolean): Promise<AdapterFactoryResult>;
38
+ /**
39
+ * Create specific adapter type (internal method)
40
+ */
41
+ private static createAdapter;
42
+ /**
43
+ * Create TablesDB adapter with dynamic import
44
+ */
45
+ private static createTablesDBAdapter;
46
+ /**
47
+ * Create Legacy adapter with dynamic import
48
+ */
49
+ private static createLegacyAdapter;
50
+ /**
51
+ * Get cached adapter if available and not expired
52
+ */
53
+ private static getCachedAdapter;
54
+ /**
55
+ * Cache adapter instance
56
+ */
57
+ private static setCachedAdapter;
58
+ /**
59
+ * Clear adapter cache (useful for testing)
60
+ */
61
+ static clearCache(): void;
62
+ /**
63
+ * Test connection and API capabilities
64
+ */
65
+ static testConnection(config: AdapterFactoryConfig): Promise<{
66
+ success: boolean;
67
+ apiMode: ApiMode;
68
+ capabilities: string[];
69
+ error?: string;
70
+ }>;
71
+ }
72
+ /**
73
+ * Convenience function for quick adapter creation
74
+ */
75
+ export declare function createDatabaseAdapter(endpoint: string, project: string, apiKey: string, mode?: 'auto' | 'legacy' | 'tablesdb'): Promise<DatabaseAdapter>;
76
+ /**
77
+ * Helper function to get adapter metadata without creating full adapter
78
+ */
79
+ export declare function getApiCapabilities(endpoint: string, project: string, apiKey: string): Promise<{
80
+ apiMode: ApiMode;
81
+ terminology: {
82
+ container: string;
83
+ item: string;
84
+ service: string;
85
+ };
86
+ capabilities: string[];
87
+ }>;
@@ -0,0 +1,217 @@
1
+ /**
2
+ * AdapterFactory - Unified Client Creation with Automatic API Detection
3
+ *
4
+ * This factory creates the appropriate database adapter (TablesDB or Legacy)
5
+ * based on version detection and configuration. It handles dynamic SDK imports
6
+ * and provides a single entry point for all database operations.
7
+ */
8
+ import { detectAppwriteVersionCached } from "../utils/versionDetection.js";
9
+ import { TablesDBAdapter } from './TablesDBAdapter.js';
10
+ import { LegacyAdapter } from './LegacyAdapter.js';
11
+ /**
12
+ * AdapterFactory - Main factory class for creating database adapters
13
+ */
14
+ export class AdapterFactory {
15
+ static cache = new Map();
16
+ static CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
17
+ /**
18
+ * Create a database adapter based on configuration and detection
19
+ */
20
+ static async create(config) {
21
+ const cacheKey = `${config.appwriteEndpoint}:${config.appwriteProject}:${config.apiMode || 'auto'}`;
22
+ // Check cache first (unless force refresh)
23
+ if (!config.forceRefresh) {
24
+ const cached = this.getCachedAdapter(cacheKey);
25
+ if (cached) {
26
+ return {
27
+ adapter: cached.adapter,
28
+ apiMode: cached.adapter.getApiMode(),
29
+ client: cached.adapter.getRawClient()
30
+ };
31
+ }
32
+ }
33
+ // Determine API mode
34
+ let apiMode;
35
+ let detectionResult;
36
+ if (config.apiMode && config.apiMode !== 'auto') {
37
+ // Use explicitly configured mode
38
+ apiMode = config.apiMode;
39
+ }
40
+ else {
41
+ // Auto-detect API mode
42
+ detectionResult = await detectAppwriteVersionCached(config.appwriteEndpoint, config.appwriteProject, config.appwriteKey, config.forceRefresh);
43
+ apiMode = detectionResult.apiMode;
44
+ }
45
+ // Create appropriate adapter
46
+ const result = await this.createAdapter(config, apiMode);
47
+ // Cache the result
48
+ this.setCachedAdapter(cacheKey, result.adapter);
49
+ return {
50
+ ...result,
51
+ apiMode,
52
+ detectionResult
53
+ };
54
+ }
55
+ /**
56
+ * Create adapter from AppwriteConfig (convenience method)
57
+ */
58
+ static async createFromConfig(config, forceRefresh) {
59
+ return this.create({
60
+ appwriteEndpoint: config.appwriteEndpoint,
61
+ appwriteProject: config.appwriteProject,
62
+ appwriteKey: config.appwriteKey,
63
+ apiMode: config.apiMode || 'auto', // Cast to access new property
64
+ forceRefresh
65
+ });
66
+ }
67
+ /**
68
+ * Create specific adapter type (internal method)
69
+ */
70
+ static async createAdapter(config, apiMode) {
71
+ if (apiMode === 'tablesdb') {
72
+ return this.createTablesDBAdapter(config);
73
+ }
74
+ else {
75
+ return this.createLegacyAdapter(config);
76
+ }
77
+ }
78
+ /**
79
+ * Create TablesDB adapter with dynamic import
80
+ */
81
+ static async createTablesDBAdapter(config) {
82
+ try {
83
+ // Dynamic import of TablesDB SDK
84
+ const { Client, TablesDB } = await import('node-appwrite-tablesdb');
85
+ const client = new Client()
86
+ .setEndpoint(config.appwriteEndpoint)
87
+ .setProject(config.appwriteProject)
88
+ .setKey(config.appwriteKey);
89
+ const tablesDB = new TablesDB(client);
90
+ const adapter = new TablesDBAdapter(tablesDB);
91
+ return { adapter, client };
92
+ }
93
+ catch (error) {
94
+ console.warn('Failed to load TablesDB SDK, falling back to legacy:', error);
95
+ // Fallback to legacy adapter if TablesDB SDK is not available
96
+ return this.createLegacyAdapter(config);
97
+ }
98
+ }
99
+ /**
100
+ * Create Legacy adapter with dynamic import
101
+ */
102
+ static async createLegacyAdapter(config) {
103
+ try {
104
+ // Dynamic import of legacy SDK
105
+ const { Client, Databases } = await import('node-appwrite');
106
+ const client = new Client()
107
+ .setEndpoint(config.appwriteEndpoint)
108
+ .setProject(config.appwriteProject)
109
+ .setKey(config.appwriteKey);
110
+ const databases = new Databases(client);
111
+ const adapter = new LegacyAdapter(databases);
112
+ return { adapter, client };
113
+ }
114
+ catch (error) {
115
+ throw new Error(`Failed to load legacy Appwrite SDK: ${error instanceof Error ? error.message : 'Unknown error'}`);
116
+ }
117
+ }
118
+ /**
119
+ * Get cached adapter if available and not expired
120
+ */
121
+ static getCachedAdapter(cacheKey) {
122
+ const cached = this.cache.get(cacheKey);
123
+ if (!cached) {
124
+ return null;
125
+ }
126
+ // Check if cache is expired
127
+ if (Date.now() - cached.timestamp > this.CACHE_DURATION) {
128
+ this.cache.delete(cacheKey);
129
+ return null;
130
+ }
131
+ return cached;
132
+ }
133
+ /**
134
+ * Cache adapter instance
135
+ */
136
+ static setCachedAdapter(cacheKey, adapter) {
137
+ this.cache.set(cacheKey, {
138
+ adapter,
139
+ timestamp: Date.now()
140
+ });
141
+ }
142
+ /**
143
+ * Clear adapter cache (useful for testing)
144
+ */
145
+ static clearCache() {
146
+ this.cache.clear();
147
+ }
148
+ /**
149
+ * Test connection and API capabilities
150
+ */
151
+ static async testConnection(config) {
152
+ try {
153
+ const result = await this.create({ ...config, forceRefresh: true });
154
+ const metadata = result.adapter.getMetadata();
155
+ // Test basic operations
156
+ const capabilities = [];
157
+ if (metadata.capabilities.bulkOperations) {
158
+ capabilities.push('Bulk Operations');
159
+ }
160
+ if (metadata.capabilities.advancedQueries) {
161
+ capabilities.push('Advanced Queries');
162
+ }
163
+ if (metadata.capabilities.realtime) {
164
+ capabilities.push('Realtime');
165
+ }
166
+ if (metadata.capabilities.transactions) {
167
+ capabilities.push('Transactions');
168
+ }
169
+ return {
170
+ success: true,
171
+ apiMode: result.apiMode,
172
+ capabilities
173
+ };
174
+ }
175
+ catch (error) {
176
+ return {
177
+ success: false,
178
+ apiMode: 'legacy', // Default fallback
179
+ capabilities: [],
180
+ error: error instanceof Error ? error.message : 'Unknown error'
181
+ };
182
+ }
183
+ }
184
+ }
185
+ /**
186
+ * Convenience function for quick adapter creation
187
+ */
188
+ export async function createDatabaseAdapter(endpoint, project, apiKey, mode = 'auto') {
189
+ const result = await AdapterFactory.create({
190
+ appwriteEndpoint: endpoint,
191
+ appwriteProject: project,
192
+ appwriteKey: apiKey,
193
+ apiMode: mode
194
+ });
195
+ return result.adapter;
196
+ }
197
+ /**
198
+ * Helper function to get adapter metadata without creating full adapter
199
+ */
200
+ export async function getApiCapabilities(endpoint, project, apiKey) {
201
+ const adapter = await createDatabaseAdapter(endpoint, project, apiKey, 'auto');
202
+ const metadata = adapter.getMetadata();
203
+ const capabilities = [];
204
+ if (metadata.capabilities.bulkOperations)
205
+ capabilities.push('Bulk Operations');
206
+ if (metadata.capabilities.advancedQueries)
207
+ capabilities.push('Advanced Queries');
208
+ if (metadata.capabilities.realtime)
209
+ capabilities.push('Realtime');
210
+ if (metadata.capabilities.transactions)
211
+ capabilities.push('Transactions');
212
+ return {
213
+ apiMode: metadata.apiMode,
214
+ terminology: metadata.terminology,
215
+ capabilities
216
+ };
217
+ }
@@ -0,0 +1,217 @@
1
+ /**
2
+ * DatabaseAdapter Interface - Unified API for Appwrite Database Operations
3
+ *
4
+ * This interface provides a unified way to interact with both legacy Appwrite
5
+ * (collections/documents) and new TablesDB (tables/rows) APIs. All internal
6
+ * code uses TablesDB-style method signatures for consistency.
7
+ */
8
+ import type { ApiMode } from "../utils/versionDetection.js";
9
+ export interface CreateRowParams {
10
+ databaseId: string;
11
+ tableId: string;
12
+ id: string;
13
+ data: any;
14
+ permissions?: string[];
15
+ }
16
+ export interface UpdateRowParams {
17
+ databaseId: string;
18
+ tableId: string;
19
+ id: string;
20
+ data?: any;
21
+ permissions?: string[];
22
+ }
23
+ export interface ListRowsParams {
24
+ databaseId: string;
25
+ tableId: string;
26
+ queries?: any[];
27
+ }
28
+ export interface DeleteRowParams {
29
+ databaseId: string;
30
+ tableId: string;
31
+ id: string;
32
+ }
33
+ export interface CreateTableParams {
34
+ databaseId: string;
35
+ id: string;
36
+ name: string;
37
+ permissions?: string[];
38
+ documentSecurity?: boolean;
39
+ enabled?: boolean;
40
+ }
41
+ export interface UpdateTableParams {
42
+ databaseId: string;
43
+ id: string;
44
+ name: string;
45
+ permissions?: string[];
46
+ documentSecurity?: boolean;
47
+ enabled?: boolean;
48
+ }
49
+ export interface ListTablesParams {
50
+ databaseId: string;
51
+ queries?: any[];
52
+ }
53
+ export interface DeleteTableParams {
54
+ databaseId: string;
55
+ tableId: string;
56
+ }
57
+ export interface GetTableParams {
58
+ databaseId: string;
59
+ tableId: string;
60
+ }
61
+ export interface BulkCreateRowsParams {
62
+ databaseId: string;
63
+ tableId: string;
64
+ rows: any[];
65
+ }
66
+ export interface BulkUpsertRowsParams {
67
+ databaseId: string;
68
+ tableId: string;
69
+ rows: any[];
70
+ }
71
+ export interface BulkDeleteRowsParams {
72
+ databaseId: string;
73
+ tableId: string;
74
+ rowIds: string[];
75
+ }
76
+ export interface CreateIndexParams {
77
+ databaseId: string;
78
+ tableId: string;
79
+ key: string;
80
+ type: string;
81
+ attributes: string[];
82
+ orders?: string[];
83
+ }
84
+ export interface ListIndexesParams {
85
+ databaseId: string;
86
+ tableId: string;
87
+ queries?: any[];
88
+ }
89
+ export interface DeleteIndexParams {
90
+ databaseId: string;
91
+ tableId: string;
92
+ key: string;
93
+ }
94
+ export interface CreateAttributeParams {
95
+ databaseId: string;
96
+ tableId: string;
97
+ key: string;
98
+ type: string;
99
+ size?: number;
100
+ required?: boolean;
101
+ default?: any;
102
+ array?: boolean;
103
+ encrypt?: boolean;
104
+ [key: string]: any;
105
+ }
106
+ export interface UpdateAttributeParams {
107
+ databaseId: string;
108
+ tableId: string;
109
+ key: string;
110
+ required?: boolean;
111
+ default?: any;
112
+ }
113
+ export interface DeleteAttributeParams {
114
+ databaseId: string;
115
+ tableId: string;
116
+ key: string;
117
+ }
118
+ export interface ApiResponse<T = any> {
119
+ data?: T;
120
+ total?: number;
121
+ documents?: T[];
122
+ rows?: T[];
123
+ collections?: T[];
124
+ tables?: T[];
125
+ errors?: any[];
126
+ }
127
+ export interface AdapterMetadata {
128
+ apiMode: ApiMode;
129
+ terminology: {
130
+ container: 'collection' | 'table';
131
+ item: 'document' | 'row';
132
+ service: 'Databases' | 'TablesDB';
133
+ };
134
+ capabilities: {
135
+ bulkOperations: boolean;
136
+ advancedQueries: boolean;
137
+ realtime: boolean;
138
+ transactions?: boolean;
139
+ };
140
+ }
141
+ /**
142
+ * Main DatabaseAdapter interface - all implementations must support these methods
143
+ */
144
+ export interface DatabaseAdapter {
145
+ listRows(params: ListRowsParams): Promise<ApiResponse>;
146
+ createRow(params: CreateRowParams): Promise<ApiResponse>;
147
+ updateRow(params: UpdateRowParams): Promise<ApiResponse>;
148
+ deleteRow(params: DeleteRowParams): Promise<ApiResponse>;
149
+ getRow(params: {
150
+ databaseId: string;
151
+ tableId: string;
152
+ id: string;
153
+ }): Promise<ApiResponse>;
154
+ listTables(params: ListTablesParams): Promise<ApiResponse>;
155
+ createTable(params: CreateTableParams): Promise<ApiResponse>;
156
+ updateTable(params: UpdateTableParams): Promise<ApiResponse>;
157
+ deleteTable(params: DeleteTableParams): Promise<ApiResponse>;
158
+ getTable(params: GetTableParams): Promise<ApiResponse>;
159
+ listIndexes(params: ListIndexesParams): Promise<ApiResponse>;
160
+ createIndex(params: CreateIndexParams): Promise<ApiResponse>;
161
+ deleteIndex(params: DeleteIndexParams): Promise<ApiResponse>;
162
+ createAttribute(params: CreateAttributeParams): Promise<ApiResponse>;
163
+ updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse>;
164
+ deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse>;
165
+ bulkCreateRows?(params: BulkCreateRowsParams): Promise<ApiResponse>;
166
+ bulkUpsertRows?(params: BulkUpsertRowsParams): Promise<ApiResponse>;
167
+ bulkDeleteRows?(params: BulkDeleteRowsParams): Promise<ApiResponse>;
168
+ getMetadata(): AdapterMetadata;
169
+ supportsBulkOperations(): boolean;
170
+ getApiMode(): ApiMode;
171
+ getTerminology(): AdapterMetadata['terminology'];
172
+ getRawClient(): any;
173
+ }
174
+ /**
175
+ * Base adapter class with common functionality
176
+ */
177
+ export declare abstract class BaseAdapter implements DatabaseAdapter {
178
+ protected client: any;
179
+ protected apiMode: ApiMode;
180
+ constructor(client: any, apiMode: ApiMode);
181
+ abstract listRows(params: ListRowsParams): Promise<ApiResponse>;
182
+ abstract createRow(params: CreateRowParams): Promise<ApiResponse>;
183
+ abstract updateRow(params: UpdateRowParams): Promise<ApiResponse>;
184
+ abstract deleteRow(params: DeleteRowParams): Promise<ApiResponse>;
185
+ abstract getRow(params: {
186
+ databaseId: string;
187
+ tableId: string;
188
+ id: string;
189
+ }): Promise<ApiResponse>;
190
+ abstract listTables(params: ListTablesParams): Promise<ApiResponse>;
191
+ abstract createTable(params: CreateTableParams): Promise<ApiResponse>;
192
+ abstract updateTable(params: UpdateTableParams): Promise<ApiResponse>;
193
+ abstract deleteTable(params: DeleteTableParams): Promise<ApiResponse>;
194
+ abstract getTable(params: GetTableParams): Promise<ApiResponse>;
195
+ abstract listIndexes(params: ListIndexesParams): Promise<ApiResponse>;
196
+ abstract createIndex(params: CreateIndexParams): Promise<ApiResponse>;
197
+ abstract deleteIndex(params: DeleteIndexParams): Promise<ApiResponse>;
198
+ abstract createAttribute(params: CreateAttributeParams): Promise<ApiResponse>;
199
+ abstract updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse>;
200
+ abstract deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse>;
201
+ abstract getMetadata(): AdapterMetadata;
202
+ getApiMode(): ApiMode;
203
+ getRawClient(): any;
204
+ supportsBulkOperations(): boolean;
205
+ getTerminology(): AdapterMetadata['terminology'];
206
+ }
207
+ /**
208
+ * Error types for adapter operations
209
+ */
210
+ export declare class AdapterError extends Error {
211
+ readonly code: string;
212
+ readonly originalError?: Error | undefined;
213
+ constructor(message: string, code: string, originalError?: Error | undefined);
214
+ }
215
+ export declare class UnsupportedOperationError extends AdapterError {
216
+ constructor(operation: string, apiMode: ApiMode);
217
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * DatabaseAdapter Interface - Unified API for Appwrite Database Operations
3
+ *
4
+ * This interface provides a unified way to interact with both legacy Appwrite
5
+ * (collections/documents) and new TablesDB (tables/rows) APIs. All internal
6
+ * code uses TablesDB-style method signatures for consistency.
7
+ */
8
+ /**
9
+ * Base adapter class with common functionality
10
+ */
11
+ export class BaseAdapter {
12
+ client;
13
+ apiMode;
14
+ constructor(client, apiMode) {
15
+ this.client = client;
16
+ this.apiMode = apiMode;
17
+ }
18
+ // Common implementations
19
+ getApiMode() {
20
+ return this.apiMode;
21
+ }
22
+ getRawClient() {
23
+ return this.client;
24
+ }
25
+ supportsBulkOperations() {
26
+ return this.getMetadata().capabilities.bulkOperations;
27
+ }
28
+ getTerminology() {
29
+ return this.getMetadata().terminology;
30
+ }
31
+ }
32
+ /**
33
+ * Error types for adapter operations
34
+ */
35
+ export class AdapterError extends Error {
36
+ code;
37
+ originalError;
38
+ constructor(message, code, originalError) {
39
+ super(message);
40
+ this.code = code;
41
+ this.originalError = originalError;
42
+ this.name = 'AdapterError';
43
+ }
44
+ }
45
+ export class UnsupportedOperationError extends AdapterError {
46
+ constructor(operation, apiMode) {
47
+ super(`Operation '${operation}' is not supported in ${apiMode} mode`, 'UNSUPPORTED_OPERATION');
48
+ this.name = 'UnsupportedOperationError';
49
+ }
50
+ }
@@ -0,0 +1,49 @@
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
+ import { BaseAdapter, type CreateRowParams, type UpdateRowParams, type ListRowsParams, type DeleteRowParams, type CreateTableParams, type UpdateTableParams, type ListTablesParams, type DeleteTableParams, type GetTableParams, type BulkCreateRowsParams, type BulkUpsertRowsParams, type BulkDeleteRowsParams, type CreateIndexParams, type ListIndexesParams, type DeleteIndexParams, type CreateAttributeParams, type UpdateAttributeParams, type DeleteAttributeParams, type ApiResponse, type AdapterMetadata } from './DatabaseAdapter.js';
10
+ /**
11
+ * LegacyAdapter - Translates TablesDB calls to legacy Databases API
12
+ */
13
+ export declare class LegacyAdapter extends BaseAdapter {
14
+ private databases;
15
+ constructor(client: any);
16
+ listRows(params: ListRowsParams): Promise<ApiResponse>;
17
+ createRow(params: CreateRowParams): Promise<ApiResponse>;
18
+ updateRow(params: UpdateRowParams): Promise<ApiResponse>;
19
+ deleteRow(params: DeleteRowParams): Promise<ApiResponse>;
20
+ getRow(params: {
21
+ databaseId: string;
22
+ tableId: string;
23
+ id: string;
24
+ }): Promise<ApiResponse>;
25
+ listTables(params: ListTablesParams): Promise<ApiResponse>;
26
+ createTable(params: CreateTableParams): Promise<ApiResponse>;
27
+ updateTable(params: UpdateTableParams): Promise<ApiResponse>;
28
+ deleteTable(params: DeleteTableParams): Promise<ApiResponse>;
29
+ getTable(params: GetTableParams): Promise<ApiResponse>;
30
+ listIndexes(params: ListIndexesParams): Promise<ApiResponse>;
31
+ createIndex(params: CreateIndexParams): Promise<ApiResponse>;
32
+ deleteIndex(params: DeleteIndexParams): Promise<ApiResponse>;
33
+ createAttribute(params: CreateAttributeParams): Promise<ApiResponse>;
34
+ updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse>;
35
+ deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse>;
36
+ bulkCreateRows(params: BulkCreateRowsParams): Promise<ApiResponse>;
37
+ bulkUpsertRows(params: BulkUpsertRowsParams): Promise<ApiResponse>;
38
+ bulkDeleteRows(params: BulkDeleteRowsParams): Promise<ApiResponse>;
39
+ getMetadata(): AdapterMetadata;
40
+ supportsBulkOperations(): boolean;
41
+ /**
42
+ * Check if endpoint supports bulk operations via HTTP (for cloud instances)
43
+ */
44
+ private supportsHttpBulkOperations;
45
+ /**
46
+ * Normalize response format to be consistent with TablesDB
47
+ */
48
+ private normalizeResponse;
49
+ }