appwrite-utils-cli 1.5.2 → 1.6.1
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 +199 -0
- package/README.md +251 -29
- package/dist/adapters/AdapterFactory.d.ts +10 -3
- package/dist/adapters/AdapterFactory.js +213 -17
- package/dist/adapters/TablesDBAdapter.js +60 -17
- package/dist/backups/operations/bucketBackup.d.ts +19 -0
- package/dist/backups/operations/bucketBackup.js +197 -0
- package/dist/backups/operations/collectionBackup.d.ts +30 -0
- package/dist/backups/operations/collectionBackup.js +201 -0
- package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
- package/dist/backups/operations/comprehensiveBackup.js +238 -0
- package/dist/backups/schemas/bucketManifest.d.ts +93 -0
- package/dist/backups/schemas/bucketManifest.js +33 -0
- package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
- package/dist/backups/schemas/comprehensiveManifest.js +32 -0
- package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
- package/dist/backups/tracking/centralizedTracking.js +274 -0
- package/dist/cli/commands/configCommands.d.ts +8 -0
- package/dist/cli/commands/configCommands.js +160 -0
- package/dist/cli/commands/databaseCommands.d.ts +13 -0
- package/dist/cli/commands/databaseCommands.js +479 -0
- package/dist/cli/commands/functionCommands.d.ts +7 -0
- package/dist/cli/commands/functionCommands.js +289 -0
- package/dist/cli/commands/schemaCommands.d.ts +7 -0
- package/dist/cli/commands/schemaCommands.js +134 -0
- package/dist/cli/commands/transferCommands.d.ts +5 -0
- package/dist/cli/commands/transferCommands.js +384 -0
- package/dist/collections/attributes.d.ts +5 -4
- package/dist/collections/attributes.js +539 -246
- package/dist/collections/indexes.js +39 -37
- package/dist/collections/methods.d.ts +2 -16
- package/dist/collections/methods.js +90 -538
- package/dist/collections/transferOperations.d.ts +7 -0
- package/dist/collections/transferOperations.js +331 -0
- package/dist/collections/wipeOperations.d.ts +16 -0
- package/dist/collections/wipeOperations.js +328 -0
- package/dist/config/configMigration.d.ts +87 -0
- package/dist/config/configMigration.js +390 -0
- package/dist/config/configValidation.d.ts +66 -0
- package/dist/config/configValidation.js +358 -0
- package/dist/config/yamlConfig.d.ts +455 -1
- package/dist/config/yamlConfig.js +145 -52
- package/dist/databases/methods.js +3 -2
- package/dist/databases/setup.d.ts +1 -2
- package/dist/databases/setup.js +9 -87
- package/dist/examples/yamlTerminologyExample.d.ts +42 -0
- package/dist/examples/yamlTerminologyExample.js +269 -0
- package/dist/functions/deployments.js +11 -10
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -4
- package/dist/init.js +9 -9
- package/dist/interactiveCLI.d.ts +8 -17
- package/dist/interactiveCLI.js +209 -1172
- package/dist/main.js +364 -21
- package/dist/migrations/afterImportActions.js +22 -30
- package/dist/migrations/appwriteToX.js +71 -25
- package/dist/migrations/dataLoader.js +35 -26
- package/dist/migrations/importController.js +29 -30
- package/dist/migrations/relationships.js +13 -12
- package/dist/migrations/services/ImportOrchestrator.js +16 -19
- package/dist/migrations/transfer.js +46 -46
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +3 -1
- package/dist/migrations/yaml/YamlImportConfigLoader.js +6 -3
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +9 -3
- package/dist/migrations/yaml/YamlImportIntegration.js +22 -11
- package/dist/migrations/yaml/generateImportSchemas.d.ts +14 -1
- package/dist/migrations/yaml/generateImportSchemas.js +736 -7
- package/dist/schemas/authUser.d.ts +1 -1
- package/dist/setupController.js +3 -2
- package/dist/shared/backupMetadataSchema.d.ts +94 -0
- package/dist/shared/backupMetadataSchema.js +38 -0
- package/dist/shared/backupTracking.d.ts +18 -0
- package/dist/shared/backupTracking.js +176 -0
- package/dist/shared/confirmationDialogs.js +15 -15
- package/dist/shared/errorUtils.d.ts +54 -0
- package/dist/shared/errorUtils.js +95 -0
- package/dist/shared/functionManager.js +20 -19
- package/dist/shared/indexManager.js +12 -11
- package/dist/shared/jsonSchemaGenerator.js +10 -26
- package/dist/shared/logging.d.ts +51 -0
- package/dist/shared/logging.js +70 -0
- package/dist/shared/messageFormatter.d.ts +2 -0
- package/dist/shared/messageFormatter.js +10 -0
- package/dist/shared/migrationHelpers.d.ts +6 -16
- package/dist/shared/migrationHelpers.js +24 -21
- package/dist/shared/operationLogger.d.ts +8 -1
- package/dist/shared/operationLogger.js +11 -24
- package/dist/shared/operationQueue.d.ts +28 -1
- package/dist/shared/operationQueue.js +268 -66
- package/dist/shared/operationsTable.d.ts +26 -0
- package/dist/shared/operationsTable.js +286 -0
- package/dist/shared/operationsTableSchema.d.ts +48 -0
- package/dist/shared/operationsTableSchema.js +35 -0
- package/dist/shared/relationshipExtractor.d.ts +56 -0
- package/dist/shared/relationshipExtractor.js +138 -0
- package/dist/shared/schemaGenerator.d.ts +19 -1
- package/dist/shared/schemaGenerator.js +56 -75
- package/dist/storage/backupCompression.d.ts +20 -0
- package/dist/storage/backupCompression.js +67 -0
- package/dist/storage/methods.d.ts +16 -2
- package/dist/storage/methods.js +98 -14
- package/dist/users/methods.js +9 -8
- package/dist/utils/configDiscovery.d.ts +78 -0
- package/dist/utils/configDiscovery.js +430 -0
- package/dist/utils/directoryUtils.d.ts +22 -0
- package/dist/utils/directoryUtils.js +59 -0
- package/dist/utils/getClientFromConfig.d.ts +17 -8
- package/dist/utils/getClientFromConfig.js +162 -17
- package/dist/utils/helperFunctions.d.ts +16 -2
- package/dist/utils/helperFunctions.js +19 -5
- package/dist/utils/loadConfigs.d.ts +34 -9
- package/dist/utils/loadConfigs.js +236 -316
- package/dist/utils/pathResolvers.d.ts +53 -0
- package/dist/utils/pathResolvers.js +72 -0
- package/dist/utils/projectConfig.d.ts +119 -0
- package/dist/utils/projectConfig.js +171 -0
- package/dist/utils/retryFailedPromises.js +4 -2
- package/dist/utils/sessionAuth.d.ts +48 -0
- package/dist/utils/sessionAuth.js +164 -0
- package/dist/utils/sessionPreservationExample.d.ts +1666 -0
- package/dist/utils/sessionPreservationExample.js +101 -0
- package/dist/utils/setupFiles.js +301 -41
- package/dist/utils/typeGuards.d.ts +35 -0
- package/dist/utils/typeGuards.js +57 -0
- package/dist/utils/versionDetection.js +145 -9
- package/dist/utils/yamlConverter.d.ts +53 -3
- package/dist/utils/yamlConverter.js +232 -13
- package/dist/utils/yamlLoader.d.ts +70 -0
- package/dist/utils/yamlLoader.js +263 -0
- package/dist/utilsController.d.ts +36 -3
- package/dist/utilsController.js +186 -56
- package/package.json +12 -2
- package/src/adapters/AdapterFactory.ts +263 -35
- package/src/adapters/TablesDBAdapter.ts +225 -36
- package/src/backups/operations/bucketBackup.ts +277 -0
- package/src/backups/operations/collectionBackup.ts +310 -0
- package/src/backups/operations/comprehensiveBackup.ts +342 -0
- package/src/backups/schemas/bucketManifest.ts +78 -0
- package/src/backups/schemas/comprehensiveManifest.ts +76 -0
- package/src/backups/tracking/centralizedTracking.ts +352 -0
- package/src/cli/commands/configCommands.ts +194 -0
- package/src/cli/commands/databaseCommands.ts +635 -0
- package/src/cli/commands/functionCommands.ts +379 -0
- package/src/cli/commands/schemaCommands.ts +163 -0
- package/src/cli/commands/transferCommands.ts +457 -0
- package/src/collections/attributes.ts +900 -621
- package/src/collections/attributes.ts.backup +1555 -0
- package/src/collections/indexes.ts +116 -114
- package/src/collections/methods.ts +295 -968
- package/src/collections/transferOperations.ts +516 -0
- package/src/collections/wipeOperations.ts +501 -0
- package/src/config/README.md +274 -0
- package/src/config/configMigration.ts +575 -0
- package/src/config/configValidation.ts +445 -0
- package/src/config/yamlConfig.ts +168 -55
- package/src/databases/methods.ts +3 -2
- package/src/databases/setup.ts +11 -138
- package/src/examples/yamlTerminologyExample.ts +341 -0
- package/src/functions/deployments.ts +14 -12
- package/src/functions/methods.ts +11 -11
- package/src/functions/templates/hono-typescript/README.md +286 -0
- package/src/functions/templates/hono-typescript/package.json +26 -0
- package/src/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
- package/src/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
- package/src/functions/templates/hono-typescript/src/app.ts +180 -0
- package/src/functions/templates/hono-typescript/src/context.ts +103 -0
- package/src/functions/templates/hono-typescript/src/index.ts +54 -0
- package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
- package/src/functions/templates/hono-typescript/tsconfig.json +20 -0
- package/src/functions/templates/typescript-node/package.json +2 -1
- package/src/functions/templates/typescript-node/src/context.ts +103 -0
- package/src/functions/templates/typescript-node/src/index.ts +18 -12
- package/src/functions/templates/uv/pyproject.toml +1 -0
- package/src/functions/templates/uv/src/context.py +125 -0
- package/src/functions/templates/uv/src/index.py +35 -5
- package/src/init.ts +9 -11
- package/src/interactiveCLI.ts +274 -1563
- package/src/main.ts +418 -24
- package/src/migrations/afterImportActions.ts +71 -44
- package/src/migrations/appwriteToX.ts +100 -34
- package/src/migrations/dataLoader.ts +48 -34
- package/src/migrations/importController.ts +44 -39
- package/src/migrations/relationships.ts +28 -18
- package/src/migrations/services/ImportOrchestrator.ts +24 -27
- package/src/migrations/transfer.ts +159 -121
- package/src/migrations/yaml/YamlImportConfigLoader.ts +11 -4
- package/src/migrations/yaml/YamlImportIntegration.ts +47 -20
- package/src/migrations/yaml/generateImportSchemas.ts +751 -12
- package/src/setupController.ts +3 -2
- package/src/shared/backupMetadataSchema.ts +93 -0
- package/src/shared/backupTracking.ts +211 -0
- package/src/shared/confirmationDialogs.ts +19 -19
- package/src/shared/errorUtils.ts +110 -0
- package/src/shared/functionManager.ts +21 -20
- package/src/shared/indexManager.ts +12 -11
- package/src/shared/jsonSchemaGenerator.ts +38 -52
- package/src/shared/logging.ts +75 -0
- package/src/shared/messageFormatter.ts +14 -1
- package/src/shared/migrationHelpers.ts +45 -38
- package/src/shared/operationLogger.ts +11 -36
- package/src/shared/operationQueue.ts +322 -93
- package/src/shared/operationsTable.ts +338 -0
- package/src/shared/operationsTableSchema.ts +60 -0
- package/src/shared/relationshipExtractor.ts +214 -0
- package/src/shared/schemaGenerator.ts +179 -219
- package/src/storage/backupCompression.ts +88 -0
- package/src/storage/methods.ts +131 -34
- package/src/users/methods.ts +11 -9
- package/src/utils/configDiscovery.ts +502 -0
- package/src/utils/directoryUtils.ts +61 -0
- package/src/utils/getClientFromConfig.ts +205 -22
- package/src/utils/helperFunctions.ts +23 -5
- package/src/utils/loadConfigs.ts +313 -345
- package/src/utils/pathResolvers.ts +81 -0
- package/src/utils/projectConfig.ts +299 -0
- package/src/utils/retryFailedPromises.ts +4 -2
- package/src/utils/sessionAuth.ts +230 -0
- package/src/utils/setupFiles.ts +322 -54
- package/src/utils/typeGuards.ts +65 -0
- package/src/utils/versionDetection.ts +218 -64
- package/src/utils/yamlConverter.ts +296 -13
- package/src/utils/yamlLoader.ts +364 -0
- package/src/utilsController.ts +314 -110
- package/tests/README.md +497 -0
- package/tests/adapters/AdapterFactory.test.ts +277 -0
- package/tests/integration/syncOperations.test.ts +463 -0
- package/tests/jest.config.js +25 -0
- package/tests/migration/configMigration.test.ts +546 -0
- package/tests/setup.ts +62 -0
- package/tests/testUtils.ts +340 -0
- package/tests/utils/loadConfigs.test.ts +350 -0
- package/tests/validation/configValidation.test.ts +412 -0
- package/src/utils/schemaStrings.ts +0 -517
@@ -0,0 +1,269 @@
|
|
1
|
+
/**
|
2
|
+
* Example demonstrating YAML import/export with dual terminology support
|
3
|
+
*
|
4
|
+
* This example shows how to:
|
5
|
+
* 1. Generate YAML files for both collections and tables
|
6
|
+
* 2. Load and convert between terminologies
|
7
|
+
* 3. Validate terminology consistency
|
8
|
+
* 4. Migrate between formats
|
9
|
+
*/
|
10
|
+
import { collectionToYaml, generateYamlTemplate, generateExampleYamls, convertTerminology, normalizeYamlData, usesTableTerminology } from "../utils/yamlConverter.js";
|
11
|
+
import { createYamlLoader } from "../utils/yamlLoader.js";
|
12
|
+
import { YamlImportIntegration } from "../migrations/yaml/YamlImportIntegration.js";
|
13
|
+
import { createImportSchemas } from "../migrations/yaml/generateImportSchemas.js";
|
14
|
+
import fs from "fs";
|
15
|
+
import path from "path";
|
16
|
+
/**
|
17
|
+
* Example 1: Generate YAML templates for both collection and table formats
|
18
|
+
*/
|
19
|
+
export async function generateTemplateExamples(outputDir) {
|
20
|
+
console.log("🚀 Generating YAML template examples...");
|
21
|
+
// Ensure output directories exist
|
22
|
+
const collectionsDir = path.join(outputDir, "collections");
|
23
|
+
const tablesDir = path.join(outputDir, "tables");
|
24
|
+
[collectionsDir, tablesDir].forEach(dir => {
|
25
|
+
if (!fs.existsSync(dir)) {
|
26
|
+
fs.mkdirSync(dir, { recursive: true });
|
27
|
+
}
|
28
|
+
});
|
29
|
+
// Generate schemas first
|
30
|
+
await createImportSchemas(outputDir);
|
31
|
+
// Generate examples for both formats
|
32
|
+
const examples = generateExampleYamls("Product");
|
33
|
+
// Save collection format
|
34
|
+
const collectionPath = path.join(collectionsDir, "Product.yaml");
|
35
|
+
fs.writeFileSync(collectionPath, examples.collection);
|
36
|
+
console.log(`✅ Generated collection YAML: ${collectionPath}`);
|
37
|
+
// Save table format
|
38
|
+
const tablePath = path.join(tablesDir, "Product.yaml");
|
39
|
+
fs.writeFileSync(tablePath, examples.table);
|
40
|
+
console.log(`✅ Generated table YAML: ${tablePath}`);
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Example 2: Convert existing collection definition to different formats
|
44
|
+
*/
|
45
|
+
export function convertCollectionFormats(collection) {
|
46
|
+
console.log("🔄 Converting collection to different YAML formats...");
|
47
|
+
// Generate collection format YAML
|
48
|
+
const collectionConfig = {
|
49
|
+
useTableTerminology: false,
|
50
|
+
entityType: 'collection',
|
51
|
+
schemaPath: "../.yaml_schemas/collection.schema.json"
|
52
|
+
};
|
53
|
+
const collectionYaml = collectionToYaml(collection, collectionConfig);
|
54
|
+
console.log("📄 Collection Format YAML:");
|
55
|
+
console.log(collectionYaml);
|
56
|
+
console.log("");
|
57
|
+
// Generate table format YAML
|
58
|
+
const tableConfig = {
|
59
|
+
useTableTerminology: true,
|
60
|
+
entityType: 'table',
|
61
|
+
schemaPath: "../.yaml_schemas/table.schema.json"
|
62
|
+
};
|
63
|
+
const tableYaml = collectionToYaml(collection, tableConfig);
|
64
|
+
console.log("📄 Table Format YAML:");
|
65
|
+
console.log(tableYaml);
|
66
|
+
}
|
67
|
+
/**
|
68
|
+
* Example 3: Load and process YAML files with mixed terminologies
|
69
|
+
*/
|
70
|
+
export async function processYamlFiles(baseDir) {
|
71
|
+
console.log("📂 Processing YAML files with terminology support...");
|
72
|
+
const yamlLoader = createYamlLoader(baseDir);
|
73
|
+
// Load all YAML files from collections directory
|
74
|
+
const collectionsResult = await yamlLoader.loadDirectoryYamls("collections");
|
75
|
+
console.log(`📊 Collections Summary:`, collectionsResult.summary);
|
76
|
+
// Load all YAML files from tables directory
|
77
|
+
const tablesResult = await yamlLoader.loadDirectoryYamls("tables");
|
78
|
+
console.log(`📊 Tables Summary:`, tablesResult.summary);
|
79
|
+
// Process each file and show terminology detection
|
80
|
+
console.log("\\n🔍 File Analysis:");
|
81
|
+
[...collectionsResult.collections, ...tablesResult.collections].forEach(file => {
|
82
|
+
const terminology = file.originalTerminology;
|
83
|
+
const hasColumns = usesTableTerminology(file.data);
|
84
|
+
console.log(` ${file.filePath}: ${terminology} format (uses table terminology: ${hasColumns})`);
|
85
|
+
});
|
86
|
+
}
|
87
|
+
/**
|
88
|
+
* Example 4: Migrate between terminologies
|
89
|
+
*/
|
90
|
+
export async function migrateTerminology(baseDir) {
|
91
|
+
console.log("🔄 Migrating between terminologies...");
|
92
|
+
const yamlLoader = createYamlLoader(baseDir);
|
93
|
+
// Migrate collections to table format
|
94
|
+
console.log("\\n📤 Migrating collections to table format...");
|
95
|
+
const collectionToTableResult = await yamlLoader.migrateTerminology("collections", "migrated/tables", true // to table terminology
|
96
|
+
);
|
97
|
+
console.log(`✅ Migration complete: ${collectionToTableResult.migrated} migrated, ${collectionToTableResult.skipped} skipped`);
|
98
|
+
if (collectionToTableResult.errors.length > 0) {
|
99
|
+
console.log(`❌ Errors:`, collectionToTableResult.errors);
|
100
|
+
}
|
101
|
+
// Migrate tables to collection format
|
102
|
+
console.log("\\n📤 Migrating tables to collection format...");
|
103
|
+
const tableToCollectionResult = await yamlLoader.migrateTerminology("tables", "migrated/collections", false // to collection terminology
|
104
|
+
);
|
105
|
+
console.log(`✅ Migration complete: ${tableToCollectionResult.migrated} migrated, ${tableToCollectionResult.skipped} skipped`);
|
106
|
+
if (tableToCollectionResult.errors.length > 0) {
|
107
|
+
console.log(`❌ Errors:`, tableToCollectionResult.errors);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
/**
|
111
|
+
* Example 5: Validate terminology consistency
|
112
|
+
*/
|
113
|
+
export async function validateTerminology(baseDir) {
|
114
|
+
console.log("🔍 Validating terminology consistency...");
|
115
|
+
const yamlLoader = createYamlLoader(baseDir);
|
116
|
+
// Validate collections directory
|
117
|
+
const collectionsValidation = await yamlLoader.validateTerminologyConsistency("collections");
|
118
|
+
console.log("\\n📂 Collections Directory:");
|
119
|
+
console.log(` Consistent: ${collectionsValidation.isConsistent}`);
|
120
|
+
console.log(` Summary:`, collectionsValidation.summary);
|
121
|
+
if (collectionsValidation.issues.length > 0) {
|
122
|
+
console.log(` Issues:`);
|
123
|
+
collectionsValidation.issues.forEach(issue => {
|
124
|
+
console.log(` ${issue.severity.toUpperCase()}: ${issue.file} - ${issue.issue}`);
|
125
|
+
});
|
126
|
+
}
|
127
|
+
// Validate tables directory
|
128
|
+
const tablesValidation = await yamlLoader.validateTerminologyConsistency("tables");
|
129
|
+
console.log("\\n📂 Tables Directory:");
|
130
|
+
console.log(` Consistent: ${tablesValidation.isConsistent}`);
|
131
|
+
console.log(` Summary:`, tablesValidation.summary);
|
132
|
+
if (tablesValidation.issues.length > 0) {
|
133
|
+
console.log(` Issues:`);
|
134
|
+
tablesValidation.issues.forEach(issue => {
|
135
|
+
console.log(` ${issue.severity.toUpperCase()}: ${issue.file} - ${issue.issue}`);
|
136
|
+
});
|
137
|
+
}
|
138
|
+
}
|
139
|
+
/**
|
140
|
+
* Example 6: Import configuration with terminology support
|
141
|
+
*/
|
142
|
+
export async function importConfigurationExample(appwriteFolderPath) {
|
143
|
+
console.log("📥 Import configuration with terminology support...");
|
144
|
+
const yamlImportIntegration = new YamlImportIntegration(appwriteFolderPath);
|
145
|
+
// Initialize YAML import system
|
146
|
+
await yamlImportIntegration.initialize();
|
147
|
+
// Create example import configurations for both formats
|
148
|
+
console.log("\\n📝 Creating import configuration templates...");
|
149
|
+
// Collection format import config
|
150
|
+
await yamlImportIntegration.createFromTemplate("Users", "users.json", false, // collection terminology
|
151
|
+
"users-collection-import.yaml");
|
152
|
+
// Table format import config
|
153
|
+
await yamlImportIntegration.createFromTemplate("Users", "users.json", true, // table terminology
|
154
|
+
"users-table-import.yaml");
|
155
|
+
// Get statistics
|
156
|
+
const stats = await yamlImportIntegration.getStatistics();
|
157
|
+
console.log("\\n📊 Import Configuration Statistics:");
|
158
|
+
console.log(` Total configurations: ${stats.totalConfigurations}`);
|
159
|
+
console.log(` Collections with configs: ${stats.collectionsWithConfigs}`);
|
160
|
+
console.log(` Total attribute mappings: ${stats.totalAttributeMappings}`);
|
161
|
+
console.log(` Total relationship mappings: ${stats.totalRelationshipMappings}`);
|
162
|
+
}
|
163
|
+
/**
|
164
|
+
* Example 7: Manual terminology conversion
|
165
|
+
*/
|
166
|
+
export function manualTerminologyConversion() {
|
167
|
+
console.log("🔧 Manual terminology conversion example...");
|
168
|
+
// Sample YAML data with collection terminology
|
169
|
+
const collectionData = {
|
170
|
+
name: "Product",
|
171
|
+
id: "product",
|
172
|
+
attributes: [
|
173
|
+
{
|
174
|
+
key: "name",
|
175
|
+
type: "string",
|
176
|
+
required: true,
|
177
|
+
relatedCollection: "Categories"
|
178
|
+
}
|
179
|
+
],
|
180
|
+
indexes: [
|
181
|
+
{
|
182
|
+
key: "name_index",
|
183
|
+
type: "key",
|
184
|
+
attributes: ["name"]
|
185
|
+
}
|
186
|
+
]
|
187
|
+
};
|
188
|
+
console.log("\\n📝 Original (Collection format):");
|
189
|
+
console.log(JSON.stringify(collectionData, null, 2));
|
190
|
+
// Convert to table terminology
|
191
|
+
const tableData = convertTerminology(collectionData, true);
|
192
|
+
console.log("\\n🔄 Converted to Table format:");
|
193
|
+
console.log(JSON.stringify(tableData, null, 2));
|
194
|
+
// Convert back to collection terminology
|
195
|
+
const normalizedData = normalizeYamlData(tableData);
|
196
|
+
console.log("\\n↩️ Normalized back to Collection format:");
|
197
|
+
console.log(JSON.stringify(normalizedData, null, 2));
|
198
|
+
// Terminology detection
|
199
|
+
console.log("\\n🔍 Terminology Detection:");
|
200
|
+
console.log(` Original uses table terminology: ${usesTableTerminology(collectionData)}`);
|
201
|
+
console.log(` Converted uses table terminology: ${usesTableTerminology(tableData)}`);
|
202
|
+
console.log(` Normalized uses table terminology: ${usesTableTerminology(normalizedData)}`);
|
203
|
+
}
|
204
|
+
/**
|
205
|
+
* Main example runner
|
206
|
+
*/
|
207
|
+
export async function runYamlTerminologyExamples(outputDir) {
|
208
|
+
console.log("🎯 Running YAML Terminology Examples\\n");
|
209
|
+
try {
|
210
|
+
// Example collection for demonstrations
|
211
|
+
const exampleCollection = {
|
212
|
+
name: "Product",
|
213
|
+
$id: "product",
|
214
|
+
enabled: true,
|
215
|
+
documentSecurity: false,
|
216
|
+
$permissions: [],
|
217
|
+
attributes: [
|
218
|
+
{
|
219
|
+
key: "name",
|
220
|
+
type: "string",
|
221
|
+
required: true,
|
222
|
+
size: 255
|
223
|
+
},
|
224
|
+
{
|
225
|
+
key: "price",
|
226
|
+
type: "float",
|
227
|
+
required: true,
|
228
|
+
min: 0
|
229
|
+
},
|
230
|
+
{
|
231
|
+
key: "categoryId",
|
232
|
+
type: "relationship",
|
233
|
+
relationType: "manyToOne",
|
234
|
+
relatedCollection: "Categories",
|
235
|
+
twoWay: false,
|
236
|
+
onDelete: "setNull"
|
237
|
+
}
|
238
|
+
],
|
239
|
+
indexes: [
|
240
|
+
{
|
241
|
+
key: "name_index",
|
242
|
+
type: "key",
|
243
|
+
attributes: ["name"]
|
244
|
+
}
|
245
|
+
],
|
246
|
+
importDefs: []
|
247
|
+
};
|
248
|
+
// Run examples
|
249
|
+
await generateTemplateExamples(outputDir);
|
250
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
251
|
+
convertCollectionFormats(exampleCollection);
|
252
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
253
|
+
await processYamlFiles(outputDir);
|
254
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
255
|
+
await migrateTerminology(outputDir);
|
256
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
257
|
+
await validateTerminology(outputDir);
|
258
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
259
|
+
await importConfigurationExample(outputDir);
|
260
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
261
|
+
manualTerminologyConversion();
|
262
|
+
console.log("\\n🎉 All examples completed successfully!");
|
263
|
+
}
|
264
|
+
catch (error) {
|
265
|
+
console.error("❌ Error running examples:", error);
|
266
|
+
throw error;
|
267
|
+
}
|
268
|
+
}
|
269
|
+
// Note: Functions are already exported above with their declarations
|
@@ -10,6 +10,7 @@ import cliProgress from "cli-progress";
|
|
10
10
|
import { execSync } from "child_process";
|
11
11
|
import { createFunction, getFunction, updateFunction, updateFunctionSpecifications, } from "./methods.js";
|
12
12
|
import ignore from "ignore";
|
13
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
13
14
|
const findFunctionDirectory = (basePath, functionName) => {
|
14
15
|
const normalizedName = functionName.toLowerCase().replace(/\s+/g, "-");
|
15
16
|
const dirs = fs.readdirSync(basePath, { withFileTypes: true });
|
@@ -36,7 +37,7 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
|
|
36
37
|
".venv",
|
37
38
|
]) => {
|
38
39
|
const functions = new Functions(client);
|
39
|
-
|
40
|
+
MessageFormatter.processing("Preparing function deployment...", { prefix: "Deployment" });
|
40
41
|
// Convert ignored patterns to lowercase for case-insensitive comparison
|
41
42
|
const ignoredLower = ignored.map((pattern) => pattern.toLowerCase());
|
42
43
|
const tarPath = join(process.cwd(), `function-${functionId}.tar.gz`);
|
@@ -48,7 +49,7 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
|
|
48
49
|
if (!stats.isDirectory()) {
|
49
50
|
throw new Error(`${codePath} is not a directory`);
|
50
51
|
}
|
51
|
-
|
52
|
+
MessageFormatter.processing(`Creating tarball from ${codePath}`, { prefix: "Deployment" });
|
52
53
|
const progressBar = new cliProgress.SingleBar({
|
53
54
|
format: "Uploading |" +
|
54
55
|
chalk.cyan("{bar}") +
|
@@ -67,7 +68,7 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
|
|
67
68
|
if (ignoredLower.some((pattern) => relativePath.startsWith(pattern) ||
|
68
69
|
relativePath.includes(`/${pattern}`) ||
|
69
70
|
relativePath.includes(`\\${pattern}`))) {
|
70
|
-
|
71
|
+
MessageFormatter.debug(`Ignoring ${path}`, undefined, { prefix: "Deployment" });
|
71
72
|
return false;
|
72
73
|
}
|
73
74
|
return true;
|
@@ -77,7 +78,7 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
|
|
77
78
|
const fileBuffer = await fs.promises.readFile(tarPath);
|
78
79
|
const fileObject = InputFile.fromBuffer(new Uint8Array(fileBuffer), `function-${functionId}.tar.gz`);
|
79
80
|
try {
|
80
|
-
|
81
|
+
MessageFormatter.processing("Creating deployment...", { prefix: "Deployment" });
|
81
82
|
// Start with 1 as default total since we don't know the chunk size yet
|
82
83
|
progressBar.start(1, 0);
|
83
84
|
const functionResponse = await functions.createDeployment(functionId, fileObject, activate, entrypoint, commands, (progress) => {
|
@@ -94,7 +95,7 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
|
|
94
95
|
if (chunks === total) {
|
95
96
|
progressBar.update(total);
|
96
97
|
progressBar.stop();
|
97
|
-
|
98
|
+
MessageFormatter.success("Upload complete!", { prefix: "Deployment" });
|
98
99
|
}
|
99
100
|
}
|
100
101
|
}
|
@@ -109,7 +110,7 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
|
|
109
110
|
}
|
110
111
|
catch (error) {
|
111
112
|
progressBar.stop();
|
112
|
-
|
113
|
+
MessageFormatter.error("Deployment failed", error instanceof Error ? error : undefined, { prefix: "Deployment" });
|
113
114
|
throw error;
|
114
115
|
}
|
115
116
|
};
|
@@ -130,11 +131,11 @@ export const deployLocalFunction = async (client, functionName, functionConfig,
|
|
130
131
|
throw new Error(`Function directory not found at ${resolvedPath}`);
|
131
132
|
}
|
132
133
|
if (functionConfig.predeployCommands?.length) {
|
133
|
-
|
134
|
+
MessageFormatter.processing("Executing predeploy commands...", { prefix: "Deployment" });
|
134
135
|
const isWindows = platform() === "win32";
|
135
136
|
for (const command of functionConfig.predeployCommands) {
|
136
137
|
try {
|
137
|
-
|
138
|
+
MessageFormatter.debug(`Executing: ${command}`, undefined, { prefix: "Deployment" });
|
138
139
|
execSync(command, {
|
139
140
|
cwd: resolvedPath,
|
140
141
|
stdio: "inherit",
|
@@ -143,7 +144,7 @@ export const deployLocalFunction = async (client, functionName, functionConfig,
|
|
143
144
|
});
|
144
145
|
}
|
145
146
|
catch (error) {
|
146
|
-
|
147
|
+
MessageFormatter.error(`Failed to execute predeploy command: ${command}`, error instanceof Error ? error : undefined, { prefix: "Deployment" });
|
147
148
|
throw new Error(``);
|
148
149
|
}
|
149
150
|
}
|
@@ -153,7 +154,7 @@ export const deployLocalFunction = async (client, functionName, functionConfig,
|
|
153
154
|
await createFunction(client, functionConfig);
|
154
155
|
}
|
155
156
|
else {
|
156
|
-
|
157
|
+
MessageFormatter.processing("Updating function...", { prefix: "Deployment" });
|
157
158
|
await updateFunction(client, functionConfig);
|
158
159
|
}
|
159
160
|
const deployPath = functionConfig.deployDir
|
@@ -13,4 +13,4 @@ export declare const updateFunctionSpecifications: (client: Client, functionId:
|
|
13
13
|
export declare const listSpecifications: (client: Client) => Promise<import("node-appwrite").Models.SpecificationList>;
|
14
14
|
export declare const listFunctionDeployments: (client: Client, functionId: string, queries?: string[]) => Promise<import("node-appwrite").Models.DeploymentList>;
|
15
15
|
export declare const updateFunction: (client: Client, functionConfig: AppwriteFunction) => Promise<import("node-appwrite").Models.Function>;
|
16
|
-
export declare const createFunctionTemplate: (templateType: "typescript-node" | "uv" | "count-docs-in-collection", functionName: string, basePath?: string) => Promise<string>;
|
16
|
+
export declare const createFunctionTemplate: (templateType: "typescript-node" | "uv" | "count-docs-in-collection" | "hono-typescript", functionName: string, basePath?: string) => Promise<string>;
|
@@ -5,6 +5,7 @@ import fs from "node:fs";
|
|
5
5
|
import {} from "appwrite-utils";
|
6
6
|
import chalk from "chalk";
|
7
7
|
import { extract as extractTar } from "tar";
|
8
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
8
9
|
/**
|
9
10
|
* Validates and filters events array for Appwrite functions
|
10
11
|
* - Filters out empty/invalid strings
|
@@ -94,10 +95,10 @@ export const updateFunctionSpecifications = async (client, functionId, specifica
|
|
94
95
|
catch (error) {
|
95
96
|
if (error instanceof AppwriteException &&
|
96
97
|
error.message.includes("Invalid `specification`")) {
|
97
|
-
|
98
|
+
MessageFormatter.error("Error updating function specifications, please try setting the env variable `_FUNCTIONS_CPUS` and `_FUNCTIONS_RAM` to non-zero values", undefined, { prefix: "Functions" });
|
98
99
|
}
|
99
100
|
else {
|
100
|
-
|
101
|
+
MessageFormatter.error("Error updating function specifications", error instanceof Error ? error : undefined, { prefix: "Functions" });
|
101
102
|
throw error;
|
102
103
|
}
|
103
104
|
}
|
@@ -149,10 +150,10 @@ export const createFunctionTemplate = async (templateType, functionName, basePat
|
|
149
150
|
};
|
150
151
|
try {
|
151
152
|
await copyTemplateFiles(templatesPath, functionPath);
|
152
|
-
|
153
|
+
MessageFormatter.success(`Created ${templateType} function template at ${functionPath}`, { prefix: "Functions" });
|
153
154
|
}
|
154
155
|
catch (error) {
|
155
|
-
|
156
|
+
MessageFormatter.error("Failed to create function template", error instanceof Error ? error : undefined, { prefix: "Functions" });
|
156
157
|
throw error;
|
157
158
|
}
|
158
159
|
return functionPath;
|
package/dist/init.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import inquirer from "inquirer";
|
3
3
|
import { createEmptyCollection, setupDirsFiles } from "./utils/setupFiles.js";
|
4
|
-
|
5
|
-
|
4
|
+
import { MessageFormatter } from "./shared/messageFormatter.js";
|
5
|
+
MessageFormatter.banner("Appwrite Utils CLI Tool by Zach Handley", "For more information, visit https://github.com/zachhandley/appwrite-utils");
|
6
6
|
async function main() {
|
7
7
|
const answers = await inquirer.prompt([
|
8
8
|
{
|
@@ -28,30 +28,30 @@ async function main() {
|
|
28
28
|
validate: (input) => input.trim() !== "" || "Collection name cannot be empty.",
|
29
29
|
},
|
30
30
|
]);
|
31
|
-
|
31
|
+
MessageFormatter.progress(`Creating collection config file for '${collectionName}'...`, { prefix: "Init" });
|
32
32
|
createEmptyCollection(collectionName);
|
33
33
|
break;
|
34
34
|
case "Create function (not available)":
|
35
|
-
|
35
|
+
MessageFormatter.warning("This feature is not available yet.", { prefix: "Init" });
|
36
36
|
break;
|
37
37
|
case "Setup directories and files":
|
38
|
-
|
38
|
+
MessageFormatter.progress("Setting up directories and files...", { prefix: "Init" });
|
39
39
|
setupDirsFiles(false); // Assuming false means no example data
|
40
40
|
break;
|
41
41
|
case "Setup directories and files with example data":
|
42
|
-
|
42
|
+
MessageFormatter.progress("Setting up directories and files with example data...", { prefix: "Init" });
|
43
43
|
setupDirsFiles(true); // Assuming false means no example data
|
44
44
|
break;
|
45
45
|
case "Exit":
|
46
|
-
|
46
|
+
MessageFormatter.info("Exiting...", { prefix: "Init" });
|
47
47
|
process.exit(0);
|
48
48
|
break;
|
49
49
|
default:
|
50
|
-
|
50
|
+
MessageFormatter.warning("Invalid option, please try again.", { prefix: "Init" });
|
51
51
|
break;
|
52
52
|
}
|
53
53
|
}
|
54
54
|
main().catch((error) => {
|
55
|
-
|
55
|
+
MessageFormatter.error("An error occurred", error instanceof Error ? error : new Error(String(error)), { prefix: "Init" });
|
56
56
|
process.exit(1);
|
57
57
|
});
|
package/dist/interactiveCLI.d.ts
CHANGED
@@ -7,32 +7,23 @@ export declare class InteractiveCLI {
|
|
7
7
|
private initControllerIfNeeded;
|
8
8
|
private selectDatabases;
|
9
9
|
private selectCollections;
|
10
|
+
/**
|
11
|
+
* Enhanced collection/table selection with better guidance for mixed scenarios
|
12
|
+
*/
|
13
|
+
private selectCollectionsAndTables;
|
10
14
|
private getTemplateDefaults;
|
11
|
-
private createFunction;
|
12
15
|
private findFunctionInSubdirectories;
|
13
|
-
private deployFunction;
|
14
|
-
private deleteFunction;
|
15
16
|
private selectFunctions;
|
16
17
|
private getLocalFunctions;
|
17
18
|
private selectBuckets;
|
18
|
-
private createCollectionConfig;
|
19
19
|
private configureBuckets;
|
20
20
|
private createNewBucket;
|
21
|
-
private syncDb;
|
22
|
-
private synchronizeConfigurations;
|
23
|
-
private backupDatabase;
|
24
|
-
private wipeDatabase;
|
25
|
-
private wipeCollections;
|
26
|
-
private generateSchemas;
|
27
|
-
private generateConstants;
|
28
|
-
private importData;
|
29
|
-
private transferData;
|
30
21
|
private getLocalCollections;
|
31
22
|
private getLocalDatabases;
|
32
|
-
|
33
|
-
|
23
|
+
/**
|
24
|
+
* Extract session information from current controller for preservation
|
25
|
+
*/
|
26
|
+
private extractSessionFromController;
|
34
27
|
private detectConfigurationType;
|
35
28
|
private buildChoicesList;
|
36
|
-
private migrateTypeScriptConfig;
|
37
|
-
private comprehensiveTransfer;
|
38
29
|
}
|