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,296 @@
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
+
9
+ import type { AppwriteConfig } from "appwrite-utils";
10
+ import { detectAppwriteVersionCached, type ApiMode, type VersionDetectionResult } from "../utils/versionDetection.js";
11
+ import type { DatabaseAdapter } from './DatabaseAdapter.js';
12
+ import { TablesDBAdapter } from './TablesDBAdapter.js';
13
+ import { LegacyAdapter } from './LegacyAdapter.js';
14
+
15
+ export interface AdapterFactoryConfig {
16
+ appwriteEndpoint: string;
17
+ appwriteProject: string;
18
+ appwriteKey: string;
19
+ apiMode?: 'auto' | 'legacy' | 'tablesdb';
20
+ forceRefresh?: boolean; // Skip detection cache
21
+ }
22
+
23
+ export interface AdapterFactoryResult {
24
+ adapter: DatabaseAdapter;
25
+ apiMode: ApiMode;
26
+ detectionResult?: VersionDetectionResult;
27
+ client: any;
28
+ }
29
+
30
+ /**
31
+ * AdapterFactory - Main factory class for creating database adapters
32
+ */
33
+ export class AdapterFactory {
34
+ private static cache = new Map<string, { adapter: DatabaseAdapter; timestamp: number }>();
35
+ private static readonly CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
36
+
37
+ /**
38
+ * Create a database adapter based on configuration and detection
39
+ */
40
+ static async create(config: AdapterFactoryConfig): Promise<AdapterFactoryResult> {
41
+ const cacheKey = `${config.appwriteEndpoint}:${config.appwriteProject}:${config.apiMode || 'auto'}`;
42
+
43
+ // Check cache first (unless force refresh)
44
+ if (!config.forceRefresh) {
45
+ const cached = this.getCachedAdapter(cacheKey);
46
+ if (cached) {
47
+ return {
48
+ adapter: cached.adapter,
49
+ apiMode: cached.adapter.getApiMode(),
50
+ client: cached.adapter.getRawClient()
51
+ };
52
+ }
53
+ }
54
+
55
+ // Determine API mode
56
+ let apiMode: ApiMode;
57
+ let detectionResult: VersionDetectionResult | undefined;
58
+
59
+ if (config.apiMode && config.apiMode !== 'auto') {
60
+ // Use explicitly configured mode
61
+ apiMode = config.apiMode;
62
+ } else {
63
+ // Auto-detect API mode
64
+ detectionResult = await detectAppwriteVersionCached(
65
+ config.appwriteEndpoint,
66
+ config.appwriteProject,
67
+ config.appwriteKey,
68
+ config.forceRefresh
69
+ );
70
+ apiMode = detectionResult.apiMode;
71
+ }
72
+
73
+ // Create appropriate adapter
74
+ const result = await this.createAdapter(config, apiMode);
75
+
76
+ // Cache the result
77
+ this.setCachedAdapter(cacheKey, result.adapter);
78
+
79
+ return {
80
+ ...result,
81
+ apiMode,
82
+ detectionResult
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Create adapter from AppwriteConfig (convenience method)
88
+ */
89
+ static async createFromConfig(config: AppwriteConfig, forceRefresh?: boolean): Promise<AdapterFactoryResult> {
90
+ return this.create({
91
+ appwriteEndpoint: config.appwriteEndpoint,
92
+ appwriteProject: config.appwriteProject,
93
+ appwriteKey: config.appwriteKey,
94
+ apiMode: (config as any).apiMode || 'auto', // Cast to access new property
95
+ forceRefresh
96
+ });
97
+ }
98
+
99
+ /**
100
+ * Create specific adapter type (internal method)
101
+ */
102
+ private static async createAdapter(
103
+ config: AdapterFactoryConfig,
104
+ apiMode: ApiMode
105
+ ): Promise<{ adapter: DatabaseAdapter; client: any }> {
106
+ if (apiMode === 'tablesdb') {
107
+ return this.createTablesDBAdapter(config);
108
+ } else {
109
+ return this.createLegacyAdapter(config);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Create TablesDB adapter with dynamic import
115
+ */
116
+ private static async createTablesDBAdapter(
117
+ config: AdapterFactoryConfig
118
+ ): Promise<{ adapter: DatabaseAdapter; client: any }> {
119
+ try {
120
+ // Dynamic import of TablesDB SDK
121
+ const { Client, TablesDB } = await import('node-appwrite-tablesdb');
122
+
123
+ const client = new Client()
124
+ .setEndpoint(config.appwriteEndpoint)
125
+ .setProject(config.appwriteProject)
126
+ .setKey(config.appwriteKey);
127
+
128
+ const tablesDB = new TablesDB(client);
129
+ const adapter = new TablesDBAdapter(tablesDB);
130
+
131
+ return { adapter, client };
132
+
133
+ } catch (error) {
134
+ console.warn('Failed to load TablesDB SDK, falling back to legacy:', error);
135
+
136
+ // Fallback to legacy adapter if TablesDB SDK is not available
137
+ return this.createLegacyAdapter(config);
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Create Legacy adapter with dynamic import
143
+ */
144
+ private static async createLegacyAdapter(
145
+ config: AdapterFactoryConfig
146
+ ): Promise<{ adapter: DatabaseAdapter; client: any }> {
147
+ try {
148
+ // Dynamic import of legacy SDK
149
+ const { Client, Databases } = await import('node-appwrite');
150
+
151
+ const client = new Client()
152
+ .setEndpoint(config.appwriteEndpoint)
153
+ .setProject(config.appwriteProject)
154
+ .setKey(config.appwriteKey);
155
+
156
+ const databases = new Databases(client);
157
+ const adapter = new LegacyAdapter(databases);
158
+
159
+ return { adapter, client };
160
+
161
+ } catch (error) {
162
+ throw new Error(`Failed to load legacy Appwrite SDK: ${error instanceof Error ? error.message : 'Unknown error'}`);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Get cached adapter if available and not expired
168
+ */
169
+ private static getCachedAdapter(cacheKey: string): { adapter: DatabaseAdapter; timestamp: number } | null {
170
+ const cached = this.cache.get(cacheKey);
171
+
172
+ if (!cached) {
173
+ return null;
174
+ }
175
+
176
+ // Check if cache is expired
177
+ if (Date.now() - cached.timestamp > this.CACHE_DURATION) {
178
+ this.cache.delete(cacheKey);
179
+ return null;
180
+ }
181
+
182
+ return cached;
183
+ }
184
+
185
+ /**
186
+ * Cache adapter instance
187
+ */
188
+ private static setCachedAdapter(cacheKey: string, adapter: DatabaseAdapter): void {
189
+ this.cache.set(cacheKey, {
190
+ adapter,
191
+ timestamp: Date.now()
192
+ });
193
+ }
194
+
195
+ /**
196
+ * Clear adapter cache (useful for testing)
197
+ */
198
+ static clearCache(): void {
199
+ this.cache.clear();
200
+ }
201
+
202
+ /**
203
+ * Test connection and API capabilities
204
+ */
205
+ static async testConnection(config: AdapterFactoryConfig): Promise<{
206
+ success: boolean;
207
+ apiMode: ApiMode;
208
+ capabilities: string[];
209
+ error?: string;
210
+ }> {
211
+ try {
212
+ const result = await this.create({ ...config, forceRefresh: true });
213
+ const metadata = result.adapter.getMetadata();
214
+
215
+ // Test basic operations
216
+ const capabilities = [];
217
+
218
+ if (metadata.capabilities.bulkOperations) {
219
+ capabilities.push('Bulk Operations');
220
+ }
221
+
222
+ if (metadata.capabilities.advancedQueries) {
223
+ capabilities.push('Advanced Queries');
224
+ }
225
+
226
+ if (metadata.capabilities.realtime) {
227
+ capabilities.push('Realtime');
228
+ }
229
+
230
+ if (metadata.capabilities.transactions) {
231
+ capabilities.push('Transactions');
232
+ }
233
+
234
+ return {
235
+ success: true,
236
+ apiMode: result.apiMode,
237
+ capabilities
238
+ };
239
+
240
+ } catch (error) {
241
+ return {
242
+ success: false,
243
+ apiMode: 'legacy', // Default fallback
244
+ capabilities: [],
245
+ error: error instanceof Error ? error.message : 'Unknown error'
246
+ };
247
+ }
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Convenience function for quick adapter creation
253
+ */
254
+ export async function createDatabaseAdapter(
255
+ endpoint: string,
256
+ project: string,
257
+ apiKey: string,
258
+ mode: 'auto' | 'legacy' | 'tablesdb' = 'auto'
259
+ ): Promise<DatabaseAdapter> {
260
+ const result = await AdapterFactory.create({
261
+ appwriteEndpoint: endpoint,
262
+ appwriteProject: project,
263
+ appwriteKey: apiKey,
264
+ apiMode: mode
265
+ });
266
+
267
+ return result.adapter;
268
+ }
269
+
270
+ /**
271
+ * Helper function to get adapter metadata without creating full adapter
272
+ */
273
+ export async function getApiCapabilities(
274
+ endpoint: string,
275
+ project: string,
276
+ apiKey: string
277
+ ): Promise<{
278
+ apiMode: ApiMode;
279
+ terminology: { container: string; item: string; service: string };
280
+ capabilities: string[];
281
+ }> {
282
+ const adapter = await createDatabaseAdapter(endpoint, project, apiKey, 'auto');
283
+ const metadata = adapter.getMetadata();
284
+
285
+ const capabilities = [];
286
+ if (metadata.capabilities.bulkOperations) capabilities.push('Bulk Operations');
287
+ if (metadata.capabilities.advancedQueries) capabilities.push('Advanced Queries');
288
+ if (metadata.capabilities.realtime) capabilities.push('Realtime');
289
+ if (metadata.capabilities.transactions) capabilities.push('Transactions');
290
+
291
+ return {
292
+ apiMode: metadata.apiMode,
293
+ terminology: metadata.terminology,
294
+ capabilities
295
+ };
296
+ }
@@ -0,0 +1,290 @@
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
+ import type { ApiMode } from "../utils/versionDetection.js";
10
+
11
+ // Base parameter types using TablesDB terminology
12
+ export interface CreateRowParams {
13
+ databaseId: string;
14
+ tableId: string;
15
+ id: string;
16
+ data: any;
17
+ permissions?: string[];
18
+ }
19
+
20
+ export interface UpdateRowParams {
21
+ databaseId: string;
22
+ tableId: string;
23
+ id: string;
24
+ data?: any;
25
+ permissions?: string[];
26
+ }
27
+
28
+ export interface ListRowsParams {
29
+ databaseId: string;
30
+ tableId: string;
31
+ queries?: any[];
32
+ }
33
+
34
+ export interface DeleteRowParams {
35
+ databaseId: string;
36
+ tableId: string;
37
+ id: string;
38
+ }
39
+
40
+ export interface CreateTableParams {
41
+ databaseId: string;
42
+ id: string;
43
+ name: string;
44
+ permissions?: string[];
45
+ documentSecurity?: boolean;
46
+ enabled?: boolean;
47
+ }
48
+
49
+ export interface UpdateTableParams {
50
+ databaseId: string;
51
+ id: string;
52
+ name: string;
53
+ permissions?: string[];
54
+ documentSecurity?: boolean;
55
+ enabled?: boolean;
56
+ }
57
+
58
+ export interface ListTablesParams {
59
+ databaseId: string;
60
+ queries?: any[];
61
+ }
62
+
63
+ export interface DeleteTableParams {
64
+ databaseId: string;
65
+ tableId: string;
66
+ }
67
+
68
+ export interface GetTableParams {
69
+ databaseId: string;
70
+ tableId: string;
71
+ }
72
+
73
+ // Bulk operation parameters
74
+ export interface BulkCreateRowsParams {
75
+ databaseId: string;
76
+ tableId: string;
77
+ rows: any[];
78
+ }
79
+
80
+ export interface BulkUpsertRowsParams {
81
+ databaseId: string;
82
+ tableId: string;
83
+ rows: any[];
84
+ }
85
+
86
+ export interface BulkDeleteRowsParams {
87
+ databaseId: string;
88
+ tableId: string;
89
+ rowIds: string[];
90
+ }
91
+
92
+ // Index operation parameters
93
+ export interface CreateIndexParams {
94
+ databaseId: string;
95
+ tableId: string;
96
+ key: string;
97
+ type: string;
98
+ attributes: string[];
99
+ orders?: string[];
100
+ }
101
+
102
+ export interface ListIndexesParams {
103
+ databaseId: string;
104
+ tableId: string;
105
+ queries?: any[];
106
+ }
107
+
108
+ export interface DeleteIndexParams {
109
+ databaseId: string;
110
+ tableId: string;
111
+ key: string;
112
+ }
113
+
114
+ // Attribute operation parameters
115
+ export interface CreateAttributeParams {
116
+ databaseId: string;
117
+ tableId: string;
118
+ key: string;
119
+ type: string;
120
+ size?: number;
121
+ required?: boolean;
122
+ default?: any;
123
+ array?: boolean;
124
+ encrypt?: boolean;
125
+ // Additional type-specific parameters
126
+ [key: string]: any;
127
+ }
128
+
129
+ export interface UpdateAttributeParams {
130
+ databaseId: string;
131
+ tableId: string;
132
+ key: string;
133
+ required?: boolean;
134
+ default?: any;
135
+ }
136
+
137
+ export interface DeleteAttributeParams {
138
+ databaseId: string;
139
+ tableId: string;
140
+ key: string;
141
+ }
142
+
143
+ // Response types with conditional typing
144
+ export interface ApiResponse<T = any> {
145
+ data?: T;
146
+ total?: number;
147
+ documents?: T[]; // Legacy compatibility
148
+ rows?: T[]; // TablesDB format
149
+ collections?: T[]; // Legacy format
150
+ tables?: T[]; // TablesDB format
151
+ errors?: any[]; // For bulk operation errors
152
+ }
153
+
154
+ // Metadata about the adapter
155
+ export interface AdapterMetadata {
156
+ apiMode: ApiMode;
157
+ terminology: {
158
+ container: 'collection' | 'table';
159
+ item: 'document' | 'row';
160
+ service: 'Databases' | 'TablesDB';
161
+ };
162
+ capabilities: {
163
+ bulkOperations: boolean;
164
+ advancedQueries: boolean;
165
+ realtime: boolean;
166
+ transactions?: boolean;
167
+ };
168
+ }
169
+
170
+ /**
171
+ * Main DatabaseAdapter interface - all implementations must support these methods
172
+ */
173
+ export interface DatabaseAdapter {
174
+ // Row (Document) operations - TablesDB-style signatures
175
+ listRows(params: ListRowsParams): Promise<ApiResponse>;
176
+ createRow(params: CreateRowParams): Promise<ApiResponse>;
177
+ updateRow(params: UpdateRowParams): Promise<ApiResponse>;
178
+ deleteRow(params: DeleteRowParams): Promise<ApiResponse>;
179
+ getRow(params: { databaseId: string; tableId: string; id: string }): Promise<ApiResponse>;
180
+
181
+ // Table (Collection) operations - TablesDB-style signatures
182
+ listTables(params: ListTablesParams): Promise<ApiResponse>;
183
+ createTable(params: CreateTableParams): Promise<ApiResponse>;
184
+ updateTable(params: UpdateTableParams): Promise<ApiResponse>;
185
+ deleteTable(params: DeleteTableParams): Promise<ApiResponse>;
186
+ getTable(params: GetTableParams): Promise<ApiResponse>;
187
+
188
+ // Index operations
189
+ listIndexes(params: ListIndexesParams): Promise<ApiResponse>;
190
+ createIndex(params: CreateIndexParams): Promise<ApiResponse>;
191
+ deleteIndex(params: DeleteIndexParams): Promise<ApiResponse>;
192
+
193
+ // Attribute operations
194
+ createAttribute(params: CreateAttributeParams): Promise<ApiResponse>;
195
+ updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse>;
196
+ deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse>;
197
+
198
+ // Bulk operations (when supported)
199
+ bulkCreateRows?(params: BulkCreateRowsParams): Promise<ApiResponse>;
200
+ bulkUpsertRows?(params: BulkUpsertRowsParams): Promise<ApiResponse>;
201
+ bulkDeleteRows?(params: BulkDeleteRowsParams): Promise<ApiResponse>;
202
+
203
+ // Adapter metadata
204
+ getMetadata(): AdapterMetadata;
205
+
206
+ // Utility methods
207
+ supportsBulkOperations(): boolean;
208
+ getApiMode(): ApiMode;
209
+ getTerminology(): AdapterMetadata['terminology'];
210
+
211
+ // Raw client access for advanced operations
212
+ getRawClient(): any;
213
+ }
214
+
215
+ /**
216
+ * Base adapter class with common functionality
217
+ */
218
+ export abstract class BaseAdapter implements DatabaseAdapter {
219
+ protected client: any;
220
+ protected apiMode: ApiMode;
221
+
222
+ constructor(client: any, apiMode: ApiMode) {
223
+ this.client = client;
224
+ this.apiMode = apiMode;
225
+ }
226
+
227
+ // Abstract methods that must be implemented by concrete adapters
228
+ abstract listRows(params: ListRowsParams): Promise<ApiResponse>;
229
+ abstract createRow(params: CreateRowParams): Promise<ApiResponse>;
230
+ abstract updateRow(params: UpdateRowParams): Promise<ApiResponse>;
231
+ abstract deleteRow(params: DeleteRowParams): Promise<ApiResponse>;
232
+ abstract getRow(params: { databaseId: string; tableId: string; id: string }): Promise<ApiResponse>;
233
+
234
+ abstract listTables(params: ListTablesParams): Promise<ApiResponse>;
235
+ abstract createTable(params: CreateTableParams): Promise<ApiResponse>;
236
+ abstract updateTable(params: UpdateTableParams): Promise<ApiResponse>;
237
+ abstract deleteTable(params: DeleteTableParams): Promise<ApiResponse>;
238
+ abstract getTable(params: GetTableParams): Promise<ApiResponse>;
239
+
240
+ abstract listIndexes(params: ListIndexesParams): Promise<ApiResponse>;
241
+ abstract createIndex(params: CreateIndexParams): Promise<ApiResponse>;
242
+ abstract deleteIndex(params: DeleteIndexParams): Promise<ApiResponse>;
243
+
244
+ abstract createAttribute(params: CreateAttributeParams): Promise<ApiResponse>;
245
+ abstract updateAttribute(params: UpdateAttributeParams): Promise<ApiResponse>;
246
+ abstract deleteAttribute(params: DeleteAttributeParams): Promise<ApiResponse>;
247
+
248
+ abstract getMetadata(): AdapterMetadata;
249
+
250
+ // Common implementations
251
+ getApiMode(): ApiMode {
252
+ return this.apiMode;
253
+ }
254
+
255
+ getRawClient(): any {
256
+ return this.client;
257
+ }
258
+
259
+ supportsBulkOperations(): boolean {
260
+ return this.getMetadata().capabilities.bulkOperations;
261
+ }
262
+
263
+ getTerminology(): AdapterMetadata['terminology'] {
264
+ return this.getMetadata().terminology;
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Error types for adapter operations
270
+ */
271
+ export class AdapterError extends Error {
272
+ constructor(
273
+ message: string,
274
+ public readonly code: string,
275
+ public readonly originalError?: Error
276
+ ) {
277
+ super(message);
278
+ this.name = 'AdapterError';
279
+ }
280
+ }
281
+
282
+ export class UnsupportedOperationError extends AdapterError {
283
+ constructor(operation: string, apiMode: ApiMode) {
284
+ super(
285
+ `Operation '${operation}' is not supported in ${apiMode} mode`,
286
+ 'UNSUPPORTED_OPERATION'
287
+ );
288
+ this.name = 'UnsupportedOperationError';
289
+ }
290
+ }