appwrite-utils-cli 1.7.8 → 1.8.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +14 -199
  2. package/README.md +87 -30
  3. package/dist/adapters/AdapterFactory.js +5 -25
  4. package/dist/adapters/DatabaseAdapter.d.ts +17 -2
  5. package/dist/adapters/LegacyAdapter.d.ts +2 -1
  6. package/dist/adapters/LegacyAdapter.js +212 -16
  7. package/dist/adapters/TablesDBAdapter.d.ts +2 -12
  8. package/dist/adapters/TablesDBAdapter.js +261 -57
  9. package/dist/cli/commands/databaseCommands.js +10 -10
  10. package/dist/cli/commands/functionCommands.js +17 -8
  11. package/dist/collections/attributes.js +447 -125
  12. package/dist/collections/methods.js +197 -186
  13. package/dist/collections/tableOperations.d.ts +86 -0
  14. package/dist/collections/tableOperations.js +434 -0
  15. package/dist/collections/transferOperations.d.ts +3 -2
  16. package/dist/collections/transferOperations.js +93 -12
  17. package/dist/config/services/ConfigLoaderService.d.ts +7 -0
  18. package/dist/config/services/ConfigLoaderService.js +47 -1
  19. package/dist/config/yamlConfig.d.ts +221 -88
  20. package/dist/examples/yamlTerminologyExample.d.ts +1 -1
  21. package/dist/examples/yamlTerminologyExample.js +6 -3
  22. package/dist/functions/deployments.js +5 -23
  23. package/dist/functions/fnConfigDiscovery.d.ts +3 -0
  24. package/dist/functions/fnConfigDiscovery.js +108 -0
  25. package/dist/functions/methods.js +4 -2
  26. package/dist/functions/pathResolution.d.ts +37 -0
  27. package/dist/functions/pathResolution.js +185 -0
  28. package/dist/functions/templates/count-docs-in-collection/README.md +54 -0
  29. package/dist/functions/templates/count-docs-in-collection/package.json +25 -0
  30. package/dist/functions/templates/count-docs-in-collection/src/main.ts +159 -0
  31. package/dist/functions/templates/count-docs-in-collection/src/request.ts +9 -0
  32. package/dist/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
  33. package/dist/functions/templates/hono-typescript/README.md +286 -0
  34. package/dist/functions/templates/hono-typescript/package.json +26 -0
  35. package/dist/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
  36. package/dist/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
  37. package/dist/functions/templates/hono-typescript/src/app.ts +180 -0
  38. package/dist/functions/templates/hono-typescript/src/context.ts +103 -0
  39. package/dist/functions/templates/hono-typescript/src/index.ts +54 -0
  40. package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
  41. package/dist/functions/templates/hono-typescript/tsconfig.json +20 -0
  42. package/dist/functions/templates/typescript-node/README.md +32 -0
  43. package/dist/functions/templates/typescript-node/package.json +25 -0
  44. package/dist/functions/templates/typescript-node/src/context.ts +103 -0
  45. package/dist/functions/templates/typescript-node/src/index.ts +29 -0
  46. package/dist/functions/templates/typescript-node/tsconfig.json +28 -0
  47. package/dist/functions/templates/uv/README.md +31 -0
  48. package/dist/functions/templates/uv/pyproject.toml +30 -0
  49. package/dist/functions/templates/uv/src/__init__.py +0 -0
  50. package/dist/functions/templates/uv/src/context.py +125 -0
  51. package/dist/functions/templates/uv/src/index.py +46 -0
  52. package/dist/interactiveCLI.js +18 -15
  53. package/dist/main.js +219 -81
  54. package/dist/migrations/appwriteToX.d.ts +88 -23
  55. package/dist/migrations/comprehensiveTransfer.d.ts +2 -0
  56. package/dist/migrations/comprehensiveTransfer.js +83 -6
  57. package/dist/migrations/dataLoader.d.ts +227 -69
  58. package/dist/migrations/dataLoader.js +3 -3
  59. package/dist/migrations/importController.js +3 -3
  60. package/dist/migrations/relationships.d.ts +8 -2
  61. package/dist/migrations/services/ImportOrchestrator.js +3 -3
  62. package/dist/migrations/transfer.js +159 -37
  63. package/dist/shared/attributeMapper.d.ts +20 -0
  64. package/dist/shared/attributeMapper.js +203 -0
  65. package/dist/shared/selectionDialogs.d.ts +1 -1
  66. package/dist/shared/selectionDialogs.js +39 -11
  67. package/dist/storage/schemas.d.ts +354 -92
  68. package/dist/utils/configDiscovery.js +4 -3
  69. package/dist/utils/versionDetection.d.ts +0 -4
  70. package/dist/utils/versionDetection.js +41 -173
  71. package/dist/utils/yamlConverter.js +89 -16
  72. package/dist/utils/yamlLoader.d.ts +1 -1
  73. package/dist/utils/yamlLoader.js +6 -2
  74. package/dist/utilsController.d.ts +2 -1
  75. package/dist/utilsController.js +151 -22
  76. package/package.json +7 -5
  77. package/scripts/copy-templates.ts +23 -0
  78. package/src/adapters/AdapterFactory.ts +119 -143
  79. package/src/adapters/DatabaseAdapter.ts +18 -3
  80. package/src/adapters/LegacyAdapter.ts +236 -105
  81. package/src/adapters/TablesDBAdapter.ts +773 -643
  82. package/src/cli/commands/databaseCommands.ts +19 -19
  83. package/src/cli/commands/functionCommands.ts +23 -14
  84. package/src/collections/attributes.ts +2054 -1611
  85. package/src/collections/methods.ts +208 -293
  86. package/src/collections/tableOperations.ts +506 -0
  87. package/src/collections/transferOperations.ts +218 -144
  88. package/src/config/services/ConfigLoaderService.ts +62 -1
  89. package/src/examples/yamlTerminologyExample.ts +10 -5
  90. package/src/functions/deployments.ts +10 -35
  91. package/src/functions/fnConfigDiscovery.ts +103 -0
  92. package/src/functions/methods.ts +4 -2
  93. package/src/functions/pathResolution.ts +227 -0
  94. package/src/interactiveCLI.ts +25 -20
  95. package/src/main.ts +557 -202
  96. package/src/migrations/comprehensiveTransfer.ts +126 -50
  97. package/src/migrations/dataLoader.ts +3 -3
  98. package/src/migrations/importController.ts +3 -3
  99. package/src/migrations/services/ImportOrchestrator.ts +3 -3
  100. package/src/migrations/transfer.ts +148 -131
  101. package/src/shared/attributeMapper.ts +229 -0
  102. package/src/shared/selectionDialogs.ts +65 -32
  103. package/src/utils/configDiscovery.ts +9 -3
  104. package/src/utils/versionDetection.ts +74 -228
  105. package/src/utils/yamlConverter.ts +94 -17
  106. package/src/utils/yamlLoader.ts +11 -4
  107. package/src/utilsController.ts +202 -36
  108. package/dist/utils/schemaStrings.d.ts +0 -14
  109. package/dist/utils/schemaStrings.js +0 -428
  110. package/dist/utils/sessionPreservationExample.d.ts +0 -1666
  111. package/dist/utils/sessionPreservationExample.js +0 -101
@@ -26,15 +26,14 @@ export const databaseCommands = {
26
26
  // Get local collections for selection
27
27
  const localCollections = (cli as any).getLocalCollections();
28
28
 
29
- // Prompt about existing configuration
30
- const { syncExisting, modifyConfiguration } = await SelectionDialogs.promptForExistingConfig(configuredDatabases);
29
+ // Push operations always use local configuration as source of truth
31
30
 
32
31
  // Select databases
33
- const selectedDatabaseIds = await SelectionDialogs.selectDatabases(
34
- availableDatabases,
35
- configuredDatabases,
36
- { showSelectAll: true, allowNewOnly: !syncExisting }
37
- );
32
+ const selectedDatabaseIds = await SelectionDialogs.selectDatabases(
33
+ availableDatabases,
34
+ configuredDatabases,
35
+ { showSelectAll: false, allowNewOnly: false, defaultSelected: [] }
36
+ );
38
37
 
39
38
  if (selectedDatabaseIds.length === 0) {
40
39
  MessageFormatter.warning("No databases selected. Skipping database sync.", { prefix: "Database" });
@@ -54,7 +53,8 @@ export const databaseCommands = {
54
53
  (cli as any).controller!.database!,
55
54
  chalk.blue(`Select collections/tables to push to "${database.name}":`),
56
55
  true, // multiSelect
57
- true // prefer local
56
+ true, // prefer local
57
+ true // shouldFilterByDatabase
58
58
  );
59
59
 
60
60
  // Map selected collections to table IDs
@@ -93,12 +93,12 @@ export const databaseCommands = {
93
93
  MessageFormatter.warning("No storage buckets available in remote instance.", { prefix: "Database" });
94
94
  } else {
95
95
  // Select buckets using SelectionDialogs
96
- const selectedBucketIds = await SelectionDialogs.selectBucketsForDatabases(
97
- selectedDatabaseIds,
98
- availableBuckets,
99
- configuredBuckets,
100
- { showSelectAll: true, groupByDatabase: true }
101
- );
96
+ const selectedBucketIds = await SelectionDialogs.selectBucketsForDatabases(
97
+ selectedDatabaseIds,
98
+ availableBuckets,
99
+ configuredBuckets,
100
+ { showSelectAll: false, groupByDatabase: true, defaultSelected: [] }
101
+ );
102
102
 
103
103
  if (selectedBucketIds.length > 0) {
104
104
  // Create BucketSelection objects
@@ -133,16 +133,16 @@ export const databaseCommands = {
133
133
  bucketSelections
134
134
  );
135
135
 
136
- const confirmed = await SelectionDialogs.confirmSyncSelection(selectionSummary);
136
+ const confirmed = await SelectionDialogs.confirmSyncSelection(selectionSummary, 'push');
137
137
 
138
138
  if (!confirmed) {
139
- MessageFormatter.info("Sync operation cancelled by user", { prefix: "Database" });
139
+ MessageFormatter.info("Push operation cancelled by user", { prefix: "Database" });
140
140
  return;
141
141
  }
142
142
 
143
- // Perform selective sync using the controller
144
- MessageFormatter.progress("Starting selective sync...", { prefix: "Database" });
145
- await (cli as any).controller!.selectiveSync(databaseSelections, bucketSelections);
143
+ // Perform selective push using the controller
144
+ MessageFormatter.progress("Starting selective push...", { prefix: "Database" });
145
+ await (cli as any).controller!.selectivePush(databaseSelections, bucketSelections);
146
146
 
147
147
  MessageFormatter.success("\n✅ All database configurations pushed successfully!", { prefix: "Database" });
148
148
 
@@ -13,7 +13,8 @@ import {
13
13
  listFunctions,
14
14
  listSpecifications,
15
15
  } from "../../functions/methods.js";
16
- import { deployLocalFunction } from "../../functions/deployments.js";
16
+ import { deployLocalFunction } from "../../functions/deployments.js";
17
+ import { discoverFnConfigs, mergeDiscoveredFunctions } from "../../functions/fnConfigDiscovery.js";
17
18
  import { addFunctionToYamlConfig, findYamlConfig } from "../../config/yamlConfig.js";
18
19
  import { RuntimeSchema, type AppwriteFunction, type Runtime, type Specification } from "appwrite-utils";
19
20
  import type { InteractiveCLI } from "../../interactiveCLI.js";
@@ -137,11 +138,18 @@ export const functionCommands = {
137
138
  return;
138
139
  }
139
140
 
140
- const functions = await (cli as any).selectFunctions(
141
- "Select function(s) to deploy:",
142
- true,
143
- true
144
- );
141
+ // Discover local .fnconfig.yaml functions and merge into controller config
142
+ try {
143
+ const discovered = discoverFnConfigs((cli as any).currentDir);
144
+ const merged = mergeDiscoveredFunctions((cli as any).controller!.config!.functions || [], discovered);
145
+ (cli as any).controller!.config!.functions = merged as any;
146
+ } catch {}
147
+
148
+ const functions = await (cli as any).selectFunctions(
149
+ "Select function(s) to deploy:",
150
+ true,
151
+ true
152
+ );
145
153
 
146
154
  if (!functions?.length) {
147
155
  MessageFormatter.error("No function selected", undefined, { prefix: "Functions" });
@@ -177,18 +185,19 @@ export const functionCommands = {
177
185
  MessageFormatter.info(` Appwrite folder: ${(cli as any).controller.getAppwriteFolderPath()}`, { prefix: "Functions" });
178
186
  MessageFormatter.info(` Current working dir: ${process.cwd()}`, { prefix: "Functions" });
179
187
 
180
- // Helper function to expand tilde in paths
181
- const expandTildePath = (path: string): string => {
182
- if (path.startsWith('~/')) {
183
- return path.replace('~', os.homedir());
184
- }
185
- return path;
186
- };
188
+ // Resolve config dirPath relative to central YAML if it's relative
189
+ const yamlConfigPath = findYamlConfig((cli as any).currentDir);
190
+ const yamlBaseDir = yamlConfigPath ? require('node:path').dirname(yamlConfigPath) : process.cwd();
191
+ const expandTildePath = (p: string): string => (p?.startsWith('~/') ? p.replace('~', os.homedir()) : p);
187
192
 
188
193
  // Check locations in priority order:
189
194
  const priorityLocations = [
190
195
  // 1. Config dirPath if specified (with tilde expansion)
191
- functionConfig.dirPath ? expandTildePath(functionConfig.dirPath) : undefined,
196
+ functionConfig.dirPath
197
+ ? (require('node:path').isAbsolute(expandTildePath(functionConfig.dirPath))
198
+ ? expandTildePath(functionConfig.dirPath)
199
+ : require('node:path').resolve(yamlBaseDir, expandTildePath(functionConfig.dirPath)))
200
+ : undefined,
192
201
  // 2. Appwrite config folder/functions/name
193
202
  join(
194
203
  (cli as any).controller.getAppwriteFolderPath()!,