appwrite-utils-cli 1.8.9 → 1.9.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/dist/adapters/DatabaseAdapter.d.ts +9 -0
- package/dist/adapters/LegacyAdapter.js +1 -1
- package/dist/adapters/TablesDBAdapter.js +29 -4
- package/dist/cli/commands/databaseCommands.d.ts +1 -0
- package/dist/cli/commands/databaseCommands.js +90 -0
- package/dist/config/ConfigManager.d.ts +5 -0
- package/dist/config/ConfigManager.js +1 -1
- package/dist/config/services/ConfigDiscoveryService.d.ts +43 -47
- package/dist/config/services/ConfigDiscoveryService.js +155 -207
- package/dist/config/services/ConfigLoaderService.js +2 -7
- package/dist/config/yamlConfig.d.ts +2 -2
- package/dist/functions/methods.js +14 -2
- package/dist/main.js +9 -1
- package/dist/migrations/appwriteToX.d.ts +1 -1
- package/dist/migrations/dataLoader.d.ts +3 -3
- package/dist/shared/functionManager.js +14 -2
- package/dist/storage/schemas.d.ts +4 -4
- package/dist/utils/projectConfig.d.ts +4 -1
- package/dist/utils/projectConfig.js +41 -6
- package/dist/utilsController.d.ts +1 -0
- package/dist/utilsController.js +2 -1
- package/package.json +2 -1
- package/src/adapters/DatabaseAdapter.ts +12 -0
- package/src/adapters/LegacyAdapter.ts +28 -28
- package/src/adapters/TablesDBAdapter.ts +46 -4
- package/src/cli/commands/databaseCommands.ts +141 -11
- package/src/config/ConfigManager.ts +10 -1
- package/src/config/services/ConfigDiscoveryService.ts +180 -233
- package/src/config/services/ConfigLoaderService.ts +2 -10
- package/src/functions/methods.ts +15 -2
- package/src/main.ts +213 -204
- package/src/shared/functionManager.ts +15 -3
- package/src/utils/projectConfig.ts +57 -16
- package/src/utilsController.ts +73 -72
package/src/utilsController.ts
CHANGED
|
@@ -247,8 +247,8 @@ export class UtilsController {
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
async init(options: { validate?: boolean; strictMode?: boolean; useSession?: boolean; sessionCookie?: string } = {}) {
|
|
251
|
-
const { validate = false, strictMode = false } = options;
|
|
250
|
+
async init(options: { validate?: boolean; strictMode?: boolean; useSession?: boolean; sessionCookie?: string; preferJson?: boolean } = {}) {
|
|
251
|
+
const { validate = false, strictMode = false, preferJson = false } = options;
|
|
252
252
|
const configManager = ConfigManager.getInstance();
|
|
253
253
|
|
|
254
254
|
// Load config if not already loaded
|
|
@@ -257,6 +257,7 @@ export class UtilsController {
|
|
|
257
257
|
configDir: this.currentUserDir,
|
|
258
258
|
validate,
|
|
259
259
|
strictMode,
|
|
260
|
+
preferJson,
|
|
260
261
|
});
|
|
261
262
|
}
|
|
262
263
|
|
|
@@ -610,14 +611,14 @@ export class UtilsController {
|
|
|
610
611
|
}
|
|
611
612
|
}
|
|
612
613
|
|
|
613
|
-
async createOrUpdateCollections(
|
|
614
|
-
database: Models.Database,
|
|
615
|
-
deletedCollections?: { collectionId: string; collectionName: string }[],
|
|
616
|
-
collections: Models.Collection[] = []
|
|
617
|
-
) {
|
|
618
|
-
await this.init();
|
|
619
|
-
if (!this.database || !this.config)
|
|
620
|
-
throw new Error("Database or config not initialized");
|
|
614
|
+
async createOrUpdateCollections(
|
|
615
|
+
database: Models.Database,
|
|
616
|
+
deletedCollections?: { collectionId: string; collectionName: string }[],
|
|
617
|
+
collections: Models.Collection[] = []
|
|
618
|
+
) {
|
|
619
|
+
await this.init();
|
|
620
|
+
if (!this.database || !this.config)
|
|
621
|
+
throw new Error("Database or config not initialized");
|
|
621
622
|
|
|
622
623
|
// Ensure apiMode is properly set from adapter
|
|
623
624
|
if (this.adapter && (!this.config.apiMode || this.config.apiMode === 'auto')) {
|
|
@@ -625,38 +626,38 @@ export class UtilsController {
|
|
|
625
626
|
logger.debug(`Updated config.apiMode from adapter: ${this.config.apiMode}`, { prefix: "UtilsController" });
|
|
626
627
|
}
|
|
627
628
|
|
|
628
|
-
// Ensure we don't carry state between databases in a multi-db push
|
|
629
|
-
// This resets processed sets and name->id mapping per database
|
|
630
|
-
try {
|
|
631
|
-
const { clearProcessingState } = await import('./shared/operationQueue.js');
|
|
632
|
-
clearProcessingState();
|
|
633
|
-
} catch {}
|
|
634
|
-
|
|
635
|
-
// Always prefer adapter path for unified behavior. LegacyAdapter internally translates when needed.
|
|
636
|
-
if (this.adapter) {
|
|
637
|
-
logger.debug("Using adapter for createOrUpdateCollections (unified path)", {
|
|
638
|
-
prefix: "UtilsController",
|
|
639
|
-
apiMode: this.adapter.getApiMode()
|
|
640
|
-
});
|
|
641
|
-
await createOrUpdateCollectionsViaAdapter(
|
|
642
|
-
this.adapter,
|
|
643
|
-
database.$id,
|
|
644
|
-
this.config,
|
|
645
|
-
deletedCollections,
|
|
646
|
-
collections
|
|
647
|
-
);
|
|
648
|
-
} else {
|
|
649
|
-
// Fallback if adapter is unavailable for some reason
|
|
650
|
-
logger.debug("Adapter unavailable, falling back to legacy Databases path", { prefix: "UtilsController" });
|
|
651
|
-
await createOrUpdateCollections(
|
|
652
|
-
this.database,
|
|
653
|
-
database.$id,
|
|
654
|
-
this.config,
|
|
655
|
-
deletedCollections,
|
|
656
|
-
collections
|
|
657
|
-
);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
629
|
+
// Ensure we don't carry state between databases in a multi-db push
|
|
630
|
+
// This resets processed sets and name->id mapping per database
|
|
631
|
+
try {
|
|
632
|
+
const { clearProcessingState } = await import('./shared/operationQueue.js');
|
|
633
|
+
clearProcessingState();
|
|
634
|
+
} catch {}
|
|
635
|
+
|
|
636
|
+
// Always prefer adapter path for unified behavior. LegacyAdapter internally translates when needed.
|
|
637
|
+
if (this.adapter) {
|
|
638
|
+
logger.debug("Using adapter for createOrUpdateCollections (unified path)", {
|
|
639
|
+
prefix: "UtilsController",
|
|
640
|
+
apiMode: this.adapter.getApiMode()
|
|
641
|
+
});
|
|
642
|
+
await createOrUpdateCollectionsViaAdapter(
|
|
643
|
+
this.adapter,
|
|
644
|
+
database.$id,
|
|
645
|
+
this.config,
|
|
646
|
+
deletedCollections,
|
|
647
|
+
collections
|
|
648
|
+
);
|
|
649
|
+
} else {
|
|
650
|
+
// Fallback if adapter is unavailable for some reason
|
|
651
|
+
logger.debug("Adapter unavailable, falling back to legacy Databases path", { prefix: "UtilsController" });
|
|
652
|
+
await createOrUpdateCollections(
|
|
653
|
+
this.database,
|
|
654
|
+
database.$id,
|
|
655
|
+
this.config,
|
|
656
|
+
deletedCollections,
|
|
657
|
+
collections
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
660
661
|
|
|
661
662
|
async generateSchemas() {
|
|
662
663
|
// Schema generation doesn't need Appwrite connection, just config
|
|
@@ -855,24 +856,24 @@ export class UtilsController {
|
|
|
855
856
|
MessageFormatter.success("Selective pull completed successfully! Remote config pulled to local.", { prefix: "Controller" });
|
|
856
857
|
}
|
|
857
858
|
|
|
858
|
-
async selectivePush(
|
|
859
|
-
databaseSelections: DatabaseSelection[],
|
|
860
|
-
bucketSelections: BucketSelection[]
|
|
861
|
-
): Promise<void> {
|
|
862
|
-
await this.init();
|
|
863
|
-
if (!this.database) {
|
|
864
|
-
MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// Always reload config from disk so pushes use current local YAML/Ts definitions
|
|
869
|
-
try {
|
|
870
|
-
await this.reloadConfig();
|
|
871
|
-
MessageFormatter.info("Reloaded config from disk for push", { prefix: "Controller" });
|
|
872
|
-
} catch (e) {
|
|
873
|
-
// Non-fatal; continue with existing config
|
|
874
|
-
MessageFormatter.warning("Could not reload config; continuing with current in-memory config", { prefix: "Controller" });
|
|
875
|
-
}
|
|
859
|
+
async selectivePush(
|
|
860
|
+
databaseSelections: DatabaseSelection[],
|
|
861
|
+
bucketSelections: BucketSelection[]
|
|
862
|
+
): Promise<void> {
|
|
863
|
+
await this.init();
|
|
864
|
+
if (!this.database) {
|
|
865
|
+
MessageFormatter.error("Database not initialized", undefined, { prefix: "Controller" });
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Always reload config from disk so pushes use current local YAML/Ts definitions
|
|
870
|
+
try {
|
|
871
|
+
await this.reloadConfig();
|
|
872
|
+
MessageFormatter.info("Reloaded config from disk for push", { prefix: "Controller" });
|
|
873
|
+
} catch (e) {
|
|
874
|
+
// Non-fatal; continue with existing config
|
|
875
|
+
MessageFormatter.warning("Could not reload config; continuing with current in-memory config", { prefix: "Controller" });
|
|
876
|
+
}
|
|
876
877
|
|
|
877
878
|
MessageFormatter.progress("Starting selective push (local config → Appwrite)...", { prefix: "Controller" });
|
|
878
879
|
|
|
@@ -916,7 +917,7 @@ export class UtilsController {
|
|
|
916
917
|
const databaseCollectionsMap = new Map<string, any[]>();
|
|
917
918
|
|
|
918
919
|
// Get all collections/tables from config (they're at the root level, not nested in databases)
|
|
919
|
-
const allCollections = this.config?.collections || this.config?.tables || [];
|
|
920
|
+
const allCollections = this.config?.collections || this.config?.tables || [];
|
|
920
921
|
|
|
921
922
|
// Create database-specific collection mapping to preserve relationships
|
|
922
923
|
for (const dbSelection of databaseSelections) {
|
|
@@ -924,17 +925,17 @@ export class UtilsController {
|
|
|
924
925
|
|
|
925
926
|
MessageFormatter.info(`Processing collections for database: ${dbSelection.databaseId}`, { prefix: "Controller" });
|
|
926
927
|
|
|
927
|
-
// Filter collections that were selected for THIS specific database
|
|
928
|
-
for (const collection of allCollections) {
|
|
929
|
-
const collectionId = collection.$id || (collection as any).id;
|
|
930
|
-
|
|
931
|
-
// Check if this collection was selected for THIS database
|
|
932
|
-
if (dbSelection.tableIds.includes(collectionId)) {
|
|
933
|
-
collectionsForDatabase.push(collection);
|
|
934
|
-
const source = (collection as any)._isFromTablesDir ? 'tables/' : 'collections/';
|
|
935
|
-
MessageFormatter.info(` - Selected collection: ${collection.name || collectionId} for database ${dbSelection.databaseId} [source: ${source}]`, { prefix: "Controller" });
|
|
936
|
-
}
|
|
937
|
-
}
|
|
928
|
+
// Filter collections that were selected for THIS specific database
|
|
929
|
+
for (const collection of allCollections) {
|
|
930
|
+
const collectionId = collection.$id || (collection as any).id;
|
|
931
|
+
|
|
932
|
+
// Check if this collection was selected for THIS database
|
|
933
|
+
if (dbSelection.tableIds.includes(collectionId)) {
|
|
934
|
+
collectionsForDatabase.push(collection);
|
|
935
|
+
const source = (collection as any)._isFromTablesDir ? 'tables/' : 'collections/';
|
|
936
|
+
MessageFormatter.info(` - Selected collection: ${collection.name || collectionId} for database ${dbSelection.databaseId} [source: ${source}]`, { prefix: "Controller" });
|
|
937
|
+
}
|
|
938
|
+
}
|
|
938
939
|
|
|
939
940
|
databaseCollectionsMap.set(dbSelection.databaseId, collectionsForDatabase);
|
|
940
941
|
MessageFormatter.info(`Database ${dbSelection.databaseId}: ${collectionsForDatabase.length} collections selected`, { prefix: "Controller" });
|