appwrite-utils-cli 1.7.9 → 1.8.2
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.
- package/CHANGELOG.md +14 -199
- package/README.md +87 -30
- package/dist/adapters/AdapterFactory.js +5 -25
- package/dist/adapters/DatabaseAdapter.d.ts +17 -2
- package/dist/adapters/LegacyAdapter.d.ts +2 -1
- package/dist/adapters/LegacyAdapter.js +212 -16
- package/dist/adapters/TablesDBAdapter.d.ts +2 -12
- package/dist/adapters/TablesDBAdapter.js +261 -57
- package/dist/cli/commands/databaseCommands.js +4 -3
- package/dist/cli/commands/functionCommands.js +17 -8
- package/dist/collections/attributes.js +447 -125
- package/dist/collections/methods.js +197 -186
- package/dist/collections/tableOperations.d.ts +86 -0
- package/dist/collections/tableOperations.js +434 -0
- package/dist/collections/transferOperations.d.ts +3 -2
- package/dist/collections/transferOperations.js +93 -12
- package/dist/config/yamlConfig.d.ts +221 -88
- package/dist/examples/yamlTerminologyExample.d.ts +1 -1
- package/dist/examples/yamlTerminologyExample.js +6 -3
- package/dist/functions/fnConfigDiscovery.d.ts +3 -0
- package/dist/functions/fnConfigDiscovery.js +108 -0
- package/dist/interactiveCLI.js +18 -15
- package/dist/main.js +211 -73
- package/dist/migrations/appwriteToX.d.ts +88 -23
- package/dist/migrations/comprehensiveTransfer.d.ts +2 -0
- package/dist/migrations/comprehensiveTransfer.js +83 -6
- package/dist/migrations/dataLoader.d.ts +227 -69
- package/dist/migrations/dataLoader.js +3 -3
- package/dist/migrations/importController.js +3 -3
- package/dist/migrations/relationships.d.ts +8 -2
- package/dist/migrations/services/ImportOrchestrator.js +3 -3
- package/dist/migrations/transfer.js +159 -37
- package/dist/shared/attributeMapper.d.ts +20 -0
- package/dist/shared/attributeMapper.js +203 -0
- package/dist/shared/selectionDialogs.js +8 -4
- package/dist/storage/schemas.d.ts +354 -92
- package/dist/utils/configDiscovery.js +4 -3
- package/dist/utils/versionDetection.d.ts +0 -4
- package/dist/utils/versionDetection.js +41 -173
- package/dist/utils/yamlConverter.js +89 -16
- package/dist/utils/yamlLoader.d.ts +1 -1
- package/dist/utils/yamlLoader.js +6 -2
- package/dist/utilsController.js +56 -19
- package/package.json +4 -4
- package/src/adapters/AdapterFactory.ts +119 -143
- package/src/adapters/DatabaseAdapter.ts +18 -3
- package/src/adapters/LegacyAdapter.ts +236 -105
- package/src/adapters/TablesDBAdapter.ts +773 -643
- package/src/cli/commands/databaseCommands.ts +13 -12
- package/src/cli/commands/functionCommands.ts +23 -14
- package/src/collections/attributes.ts +2054 -1611
- package/src/collections/methods.ts +208 -293
- package/src/collections/tableOperations.ts +506 -0
- package/src/collections/transferOperations.ts +218 -144
- package/src/examples/yamlTerminologyExample.ts +10 -5
- package/src/functions/fnConfigDiscovery.ts +103 -0
- package/src/interactiveCLI.ts +25 -20
- package/src/main.ts +549 -194
- package/src/migrations/comprehensiveTransfer.ts +126 -50
- package/src/migrations/dataLoader.ts +3 -3
- package/src/migrations/importController.ts +3 -3
- package/src/migrations/services/ImportOrchestrator.ts +3 -3
- package/src/migrations/transfer.ts +148 -131
- package/src/shared/attributeMapper.ts +229 -0
- package/src/shared/selectionDialogs.ts +29 -25
- package/src/utils/configDiscovery.ts +9 -3
- package/src/utils/versionDetection.ts +74 -228
- package/src/utils/yamlConverter.ts +94 -17
- package/src/utils/yamlLoader.ts +11 -4
- package/src/utilsController.ts +80 -30
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { AppwriteConfig } from "appwrite-utils";
|
|
10
|
-
import { detectAppwriteVersionCached, isVersionAtLeast, 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
|
-
import { logger } from '../shared/logging.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
10
|
+
import { detectAppwriteVersionCached, isVersionAtLeast, 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
|
+
import { logger } from '../shared/logging.js';
|
|
15
|
+
import { isValidSessionCookie } from '../utils/sessionAuth.js';
|
|
16
|
+
import { MessageFormatter } from '../shared/messageFormatter.js';
|
|
17
|
+
import { Client } from 'node-appwrite';
|
|
18
18
|
|
|
19
19
|
export interface AdapterFactoryConfig {
|
|
20
20
|
appwriteEndpoint: string;
|
|
@@ -201,73 +201,61 @@ export class AdapterFactory {
|
|
|
201
201
|
/**
|
|
202
202
|
* Create TablesDB adapter with dynamic import
|
|
203
203
|
*/
|
|
204
|
-
private static async createTablesDBAdapter(
|
|
205
|
-
config: AdapterFactoryConfig
|
|
206
|
-
): Promise<{ adapter: DatabaseAdapter; client: any }> {
|
|
207
|
-
const startTime = Date.now();
|
|
208
|
-
|
|
209
|
-
try {
|
|
210
|
-
logger.info('
|
|
211
|
-
endpoint: config.appwriteEndpoint,
|
|
212
|
-
operation: 'createTablesDBAdapter'
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
logger.info('TablesDB adapter created successfully', {
|
|
260
|
-
totalDuration,
|
|
261
|
-
importDuration,
|
|
262
|
-
endpoint: config.appwriteEndpoint,
|
|
263
|
-
operation: 'createTablesDBAdapter'
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
return { adapter, client };
|
|
267
|
-
|
|
268
|
-
} catch (error) {
|
|
269
|
-
const errorDuration = Date.now() - startTime;
|
|
270
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
204
|
+
private static async createTablesDBAdapter(
|
|
205
|
+
config: AdapterFactoryConfig
|
|
206
|
+
): Promise<{ adapter: DatabaseAdapter; client: any }> {
|
|
207
|
+
const startTime = Date.now();
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
logger.info('Creating TablesDB adapter (static SDK imports)', {
|
|
211
|
+
endpoint: config.appwriteEndpoint,
|
|
212
|
+
operation: 'createTablesDBAdapter'
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Use pre-configured client or create session-aware client with TablesDB Client
|
|
216
|
+
let client: any;
|
|
217
|
+
if (config.preConfiguredClient) {
|
|
218
|
+
client = config.preConfiguredClient;
|
|
219
|
+
} else {
|
|
220
|
+
client = new Client()
|
|
221
|
+
.setEndpoint(config.appwriteEndpoint)
|
|
222
|
+
.setProject(config.appwriteProject);
|
|
223
|
+
|
|
224
|
+
// Set authentication method with mode headers
|
|
225
|
+
// Prefer session with admin mode, fallback to API key with default mode
|
|
226
|
+
if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
|
|
227
|
+
client.setSession(config.sessionCookie);
|
|
228
|
+
client.headers['X-Appwrite-Mode'] = 'admin';
|
|
229
|
+
logger.debug('Using session authentication for TablesDB adapter', {
|
|
230
|
+
project: config.appwriteProject,
|
|
231
|
+
operation: 'createTablesDBAdapter'
|
|
232
|
+
});
|
|
233
|
+
} else if (config.appwriteKey) {
|
|
234
|
+
client.setKey(config.appwriteKey);
|
|
235
|
+
client.headers['X-Appwrite-Mode'] = 'default';
|
|
236
|
+
logger.debug('Using API key authentication for TablesDB adapter', {
|
|
237
|
+
project: config.appwriteProject,
|
|
238
|
+
operation: 'createTablesDBAdapter'
|
|
239
|
+
});
|
|
240
|
+
} else {
|
|
241
|
+
throw new Error("No authentication available for adapter");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const adapter = new TablesDBAdapter(client);
|
|
246
|
+
|
|
247
|
+
const totalDuration = Date.now() - startTime;
|
|
248
|
+
logger.info('TablesDB adapter created successfully', {
|
|
249
|
+
totalDuration,
|
|
250
|
+
endpoint: config.appwriteEndpoint,
|
|
251
|
+
operation: 'createTablesDBAdapter'
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
return { adapter, client };
|
|
255
|
+
|
|
256
|
+
} catch (error) {
|
|
257
|
+
const errorDuration = Date.now() - startTime;
|
|
258
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
271
259
|
|
|
272
260
|
MessageFormatter.warning('Failed to create TablesDB adapter - falling back to legacy', { prefix: "Adapter" });
|
|
273
261
|
|
|
@@ -286,73 +274,61 @@ export class AdapterFactory {
|
|
|
286
274
|
/**
|
|
287
275
|
* Create Legacy adapter with dynamic import
|
|
288
276
|
*/
|
|
289
|
-
private static async createLegacyAdapter(
|
|
290
|
-
config: AdapterFactoryConfig
|
|
291
|
-
): Promise<{ adapter: DatabaseAdapter; client: any }> {
|
|
292
|
-
const startTime = Date.now();
|
|
293
|
-
|
|
294
|
-
try {
|
|
295
|
-
logger.info('
|
|
296
|
-
endpoint: config.appwriteEndpoint,
|
|
297
|
-
operation: 'createLegacyAdapter'
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const
|
|
344
|
-
logger.info('Legacy adapter created successfully', {
|
|
345
|
-
totalDuration,
|
|
346
|
-
importDuration,
|
|
347
|
-
endpoint: config.appwriteEndpoint,
|
|
348
|
-
operation: 'createLegacyAdapter'
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
return { adapter, client };
|
|
352
|
-
|
|
353
|
-
} catch (error) {
|
|
354
|
-
const errorDuration = Date.now() - startTime;
|
|
355
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
277
|
+
private static async createLegacyAdapter(
|
|
278
|
+
config: AdapterFactoryConfig
|
|
279
|
+
): Promise<{ adapter: DatabaseAdapter; client: any }> {
|
|
280
|
+
const startTime = Date.now();
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
logger.info('Creating legacy adapter (static SDK imports)', {
|
|
284
|
+
endpoint: config.appwriteEndpoint,
|
|
285
|
+
operation: 'createLegacyAdapter'
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// Use pre-configured client or create session-aware client with Legacy Client
|
|
289
|
+
let client: any;
|
|
290
|
+
if (config.preConfiguredClient) {
|
|
291
|
+
client = config.preConfiguredClient;
|
|
292
|
+
} else {
|
|
293
|
+
client = new Client()
|
|
294
|
+
.setEndpoint(config.appwriteEndpoint)
|
|
295
|
+
.setProject(config.appwriteProject);
|
|
296
|
+
|
|
297
|
+
// Set authentication method with mode headers
|
|
298
|
+
// Prefer session with admin mode, fallback to API key with default mode
|
|
299
|
+
if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
|
|
300
|
+
(client as any).setSession(config.sessionCookie);
|
|
301
|
+
client.headers['X-Appwrite-Mode'] = 'admin';
|
|
302
|
+
logger.debug('Using session authentication for Legacy adapter', {
|
|
303
|
+
project: config.appwriteProject,
|
|
304
|
+
operation: 'createLegacyAdapter'
|
|
305
|
+
});
|
|
306
|
+
} else if (config.appwriteKey) {
|
|
307
|
+
client.setKey(config.appwriteKey);
|
|
308
|
+
client.headers['X-Appwrite-Mode'] = 'default';
|
|
309
|
+
logger.debug('Using API key authentication for Legacy adapter', {
|
|
310
|
+
project: config.appwriteProject,
|
|
311
|
+
operation: 'createLegacyAdapter'
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
throw new Error("No authentication available for adapter");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const adapter = new LegacyAdapter(client);
|
|
319
|
+
|
|
320
|
+
const totalDuration = Date.now() - startTime;
|
|
321
|
+
logger.info('Legacy adapter created successfully', {
|
|
322
|
+
totalDuration,
|
|
323
|
+
endpoint: config.appwriteEndpoint,
|
|
324
|
+
operation: 'createLegacyAdapter'
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
return { adapter, client };
|
|
328
|
+
|
|
329
|
+
} catch (error) {
|
|
330
|
+
const errorDuration = Date.now() - startTime;
|
|
331
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
356
332
|
|
|
357
333
|
logger.error('Failed to load legacy Appwrite SDK', {
|
|
358
334
|
error: errorMessage,
|
|
@@ -531,4 +507,4 @@ export async function getApiCapabilities(
|
|
|
531
507
|
terminology: metadata.terminology,
|
|
532
508
|
capabilities
|
|
533
509
|
};
|
|
534
|
-
}
|
|
510
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* code uses TablesDB-style method signatures for consistency.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import type { Client } from "node-appwrite";
|
|
9
10
|
import type { ApiMode } from "../utils/versionDetection.js";
|
|
10
11
|
|
|
11
12
|
// Base parameter types using TablesDB terminology
|
|
@@ -43,6 +44,7 @@ export interface CreateTableParams {
|
|
|
43
44
|
name: string;
|
|
44
45
|
permissions?: string[];
|
|
45
46
|
documentSecurity?: boolean;
|
|
47
|
+
rowSecurity?: boolean;
|
|
46
48
|
enabled?: boolean;
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -52,6 +54,7 @@ export interface UpdateTableParams {
|
|
|
52
54
|
name: string;
|
|
53
55
|
permissions?: string[];
|
|
54
56
|
documentSecurity?: boolean;
|
|
57
|
+
rowSecurity?: boolean;
|
|
55
58
|
enabled?: boolean;
|
|
56
59
|
}
|
|
57
60
|
|
|
@@ -131,8 +134,20 @@ export interface UpdateAttributeParams {
|
|
|
131
134
|
databaseId: string;
|
|
132
135
|
tableId: string;
|
|
133
136
|
key: string;
|
|
137
|
+
type?: string;
|
|
134
138
|
required?: boolean;
|
|
135
139
|
default?: any;
|
|
140
|
+
size?: number;
|
|
141
|
+
min?: number;
|
|
142
|
+
max?: number;
|
|
143
|
+
array?: boolean;
|
|
144
|
+
encrypt?: boolean;
|
|
145
|
+
elements?: string[];
|
|
146
|
+
relatedCollection?: string;
|
|
147
|
+
relationType?: string;
|
|
148
|
+
twoWay?: boolean;
|
|
149
|
+
twoWayKey?: string;
|
|
150
|
+
onDelete?: string;
|
|
136
151
|
}
|
|
137
152
|
|
|
138
153
|
export interface DeleteAttributeParams {
|
|
@@ -217,10 +232,10 @@ export interface DatabaseAdapter {
|
|
|
217
232
|
* Base adapter class with common functionality
|
|
218
233
|
*/
|
|
219
234
|
export abstract class BaseAdapter implements DatabaseAdapter {
|
|
220
|
-
protected client:
|
|
235
|
+
protected client: Client;
|
|
221
236
|
protected apiMode: ApiMode;
|
|
222
237
|
|
|
223
|
-
constructor(client:
|
|
238
|
+
constructor(client: Client, apiMode: ApiMode) {
|
|
224
239
|
this.client = client;
|
|
225
240
|
this.apiMode = apiMode;
|
|
226
241
|
}
|
|
@@ -288,4 +303,4 @@ export class UnsupportedOperationError extends AdapterError {
|
|
|
288
303
|
);
|
|
289
304
|
this.name = 'UnsupportedOperationError';
|
|
290
305
|
}
|
|
291
|
-
}
|
|
306
|
+
}
|