appwrite-utils-cli 1.11.0 → 1.12.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/{src/adapters/index.ts → dist/adapters/index.d.ts} +0 -1
- package/dist/adapters/index.js +10 -0
- 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 +210 -0
- package/dist/cli/commands/databaseCommands.d.ts +14 -0
- package/dist/cli/commands/databaseCommands.js +696 -0
- package/dist/cli/commands/functionCommands.d.ts +7 -0
- package/dist/cli/commands/functionCommands.js +330 -0
- package/dist/cli/commands/importFileCommands.d.ts +7 -0
- package/dist/cli/commands/importFileCommands.js +674 -0
- package/dist/cli/commands/schemaCommands.d.ts +7 -0
- package/dist/cli/commands/schemaCommands.js +169 -0
- package/dist/cli/commands/storageCommands.d.ts +5 -0
- package/dist/cli/commands/storageCommands.js +142 -0
- package/dist/cli/commands/transferCommands.d.ts +5 -0
- package/dist/cli/commands/transferCommands.js +382 -0
- package/dist/collections/columns.d.ts +13 -0
- package/dist/collections/columns.js +1339 -0
- package/dist/collections/indexes.d.ts +12 -0
- package/dist/collections/indexes.js +215 -0
- package/dist/collections/methods.d.ts +19 -0
- package/dist/collections/methods.js +605 -0
- package/dist/collections/tableOperations.d.ts +87 -0
- package/dist/collections/tableOperations.js +466 -0
- package/dist/collections/transferOperations.d.ts +8 -0
- package/dist/collections/transferOperations.js +411 -0
- package/dist/collections/wipeOperations.d.ts +17 -0
- package/dist/collections/wipeOperations.js +306 -0
- package/dist/databases/methods.d.ts +6 -0
- package/dist/databases/methods.js +35 -0
- package/dist/databases/setup.d.ts +5 -0
- package/dist/databases/setup.js +45 -0
- package/dist/examples/yamlTerminologyExample.d.ts +42 -0
- package/dist/examples/yamlTerminologyExample.js +272 -0
- package/dist/functions/deployments.d.ts +4 -0
- package/dist/functions/deployments.js +146 -0
- package/dist/functions/fnConfigDiscovery.d.ts +3 -0
- package/dist/functions/fnConfigDiscovery.js +108 -0
- package/dist/functions/methods.d.ts +16 -0
- package/dist/functions/methods.js +174 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +57 -0
- package/dist/interactiveCLI.d.ts +36 -0
- package/dist/interactiveCLI.js +952 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +1125 -0
- package/dist/migrations/afterImportActions.d.ts +17 -0
- package/dist/migrations/afterImportActions.js +305 -0
- package/dist/migrations/appwriteToX.d.ts +211 -0
- package/dist/migrations/appwriteToX.js +493 -0
- package/dist/migrations/comprehensiveTransfer.d.ts +147 -0
- package/dist/migrations/comprehensiveTransfer.js +1315 -0
- package/dist/migrations/dataLoader.d.ts +755 -0
- package/dist/migrations/dataLoader.js +1272 -0
- package/dist/migrations/importController.d.ts +25 -0
- package/dist/migrations/importController.js +283 -0
- package/dist/migrations/importDataActions.d.ts +50 -0
- package/dist/migrations/importDataActions.js +230 -0
- package/dist/migrations/relationships.d.ts +29 -0
- package/dist/migrations/relationships.js +203 -0
- package/dist/migrations/services/DataTransformationService.d.ts +55 -0
- package/dist/migrations/services/DataTransformationService.js +158 -0
- package/dist/migrations/services/FileHandlerService.d.ts +75 -0
- package/dist/migrations/services/FileHandlerService.js +236 -0
- package/dist/migrations/services/ImportOrchestrator.d.ts +99 -0
- package/dist/migrations/services/ImportOrchestrator.js +493 -0
- package/dist/migrations/services/RateLimitManager.d.ts +138 -0
- package/dist/migrations/services/RateLimitManager.js +279 -0
- package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
- package/dist/migrations/services/RelationshipResolver.js +332 -0
- package/dist/migrations/services/UserMappingService.d.ts +109 -0
- package/dist/migrations/services/UserMappingService.js +277 -0
- package/dist/migrations/services/ValidationService.d.ts +74 -0
- package/dist/migrations/services/ValidationService.js +260 -0
- package/dist/migrations/transfer.d.ts +30 -0
- package/dist/migrations/transfer.js +661 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +131 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.js +383 -0
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +93 -0
- package/dist/migrations/yaml/YamlImportIntegration.js +341 -0
- package/dist/migrations/yaml/generateImportSchemas.d.ts +30 -0
- package/dist/migrations/yaml/generateImportSchemas.js +1327 -0
- package/dist/schemas/authUser.d.ts +24 -0
- package/dist/schemas/authUser.js +17 -0
- package/dist/setup.d.ts +2 -0
- package/{src/setup.ts → dist/setup.js} +0 -3
- package/dist/setupCommands.d.ts +58 -0
- package/dist/setupCommands.js +489 -0
- package/dist/setupController.d.ts +9 -0
- package/dist/setupController.js +34 -0
- 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.d.ts +75 -0
- package/dist/shared/confirmationDialogs.js +236 -0
- package/dist/shared/migrationHelpers.d.ts +61 -0
- package/dist/shared/migrationHelpers.js +145 -0
- package/{src/shared/operationLogger.ts → dist/shared/operationLogger.d.ts} +1 -11
- package/dist/shared/operationLogger.js +12 -0
- package/dist/shared/operationQueue.d.ts +40 -0
- package/dist/shared/operationQueue.js +310 -0
- package/dist/shared/operationsTable.d.ts +26 -0
- package/dist/shared/operationsTable.js +287 -0
- package/dist/shared/operationsTableSchema.d.ts +48 -0
- package/dist/shared/operationsTableSchema.js +35 -0
- package/dist/shared/progressManager.d.ts +62 -0
- package/dist/shared/progressManager.js +215 -0
- package/dist/shared/relationshipExtractor.d.ts +56 -0
- package/dist/shared/relationshipExtractor.js +138 -0
- package/dist/shared/selectionDialogs.d.ts +220 -0
- package/dist/shared/selectionDialogs.js +588 -0
- package/dist/storage/backupCompression.d.ts +20 -0
- package/dist/storage/backupCompression.js +67 -0
- package/dist/storage/methods.d.ts +44 -0
- package/dist/storage/methods.js +475 -0
- package/dist/storage/schemas.d.ts +842 -0
- package/dist/storage/schemas.js +175 -0
- package/dist/tables/indexManager.d.ts +65 -0
- package/dist/tables/indexManager.js +294 -0
- package/{src/types.ts → dist/types.d.ts} +1 -6
- package/dist/types.js +3 -0
- package/dist/users/methods.d.ts +16 -0
- package/dist/users/methods.js +276 -0
- package/dist/utils/configMigration.d.ts +1 -0
- package/dist/utils/configMigration.js +261 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/loadConfigs.d.ts +50 -0
- package/dist/utils/loadConfigs.js +357 -0
- package/dist/utils/setupFiles.d.ts +4 -0
- package/dist/utils/setupFiles.js +1190 -0
- package/dist/utilsController.d.ts +114 -0
- package/dist/utilsController.js +898 -0
- package/package.json +6 -3
- package/CHANGELOG.md +0 -35
- package/CONFIG_TODO.md +0 -1189
- package/SELECTION_DIALOGS.md +0 -146
- package/SERVICE_IMPLEMENTATION_REPORT.md +0 -462
- package/scripts/copy-templates.ts +0 -23
- package/src/backups/operations/bucketBackup.ts +0 -277
- package/src/backups/operations/collectionBackup.ts +0 -310
- package/src/backups/operations/comprehensiveBackup.ts +0 -342
- package/src/backups/schemas/bucketManifest.ts +0 -78
- package/src/backups/schemas/comprehensiveManifest.ts +0 -76
- package/src/backups/tracking/centralizedTracking.ts +0 -352
- package/src/cli/commands/configCommands.ts +0 -265
- package/src/cli/commands/databaseCommands.ts +0 -931
- package/src/cli/commands/functionCommands.ts +0 -419
- package/src/cli/commands/importFileCommands.ts +0 -815
- package/src/cli/commands/schemaCommands.ts +0 -200
- package/src/cli/commands/storageCommands.ts +0 -151
- package/src/cli/commands/transferCommands.ts +0 -454
- package/src/collections/attributes.ts.backup +0 -1555
- package/src/collections/columns.ts +0 -2025
- package/src/collections/indexes.ts +0 -350
- package/src/collections/methods.ts +0 -714
- package/src/collections/tableOperations.ts +0 -542
- package/src/collections/transferOperations.ts +0 -589
- package/src/collections/wipeOperations.ts +0 -449
- package/src/databases/methods.ts +0 -49
- package/src/databases/setup.ts +0 -77
- package/src/examples/yamlTerminologyExample.ts +0 -346
- package/src/functions/deployments.ts +0 -221
- package/src/functions/fnConfigDiscovery.ts +0 -103
- package/src/functions/methods.ts +0 -284
- package/src/init.ts +0 -62
- package/src/interactiveCLI.ts +0 -1201
- package/src/main.ts +0 -1517
- package/src/migrations/afterImportActions.ts +0 -579
- package/src/migrations/appwriteToX.ts +0 -668
- package/src/migrations/comprehensiveTransfer.ts +0 -2285
- package/src/migrations/dataLoader.ts +0 -1729
- package/src/migrations/importController.ts +0 -440
- package/src/migrations/importDataActions.ts +0 -315
- package/src/migrations/relationships.ts +0 -333
- package/src/migrations/services/DataTransformationService.ts +0 -196
- package/src/migrations/services/FileHandlerService.ts +0 -311
- package/src/migrations/services/ImportOrchestrator.ts +0 -675
- package/src/migrations/services/RateLimitManager.ts +0 -363
- package/src/migrations/services/RelationshipResolver.ts +0 -461
- package/src/migrations/services/UserMappingService.ts +0 -345
- package/src/migrations/services/ValidationService.ts +0 -349
- package/src/migrations/transfer.ts +0 -1113
- package/src/migrations/yaml/YamlImportConfigLoader.ts +0 -439
- package/src/migrations/yaml/YamlImportIntegration.ts +0 -446
- package/src/migrations/yaml/generateImportSchemas.ts +0 -1354
- package/src/schemas/authUser.ts +0 -23
- package/src/setupCommands.ts +0 -602
- package/src/setupController.ts +0 -43
- package/src/shared/backupMetadataSchema.ts +0 -93
- package/src/shared/backupTracking.ts +0 -211
- package/src/shared/confirmationDialogs.ts +0 -327
- package/src/shared/migrationHelpers.ts +0 -232
- package/src/shared/operationQueue.ts +0 -376
- package/src/shared/operationsTable.ts +0 -338
- package/src/shared/operationsTableSchema.ts +0 -60
- package/src/shared/progressManager.ts +0 -278
- package/src/shared/relationshipExtractor.ts +0 -214
- package/src/shared/selectionDialogs.ts +0 -802
- package/src/storage/backupCompression.ts +0 -88
- package/src/storage/methods.ts +0 -711
- package/src/storage/schemas.ts +0 -205
- package/src/tables/indexManager.ts +0 -409
- package/src/types/node-appwrite-tablesdb.d.ts +0 -44
- package/src/users/methods.ts +0 -358
- package/src/utils/configMigration.ts +0 -348
- package/src/utils/loadConfigs.ts +0 -457
- package/src/utils/setupFiles.ts +0 -1236
- package/src/utilsController.ts +0 -1263
- package/tests/README.md +0 -497
- package/tests/adapters/AdapterFactory.test.ts +0 -277
- package/tests/integration/syncOperations.test.ts +0 -463
- package/tests/jest.config.js +0 -25
- package/tests/migration/configMigration.test.ts +0 -546
- package/tests/setup.ts +0 -62
- package/tests/testUtils.ts +0 -340
- package/tests/utils/loadConfigs.test.ts +0 -350
- package/tests/validation/configValidation.test.ts +0 -412
- package/tsconfig.json +0 -44
- /package/{src → dist}/functions/templates/count-docs-in-collection/README.md +0 -0
- /package/{src → dist}/functions/templates/count-docs-in-collection/src/main.ts +0 -0
- /package/{src → dist}/functions/templates/count-docs-in-collection/src/request.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/README.md +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/adapters/request.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/adapters/response.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/app.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/context.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/main.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -0
- /package/{src → dist}/functions/templates/typescript-node/README.md +0 -0
- /package/{src → dist}/functions/templates/typescript-node/src/context.ts +0 -0
- /package/{src → dist}/functions/templates/typescript-node/src/main.ts +0 -0
- /package/{src → dist}/functions/templates/uv/README.md +0 -0
- /package/{src → dist}/functions/templates/uv/pyproject.toml +0 -0
- /package/{src → dist}/functions/templates/uv/src/__init__.py +0 -0
- /package/{src → dist}/functions/templates/uv/src/context.py +0 -0
- /package/{src → dist}/functions/templates/uv/src/main.py +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { AppwriteException, Client, Functions, Query, Runtime, } from "node-appwrite";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { EventTypeSchema, } from "appwrite-utils";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { extract as extractTar } from "tar";
|
|
8
|
+
import { MessageFormatter } from "appwrite-utils-helpers";
|
|
9
|
+
import { expandTildePath, normalizeFunctionName } from 'appwrite-utils-helpers';
|
|
10
|
+
/**
|
|
11
|
+
* Validates and filters events array for Appwrite functions
|
|
12
|
+
* - Filters out empty/invalid strings
|
|
13
|
+
* - Validates against EventTypeSchema
|
|
14
|
+
* - Limits to 100 items maximum (Appwrite limit)
|
|
15
|
+
* - Returns empty array if input is invalid
|
|
16
|
+
*/
|
|
17
|
+
const validateEvents = (events) => {
|
|
18
|
+
if (!events || !Array.isArray(events))
|
|
19
|
+
return [];
|
|
20
|
+
return events
|
|
21
|
+
.filter(event => {
|
|
22
|
+
if (!event || typeof event !== 'string' || event.trim().length === 0) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// Validate against EventTypeSchema
|
|
26
|
+
const result = EventTypeSchema.safeParse(event);
|
|
27
|
+
if (!result.success) {
|
|
28
|
+
MessageFormatter.warning(`Invalid event type "${event}" will be filtered out`, { prefix: "Functions" });
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
})
|
|
33
|
+
.slice(0, 100);
|
|
34
|
+
};
|
|
35
|
+
export const listFunctions = async (client, queries, search) => {
|
|
36
|
+
const functions = new Functions(client);
|
|
37
|
+
const functionsList = await functions.list(queries, search);
|
|
38
|
+
return functionsList;
|
|
39
|
+
};
|
|
40
|
+
export const getFunction = async (client, functionId) => {
|
|
41
|
+
const functions = new Functions(client);
|
|
42
|
+
const functionResponse = await functions.get(functionId);
|
|
43
|
+
return functionResponse;
|
|
44
|
+
};
|
|
45
|
+
export const downloadLatestFunctionDeployment = async (client, functionId, basePath = process.cwd()) => {
|
|
46
|
+
const functions = new Functions(client);
|
|
47
|
+
const functionInfo = await getFunction(client, functionId);
|
|
48
|
+
const functionDeployments = await functions.listDeployments(functionId, [
|
|
49
|
+
Query.orderDesc("$createdAt"),
|
|
50
|
+
]);
|
|
51
|
+
if (functionDeployments.deployments.length === 0) {
|
|
52
|
+
throw new Error("No deployments found for function");
|
|
53
|
+
}
|
|
54
|
+
const latestDeployment = functionDeployments.deployments[0];
|
|
55
|
+
const deploymentData = await functions.getDeploymentDownload(functionId, latestDeployment.$id);
|
|
56
|
+
// Create function directory using provided basePath
|
|
57
|
+
const functionDir = join(basePath, normalizeFunctionName(functionInfo.name));
|
|
58
|
+
await fs.promises.mkdir(functionDir, { recursive: true });
|
|
59
|
+
// Create temporary file for tar extraction
|
|
60
|
+
const tarPath = join(functionDir, "temp.tar.gz");
|
|
61
|
+
const uint8Array = new Uint8Array(deploymentData);
|
|
62
|
+
await fs.promises.writeFile(tarPath, uint8Array);
|
|
63
|
+
try {
|
|
64
|
+
// Extract tar file
|
|
65
|
+
extractTar({
|
|
66
|
+
C: functionDir,
|
|
67
|
+
file: tarPath,
|
|
68
|
+
sync: true,
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
path: functionDir,
|
|
72
|
+
function: functionInfo,
|
|
73
|
+
deployment: latestDeployment,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
// Clean up tar file
|
|
78
|
+
await fs.promises.unlink(tarPath).catch(() => { });
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
export const deleteFunction = async (client, functionId) => {
|
|
82
|
+
const functions = new Functions(client);
|
|
83
|
+
const functionResponse = await functions.delete(functionId);
|
|
84
|
+
return functionResponse;
|
|
85
|
+
};
|
|
86
|
+
export const createFunction = async (client, functionConfig) => {
|
|
87
|
+
const functions = new Functions(client);
|
|
88
|
+
const functionResponse = await functions.create(functionConfig.$id, functionConfig.name, functionConfig.runtime, functionConfig.execute, validateEvents(functionConfig.events), functionConfig.schedule, functionConfig.timeout, functionConfig.enabled, functionConfig.logging, functionConfig.entrypoint, functionConfig.commands, functionConfig.scopes, functionConfig.installationId, functionConfig.providerRepositoryId, functionConfig.providerBranch, functionConfig.providerSilentMode, functionConfig.providerRootDirectory);
|
|
89
|
+
return functionResponse;
|
|
90
|
+
};
|
|
91
|
+
export const updateFunctionSpecifications = async (client, functionId, specification) => {
|
|
92
|
+
const curFunction = await listFunctions(client, [
|
|
93
|
+
Query.equal("$id", functionId),
|
|
94
|
+
]);
|
|
95
|
+
if (curFunction.functions.length === 0) {
|
|
96
|
+
throw new Error("Function not found");
|
|
97
|
+
}
|
|
98
|
+
const functionFound = curFunction.functions[0];
|
|
99
|
+
try {
|
|
100
|
+
const functionResponse = await updateFunction(client, {
|
|
101
|
+
...functionFound,
|
|
102
|
+
runtime: functionFound.runtime,
|
|
103
|
+
scopes: functionFound.scopes,
|
|
104
|
+
specification: specification,
|
|
105
|
+
});
|
|
106
|
+
return functionResponse;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (error instanceof AppwriteException &&
|
|
110
|
+
error.message.includes("Invalid `specification`")) {
|
|
111
|
+
MessageFormatter.error("Error updating function specifications, please try setting the env variable `_FUNCTIONS_CPUS` and `_FUNCTIONS_RAM` to non-zero values", undefined, { prefix: "Functions" });
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
MessageFormatter.error("Error updating function specifications", error instanceof Error ? error : undefined, { prefix: "Functions" });
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
export const listSpecifications = async (client) => {
|
|
120
|
+
const functions = new Functions(client);
|
|
121
|
+
const specifications = await functions.listSpecifications();
|
|
122
|
+
return specifications;
|
|
123
|
+
};
|
|
124
|
+
export const listFunctionDeployments = async (client, functionId, queries) => {
|
|
125
|
+
const functions = new Functions(client);
|
|
126
|
+
const deployments = await functions.listDeployments(functionId, queries);
|
|
127
|
+
return deployments;
|
|
128
|
+
};
|
|
129
|
+
export const updateFunction = async (client, functionConfig) => {
|
|
130
|
+
const functions = new Functions(client);
|
|
131
|
+
const functionResponse = await functions.update(functionConfig.$id, functionConfig.name, functionConfig.runtime, functionConfig.execute, validateEvents(functionConfig.events), functionConfig.schedule, functionConfig.timeout, functionConfig.enabled, functionConfig.logging, functionConfig.entrypoint, functionConfig.commands, functionConfig.scopes, functionConfig.installationId, functionConfig.providerRepositoryId, functionConfig.providerBranch, functionConfig.providerSilentMode, functionConfig.providerRootDirectory, functionConfig.specification);
|
|
132
|
+
return functionResponse;
|
|
133
|
+
};
|
|
134
|
+
export const createFunctionTemplate = async (templateType, functionName, basePath = "./functions") => {
|
|
135
|
+
const expandedBasePath = expandTildePath(basePath);
|
|
136
|
+
const functionPath = join(expandedBasePath, functionName);
|
|
137
|
+
const currentFileUrl = import.meta.url;
|
|
138
|
+
const currentDir = dirname(fileURLToPath(currentFileUrl));
|
|
139
|
+
const templatesPath = join(currentDir, "templates", templateType);
|
|
140
|
+
// Create function directory
|
|
141
|
+
await fs.promises.mkdir(functionPath, { recursive: true });
|
|
142
|
+
// Copy template files recursively
|
|
143
|
+
const copyTemplateFiles = async (sourcePath, targetPath) => {
|
|
144
|
+
const entries = await fs.promises.readdir(sourcePath, {
|
|
145
|
+
withFileTypes: true,
|
|
146
|
+
});
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
const srcPath = join(sourcePath, entry.name);
|
|
149
|
+
const destPath = join(targetPath, entry.name);
|
|
150
|
+
if (entry.isDirectory()) {
|
|
151
|
+
await fs.promises.mkdir(destPath, { recursive: true });
|
|
152
|
+
await copyTemplateFiles(srcPath, destPath);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
let content = await fs.promises.readFile(srcPath, "utf-8");
|
|
156
|
+
// Replace template variables
|
|
157
|
+
content = content
|
|
158
|
+
.replace(/\{\{functionName\}\}/g, functionName)
|
|
159
|
+
.replace(/\{\{databaseId\}\}/g, "{{databaseId}}")
|
|
160
|
+
.replace(/\{\{collectionId\}\}/g, "{{collectionId}}");
|
|
161
|
+
await fs.promises.writeFile(destPath, content);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
try {
|
|
166
|
+
await copyTemplateFiles(templatesPath, functionPath);
|
|
167
|
+
MessageFormatter.success(`Created ${templateType} function template at ${functionPath}`, { prefix: "Functions" });
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
MessageFormatter.error("Failed to create function template", error instanceof Error ? error : undefined, { prefix: "Functions" });
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
return functionPath;
|
|
174
|
+
};
|
package/dist/init.d.ts
ADDED
package/dist/init.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import { createEmptyCollection, setupDirsFiles } from "./utils/setupFiles.js";
|
|
4
|
+
import { MessageFormatter } from "appwrite-utils-helpers";
|
|
5
|
+
MessageFormatter.banner("Appwrite Utils CLI Tool by Zach Handley", "For more information, visit https://github.com/zachhandley/appwrite-utils");
|
|
6
|
+
async function main() {
|
|
7
|
+
const answers = await inquirer.prompt([
|
|
8
|
+
{
|
|
9
|
+
type: "list",
|
|
10
|
+
name: "action",
|
|
11
|
+
message: "What would you like to do?",
|
|
12
|
+
choices: [
|
|
13
|
+
"Create collection config file",
|
|
14
|
+
"Create function (not available)",
|
|
15
|
+
"Setup directories and files",
|
|
16
|
+
"Setup directories and files with example data",
|
|
17
|
+
"Exit",
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
switch (answers.action) {
|
|
22
|
+
case "Create collection config file":
|
|
23
|
+
const { collectionName } = await inquirer.prompt([
|
|
24
|
+
{
|
|
25
|
+
type: "input",
|
|
26
|
+
name: "collectionName",
|
|
27
|
+
message: "Enter the name of the collection:",
|
|
28
|
+
validate: (input) => input.trim() !== "" || "Collection name cannot be empty.",
|
|
29
|
+
},
|
|
30
|
+
]);
|
|
31
|
+
MessageFormatter.progress(`Creating collection config file for '${collectionName}'...`, { prefix: "Init" });
|
|
32
|
+
createEmptyCollection(collectionName);
|
|
33
|
+
break;
|
|
34
|
+
case "Create function (not available)":
|
|
35
|
+
MessageFormatter.warning("This feature is not available yet.", { prefix: "Init" });
|
|
36
|
+
break;
|
|
37
|
+
case "Setup directories and files":
|
|
38
|
+
MessageFormatter.progress("Setting up directories and files...", { prefix: "Init" });
|
|
39
|
+
setupDirsFiles(false); // Assuming false means no example data
|
|
40
|
+
break;
|
|
41
|
+
case "Setup directories and files with example data":
|
|
42
|
+
MessageFormatter.progress("Setting up directories and files with example data...", { prefix: "Init" });
|
|
43
|
+
setupDirsFiles(true); // Assuming false means no example data
|
|
44
|
+
break;
|
|
45
|
+
case "Exit":
|
|
46
|
+
MessageFormatter.info("Exiting...", { prefix: "Init" });
|
|
47
|
+
process.exit(0);
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
MessageFormatter.warning("Invalid option, please try again.", { prefix: "Init" });
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
main().catch((error) => {
|
|
55
|
+
MessageFormatter.error("An error occurred", error instanceof Error ? error : new Error(String(error)), { prefix: "Init" });
|
|
56
|
+
process.exit(1);
|
|
57
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface InteractiveCLIOptions {
|
|
2
|
+
useSession?: boolean;
|
|
3
|
+
sessionCookie?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class InteractiveCLI {
|
|
6
|
+
private currentDir;
|
|
7
|
+
private controller;
|
|
8
|
+
private isUsingTypeScriptConfig;
|
|
9
|
+
private lastSelectedCollectionIds;
|
|
10
|
+
private options;
|
|
11
|
+
constructor(currentDir: string, options?: InteractiveCLIOptions);
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
private initControllerIfNeeded;
|
|
14
|
+
private manageBuckets;
|
|
15
|
+
private selectDatabases;
|
|
16
|
+
private selectCollections;
|
|
17
|
+
/**
|
|
18
|
+
* Enhanced collection/table selection with better guidance for mixed scenarios
|
|
19
|
+
*/
|
|
20
|
+
private selectCollectionsAndTables;
|
|
21
|
+
private getTemplateDefaults;
|
|
22
|
+
private findFunctionInSubdirectories;
|
|
23
|
+
private selectFunctions;
|
|
24
|
+
private getLocalFunctions;
|
|
25
|
+
private selectBuckets;
|
|
26
|
+
private configureBuckets;
|
|
27
|
+
private createNewBucket;
|
|
28
|
+
private getLocalCollections;
|
|
29
|
+
private getLocalDatabases;
|
|
30
|
+
/**
|
|
31
|
+
* Extract session information from current controller for preservation
|
|
32
|
+
*/
|
|
33
|
+
private extractSessionFromController;
|
|
34
|
+
private detectConfigurationType;
|
|
35
|
+
private buildChoicesList;
|
|
36
|
+
}
|