appwrite-utils-cli 1.5.2 → 1.6.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.
- 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 +478 -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 +181 -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 +278 -1596
- 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,341 @@
|
|
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
|
+
|
11
|
+
import {
|
12
|
+
collectionToYaml,
|
13
|
+
generateYamlTemplate,
|
14
|
+
generateExampleYamls,
|
15
|
+
convertTerminology,
|
16
|
+
normalizeYamlData,
|
17
|
+
usesTableTerminology,
|
18
|
+
type YamlTerminologyConfig,
|
19
|
+
type YamlCollectionData
|
20
|
+
} from "../utils/yamlConverter.js";
|
21
|
+
import { createYamlLoader } from "../utils/yamlLoader.js";
|
22
|
+
import { YamlImportIntegration } from "../migrations/yaml/YamlImportIntegration.js";
|
23
|
+
import { createImportSchemas } from "../migrations/yaml/generateImportSchemas.js";
|
24
|
+
import type { CollectionCreate } from "appwrite-utils";
|
25
|
+
import fs from "fs";
|
26
|
+
import path from "path";
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Example 1: Generate YAML templates for both collection and table formats
|
30
|
+
*/
|
31
|
+
export async function generateTemplateExamples(outputDir: string): Promise<void> {
|
32
|
+
console.log("🚀 Generating YAML template examples...");
|
33
|
+
|
34
|
+
// Ensure output directories exist
|
35
|
+
const collectionsDir = path.join(outputDir, "collections");
|
36
|
+
const tablesDir = path.join(outputDir, "tables");
|
37
|
+
|
38
|
+
[collectionsDir, tablesDir].forEach(dir => {
|
39
|
+
if (!fs.existsSync(dir)) {
|
40
|
+
fs.mkdirSync(dir, { recursive: true });
|
41
|
+
}
|
42
|
+
});
|
43
|
+
|
44
|
+
// Generate schemas first
|
45
|
+
await createImportSchemas(outputDir);
|
46
|
+
|
47
|
+
// Generate examples for both formats
|
48
|
+
const examples = generateExampleYamls("Product");
|
49
|
+
|
50
|
+
// Save collection format
|
51
|
+
const collectionPath = path.join(collectionsDir, "Product.yaml");
|
52
|
+
fs.writeFileSync(collectionPath, examples.collection);
|
53
|
+
console.log(`✅ Generated collection YAML: ${collectionPath}`);
|
54
|
+
|
55
|
+
// Save table format
|
56
|
+
const tablePath = path.join(tablesDir, "Product.yaml");
|
57
|
+
fs.writeFileSync(tablePath, examples.table);
|
58
|
+
console.log(`✅ Generated table YAML: ${tablePath}`);
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Example 2: Convert existing collection definition to different formats
|
63
|
+
*/
|
64
|
+
export function convertCollectionFormats(collection: CollectionCreate): void {
|
65
|
+
console.log("🔄 Converting collection to different YAML formats...");
|
66
|
+
|
67
|
+
// Generate collection format YAML
|
68
|
+
const collectionConfig: YamlTerminologyConfig = {
|
69
|
+
useTableTerminology: false,
|
70
|
+
entityType: 'collection',
|
71
|
+
schemaPath: "../.yaml_schemas/collection.schema.json"
|
72
|
+
};
|
73
|
+
const collectionYaml = collectionToYaml(collection, collectionConfig);
|
74
|
+
console.log("📄 Collection Format YAML:");
|
75
|
+
console.log(collectionYaml);
|
76
|
+
console.log("");
|
77
|
+
|
78
|
+
// Generate table format YAML
|
79
|
+
const tableConfig: YamlTerminologyConfig = {
|
80
|
+
useTableTerminology: true,
|
81
|
+
entityType: 'table',
|
82
|
+
schemaPath: "../.yaml_schemas/table.schema.json"
|
83
|
+
};
|
84
|
+
const tableYaml = collectionToYaml(collection, tableConfig);
|
85
|
+
console.log("📄 Table Format YAML:");
|
86
|
+
console.log(tableYaml);
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Example 3: Load and process YAML files with mixed terminologies
|
91
|
+
*/
|
92
|
+
export async function processYamlFiles(baseDir: string): Promise<void> {
|
93
|
+
console.log("📂 Processing YAML files with terminology support...");
|
94
|
+
|
95
|
+
const yamlLoader = createYamlLoader(baseDir);
|
96
|
+
|
97
|
+
// Load all YAML files from collections directory
|
98
|
+
const collectionsResult = await yamlLoader.loadDirectoryYamls("collections");
|
99
|
+
console.log(`📊 Collections Summary:`, collectionsResult.summary);
|
100
|
+
|
101
|
+
// Load all YAML files from tables directory
|
102
|
+
const tablesResult = await yamlLoader.loadDirectoryYamls("tables");
|
103
|
+
console.log(`📊 Tables Summary:`, tablesResult.summary);
|
104
|
+
|
105
|
+
// Process each file and show terminology detection
|
106
|
+
console.log("\\n🔍 File Analysis:");
|
107
|
+
[...collectionsResult.collections, ...tablesResult.collections].forEach(file => {
|
108
|
+
const terminology = file.originalTerminology;
|
109
|
+
const hasColumns = usesTableTerminology(file.data);
|
110
|
+
console.log(` ${file.filePath}: ${terminology} format (uses table terminology: ${hasColumns})`);
|
111
|
+
});
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Example 4: Migrate between terminologies
|
116
|
+
*/
|
117
|
+
export async function migrateTerminology(baseDir: string): Promise<void> {
|
118
|
+
console.log("🔄 Migrating between terminologies...");
|
119
|
+
|
120
|
+
const yamlLoader = createYamlLoader(baseDir);
|
121
|
+
|
122
|
+
// Migrate collections to table format
|
123
|
+
console.log("\\n📤 Migrating collections to table format...");
|
124
|
+
const collectionToTableResult = await yamlLoader.migrateTerminology(
|
125
|
+
"collections",
|
126
|
+
"migrated/tables",
|
127
|
+
true // to table terminology
|
128
|
+
);
|
129
|
+
console.log(`✅ Migration complete: ${collectionToTableResult.migrated} migrated, ${collectionToTableResult.skipped} skipped`);
|
130
|
+
if (collectionToTableResult.errors.length > 0) {
|
131
|
+
console.log(`❌ Errors:`, collectionToTableResult.errors);
|
132
|
+
}
|
133
|
+
|
134
|
+
// Migrate tables to collection format
|
135
|
+
console.log("\\n📤 Migrating tables to collection format...");
|
136
|
+
const tableToCollectionResult = await yamlLoader.migrateTerminology(
|
137
|
+
"tables",
|
138
|
+
"migrated/collections",
|
139
|
+
false // to collection terminology
|
140
|
+
);
|
141
|
+
console.log(`✅ Migration complete: ${tableToCollectionResult.migrated} migrated, ${tableToCollectionResult.skipped} skipped`);
|
142
|
+
if (tableToCollectionResult.errors.length > 0) {
|
143
|
+
console.log(`❌ Errors:`, tableToCollectionResult.errors);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Example 5: Validate terminology consistency
|
149
|
+
*/
|
150
|
+
export async function validateTerminology(baseDir: string): Promise<void> {
|
151
|
+
console.log("🔍 Validating terminology consistency...");
|
152
|
+
|
153
|
+
const yamlLoader = createYamlLoader(baseDir);
|
154
|
+
|
155
|
+
// Validate collections directory
|
156
|
+
const collectionsValidation = await yamlLoader.validateTerminologyConsistency("collections");
|
157
|
+
console.log("\\n📂 Collections Directory:");
|
158
|
+
console.log(` Consistent: ${collectionsValidation.isConsistent}`);
|
159
|
+
console.log(` Summary:`, collectionsValidation.summary);
|
160
|
+
if (collectionsValidation.issues.length > 0) {
|
161
|
+
console.log(` Issues:`);
|
162
|
+
collectionsValidation.issues.forEach(issue => {
|
163
|
+
console.log(` ${issue.severity.toUpperCase()}: ${issue.file} - ${issue.issue}`);
|
164
|
+
});
|
165
|
+
}
|
166
|
+
|
167
|
+
// Validate tables directory
|
168
|
+
const tablesValidation = await yamlLoader.validateTerminologyConsistency("tables");
|
169
|
+
console.log("\\n📂 Tables Directory:");
|
170
|
+
console.log(` Consistent: ${tablesValidation.isConsistent}`);
|
171
|
+
console.log(` Summary:`, tablesValidation.summary);
|
172
|
+
if (tablesValidation.issues.length > 0) {
|
173
|
+
console.log(` Issues:`);
|
174
|
+
tablesValidation.issues.forEach(issue => {
|
175
|
+
console.log(` ${issue.severity.toUpperCase()}: ${issue.file} - ${issue.issue}`);
|
176
|
+
});
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Example 6: Import configuration with terminology support
|
182
|
+
*/
|
183
|
+
export async function importConfigurationExample(appwriteFolderPath: string): Promise<void> {
|
184
|
+
console.log("📥 Import configuration with terminology support...");
|
185
|
+
|
186
|
+
const yamlImportIntegration = new YamlImportIntegration(appwriteFolderPath);
|
187
|
+
|
188
|
+
// Initialize YAML import system
|
189
|
+
await yamlImportIntegration.initialize();
|
190
|
+
|
191
|
+
// Create example import configurations for both formats
|
192
|
+
console.log("\\n📝 Creating import configuration templates...");
|
193
|
+
|
194
|
+
// Collection format import config
|
195
|
+
await yamlImportIntegration.createFromTemplate(
|
196
|
+
"Users",
|
197
|
+
"users.json",
|
198
|
+
false, // collection terminology
|
199
|
+
"users-collection-import.yaml"
|
200
|
+
);
|
201
|
+
|
202
|
+
// Table format import config
|
203
|
+
await yamlImportIntegration.createFromTemplate(
|
204
|
+
"Users",
|
205
|
+
"users.json",
|
206
|
+
true, // table terminology
|
207
|
+
"users-table-import.yaml"
|
208
|
+
);
|
209
|
+
|
210
|
+
// Get statistics
|
211
|
+
const stats = await yamlImportIntegration.getStatistics();
|
212
|
+
console.log("\\n📊 Import Configuration Statistics:");
|
213
|
+
console.log(` Total configurations: ${stats.totalConfigurations}`);
|
214
|
+
console.log(` Collections with configs: ${stats.collectionsWithConfigs}`);
|
215
|
+
console.log(` Total attribute mappings: ${stats.totalAttributeMappings}`);
|
216
|
+
console.log(` Total relationship mappings: ${stats.totalRelationshipMappings}`);
|
217
|
+
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Example 7: Manual terminology conversion
|
221
|
+
*/
|
222
|
+
export function manualTerminologyConversion(): void {
|
223
|
+
console.log("🔧 Manual terminology conversion example...");
|
224
|
+
|
225
|
+
// Sample YAML data with collection terminology
|
226
|
+
const collectionData: YamlCollectionData = {
|
227
|
+
name: "Product",
|
228
|
+
id: "product",
|
229
|
+
attributes: [
|
230
|
+
{
|
231
|
+
key: "name",
|
232
|
+
type: "string",
|
233
|
+
required: true,
|
234
|
+
relatedCollection: "Categories"
|
235
|
+
}
|
236
|
+
],
|
237
|
+
indexes: [
|
238
|
+
{
|
239
|
+
key: "name_index",
|
240
|
+
type: "key",
|
241
|
+
attributes: ["name"]
|
242
|
+
}
|
243
|
+
]
|
244
|
+
};
|
245
|
+
|
246
|
+
console.log("\\n📝 Original (Collection format):");
|
247
|
+
console.log(JSON.stringify(collectionData, null, 2));
|
248
|
+
|
249
|
+
// Convert to table terminology
|
250
|
+
const tableData = convertTerminology(collectionData, true);
|
251
|
+
console.log("\\n🔄 Converted to Table format:");
|
252
|
+
console.log(JSON.stringify(tableData, null, 2));
|
253
|
+
|
254
|
+
// Convert back to collection terminology
|
255
|
+
const normalizedData = normalizeYamlData(tableData);
|
256
|
+
console.log("\\n↩️ Normalized back to Collection format:");
|
257
|
+
console.log(JSON.stringify(normalizedData, null, 2));
|
258
|
+
|
259
|
+
// Terminology detection
|
260
|
+
console.log("\\n🔍 Terminology Detection:");
|
261
|
+
console.log(` Original uses table terminology: ${usesTableTerminology(collectionData)}`);
|
262
|
+
console.log(` Converted uses table terminology: ${usesTableTerminology(tableData)}`);
|
263
|
+
console.log(` Normalized uses table terminology: ${usesTableTerminology(normalizedData)}`);
|
264
|
+
}
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Main example runner
|
268
|
+
*/
|
269
|
+
export async function runYamlTerminologyExamples(outputDir: string): Promise<void> {
|
270
|
+
console.log("🎯 Running YAML Terminology Examples\\n");
|
271
|
+
|
272
|
+
try {
|
273
|
+
// Example collection for demonstrations
|
274
|
+
const exampleCollection: CollectionCreate = {
|
275
|
+
name: "Product",
|
276
|
+
$id: "product",
|
277
|
+
enabled: true,
|
278
|
+
documentSecurity: false,
|
279
|
+
$permissions: [],
|
280
|
+
attributes: [
|
281
|
+
{
|
282
|
+
key: "name",
|
283
|
+
type: "string",
|
284
|
+
required: true,
|
285
|
+
size: 255
|
286
|
+
},
|
287
|
+
{
|
288
|
+
key: "price",
|
289
|
+
type: "float",
|
290
|
+
required: true,
|
291
|
+
min: 0
|
292
|
+
},
|
293
|
+
{
|
294
|
+
key: "categoryId",
|
295
|
+
type: "relationship",
|
296
|
+
relationType: "manyToOne",
|
297
|
+
relatedCollection: "Categories",
|
298
|
+
twoWay: false,
|
299
|
+
onDelete: "setNull"
|
300
|
+
}
|
301
|
+
],
|
302
|
+
indexes: [
|
303
|
+
{
|
304
|
+
key: "name_index",
|
305
|
+
type: "key",
|
306
|
+
attributes: ["name"]
|
307
|
+
}
|
308
|
+
],
|
309
|
+
importDefs: []
|
310
|
+
};
|
311
|
+
|
312
|
+
// Run examples
|
313
|
+
await generateTemplateExamples(outputDir);
|
314
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
315
|
+
|
316
|
+
convertCollectionFormats(exampleCollection);
|
317
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
318
|
+
|
319
|
+
await processYamlFiles(outputDir);
|
320
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
321
|
+
|
322
|
+
await migrateTerminology(outputDir);
|
323
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
324
|
+
|
325
|
+
await validateTerminology(outputDir);
|
326
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
327
|
+
|
328
|
+
await importConfigurationExample(outputDir);
|
329
|
+
console.log("\\n" + "=".repeat(60) + "\\n");
|
330
|
+
|
331
|
+
manualTerminologyConversion();
|
332
|
+
|
333
|
+
console.log("\\n🎉 All examples completed successfully!");
|
334
|
+
|
335
|
+
} catch (error) {
|
336
|
+
console.error("❌ Error running examples:", error);
|
337
|
+
throw error;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
|
341
|
+
// Note: Functions are already exported above with their declarations
|
@@ -15,6 +15,7 @@ import {
|
|
15
15
|
updateFunctionSpecifications,
|
16
16
|
} from "./methods.js";
|
17
17
|
import ignore from "ignore";
|
18
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
18
19
|
|
19
20
|
const findFunctionDirectory = (
|
20
21
|
basePath: string,
|
@@ -57,7 +58,7 @@ export const deployFunction = async (
|
|
57
58
|
]
|
58
59
|
) => {
|
59
60
|
const functions = new Functions(client);
|
60
|
-
|
61
|
+
MessageFormatter.processing("Preparing function deployment...", { prefix: "Deployment" });
|
61
62
|
|
62
63
|
// Convert ignored patterns to lowercase for case-insensitive comparison
|
63
64
|
const ignoredLower = ignored.map((pattern) => pattern.toLowerCase());
|
@@ -74,7 +75,7 @@ export const deployFunction = async (
|
|
74
75
|
throw new Error(`${codePath} is not a directory`);
|
75
76
|
}
|
76
77
|
|
77
|
-
|
78
|
+
MessageFormatter.processing(`Creating tarball from ${codePath}`, { prefix: "Deployment" });
|
78
79
|
|
79
80
|
const progressBar = new cliProgress.SingleBar({
|
80
81
|
format:
|
@@ -105,7 +106,7 @@ export const deployFunction = async (
|
|
105
106
|
relativePath.includes(`\\${pattern}`)
|
106
107
|
)
|
107
108
|
) {
|
108
|
-
|
109
|
+
MessageFormatter.debug(`Ignoring ${path}`, undefined, { prefix: "Deployment" });
|
109
110
|
return false;
|
110
111
|
}
|
111
112
|
return true;
|
@@ -121,7 +122,7 @@ export const deployFunction = async (
|
|
121
122
|
);
|
122
123
|
|
123
124
|
try {
|
124
|
-
|
125
|
+
MessageFormatter.processing("Creating deployment...", { prefix: "Deployment" });
|
125
126
|
// Start with 1 as default total since we don't know the chunk size yet
|
126
127
|
progressBar.start(1, 0);
|
127
128
|
|
@@ -146,7 +147,7 @@ export const deployFunction = async (
|
|
146
147
|
if (chunks === total) {
|
147
148
|
progressBar.update(total);
|
148
149
|
progressBar.stop();
|
149
|
-
|
150
|
+
MessageFormatter.success("Upload complete!", { prefix: "Deployment" });
|
150
151
|
}
|
151
152
|
}
|
152
153
|
}
|
@@ -163,7 +164,7 @@ export const deployFunction = async (
|
|
163
164
|
return functionResponse;
|
164
165
|
} catch (error) {
|
165
166
|
progressBar.stop();
|
166
|
-
|
167
|
+
MessageFormatter.error("Deployment failed", error instanceof Error ? error : undefined, { prefix: "Deployment" });
|
167
168
|
throw error;
|
168
169
|
}
|
169
170
|
};
|
@@ -197,12 +198,12 @@ export const deployLocalFunction = async (
|
|
197
198
|
}
|
198
199
|
|
199
200
|
if (functionConfig.predeployCommands?.length) {
|
200
|
-
|
201
|
+
MessageFormatter.processing("Executing predeploy commands...", { prefix: "Deployment" });
|
201
202
|
const isWindows = platform() === "win32";
|
202
203
|
|
203
204
|
for (const command of functionConfig.predeployCommands) {
|
204
205
|
try {
|
205
|
-
|
206
|
+
MessageFormatter.debug(`Executing: ${command}`, undefined, { prefix: "Deployment" });
|
206
207
|
execSync(command, {
|
207
208
|
cwd: resolvedPath,
|
208
209
|
stdio: "inherit",
|
@@ -210,9 +211,10 @@ export const deployLocalFunction = async (
|
|
210
211
|
windowsHide: true,
|
211
212
|
});
|
212
213
|
} catch (error) {
|
213
|
-
|
214
|
-
|
215
|
-
error
|
214
|
+
MessageFormatter.error(
|
215
|
+
`Failed to execute predeploy command: ${command}`,
|
216
|
+
error instanceof Error ? error : undefined,
|
217
|
+
{ prefix: "Deployment" }
|
216
218
|
);
|
217
219
|
throw new Error(``);
|
218
220
|
}
|
@@ -223,7 +225,7 @@ export const deployLocalFunction = async (
|
|
223
225
|
if (!functionExists) {
|
224
226
|
await createFunction(client, functionConfig);
|
225
227
|
} else {
|
226
|
-
|
228
|
+
MessageFormatter.processing("Updating function...", { prefix: "Deployment" });
|
227
229
|
await updateFunction(client, functionConfig);
|
228
230
|
}
|
229
231
|
|
package/src/functions/methods.ts
CHANGED
@@ -16,6 +16,7 @@ import {
|
|
16
16
|
} from "appwrite-utils";
|
17
17
|
import chalk from "chalk";
|
18
18
|
import { extract as extractTar } from "tar";
|
19
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
19
20
|
|
20
21
|
/**
|
21
22
|
* Validates and filters events array for Appwrite functions
|
@@ -157,13 +158,13 @@ export const updateFunctionSpecifications = async (
|
|
157
158
|
error instanceof AppwriteException &&
|
158
159
|
error.message.includes("Invalid `specification`")
|
159
160
|
) {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
161
|
+
MessageFormatter.error(
|
162
|
+
"Error updating function specifications, please try setting the env variable `_FUNCTIONS_CPUS` and `_FUNCTIONS_RAM` to non-zero values",
|
163
|
+
undefined,
|
164
|
+
{ prefix: "Functions" }
|
164
165
|
);
|
165
166
|
} else {
|
166
|
-
|
167
|
+
MessageFormatter.error("Error updating function specifications", error instanceof Error ? error : undefined, { prefix: "Functions" });
|
167
168
|
throw error;
|
168
169
|
}
|
169
170
|
}
|
@@ -214,7 +215,7 @@ export const updateFunction = async (
|
|
214
215
|
};
|
215
216
|
|
216
217
|
export const createFunctionTemplate = async (
|
217
|
-
templateType: "typescript-node" | "uv" | "count-docs-in-collection",
|
218
|
+
templateType: "typescript-node" | "uv" | "count-docs-in-collection" | "hono-typescript",
|
218
219
|
functionName: string,
|
219
220
|
basePath: string = "./functions"
|
220
221
|
) => {
|
@@ -255,13 +256,12 @@ export const createFunctionTemplate = async (
|
|
255
256
|
|
256
257
|
try {
|
257
258
|
await copyTemplateFiles(templatesPath, functionPath);
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
)
|
259
|
+
MessageFormatter.success(
|
260
|
+
`Created ${templateType} function template at ${functionPath}`,
|
261
|
+
{ prefix: "Functions" }
|
262
262
|
);
|
263
263
|
} catch (error) {
|
264
|
-
|
264
|
+
MessageFormatter.error("Failed to create function template", error instanceof Error ? error : undefined, { prefix: "Functions" });
|
265
265
|
throw error;
|
266
266
|
}
|
267
267
|
|