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.
Files changed (233) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/README.md +251 -29
  3. package/dist/adapters/AdapterFactory.d.ts +10 -3
  4. package/dist/adapters/AdapterFactory.js +213 -17
  5. package/dist/adapters/TablesDBAdapter.js +60 -17
  6. package/dist/backups/operations/bucketBackup.d.ts +19 -0
  7. package/dist/backups/operations/bucketBackup.js +197 -0
  8. package/dist/backups/operations/collectionBackup.d.ts +30 -0
  9. package/dist/backups/operations/collectionBackup.js +201 -0
  10. package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
  11. package/dist/backups/operations/comprehensiveBackup.js +238 -0
  12. package/dist/backups/schemas/bucketManifest.d.ts +93 -0
  13. package/dist/backups/schemas/bucketManifest.js +33 -0
  14. package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
  15. package/dist/backups/schemas/comprehensiveManifest.js +32 -0
  16. package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
  17. package/dist/backups/tracking/centralizedTracking.js +274 -0
  18. package/dist/cli/commands/configCommands.d.ts +8 -0
  19. package/dist/cli/commands/configCommands.js +160 -0
  20. package/dist/cli/commands/databaseCommands.d.ts +13 -0
  21. package/dist/cli/commands/databaseCommands.js +479 -0
  22. package/dist/cli/commands/functionCommands.d.ts +7 -0
  23. package/dist/cli/commands/functionCommands.js +289 -0
  24. package/dist/cli/commands/schemaCommands.d.ts +7 -0
  25. package/dist/cli/commands/schemaCommands.js +134 -0
  26. package/dist/cli/commands/transferCommands.d.ts +5 -0
  27. package/dist/cli/commands/transferCommands.js +384 -0
  28. package/dist/collections/attributes.d.ts +5 -4
  29. package/dist/collections/attributes.js +539 -246
  30. package/dist/collections/indexes.js +39 -37
  31. package/dist/collections/methods.d.ts +2 -16
  32. package/dist/collections/methods.js +90 -538
  33. package/dist/collections/transferOperations.d.ts +7 -0
  34. package/dist/collections/transferOperations.js +331 -0
  35. package/dist/collections/wipeOperations.d.ts +16 -0
  36. package/dist/collections/wipeOperations.js +328 -0
  37. package/dist/config/configMigration.d.ts +87 -0
  38. package/dist/config/configMigration.js +390 -0
  39. package/dist/config/configValidation.d.ts +66 -0
  40. package/dist/config/configValidation.js +358 -0
  41. package/dist/config/yamlConfig.d.ts +455 -1
  42. package/dist/config/yamlConfig.js +145 -52
  43. package/dist/databases/methods.js +3 -2
  44. package/dist/databases/setup.d.ts +1 -2
  45. package/dist/databases/setup.js +9 -87
  46. package/dist/examples/yamlTerminologyExample.d.ts +42 -0
  47. package/dist/examples/yamlTerminologyExample.js +269 -0
  48. package/dist/functions/deployments.js +11 -10
  49. package/dist/functions/methods.d.ts +1 -1
  50. package/dist/functions/methods.js +5 -4
  51. package/dist/init.js +9 -9
  52. package/dist/interactiveCLI.d.ts +8 -17
  53. package/dist/interactiveCLI.js +209 -1172
  54. package/dist/main.js +364 -21
  55. package/dist/migrations/afterImportActions.js +22 -30
  56. package/dist/migrations/appwriteToX.js +71 -25
  57. package/dist/migrations/dataLoader.js +35 -26
  58. package/dist/migrations/importController.js +29 -30
  59. package/dist/migrations/relationships.js +13 -12
  60. package/dist/migrations/services/ImportOrchestrator.js +16 -19
  61. package/dist/migrations/transfer.js +46 -46
  62. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +3 -1
  63. package/dist/migrations/yaml/YamlImportConfigLoader.js +6 -3
  64. package/dist/migrations/yaml/YamlImportIntegration.d.ts +9 -3
  65. package/dist/migrations/yaml/YamlImportIntegration.js +22 -11
  66. package/dist/migrations/yaml/generateImportSchemas.d.ts +14 -1
  67. package/dist/migrations/yaml/generateImportSchemas.js +736 -7
  68. package/dist/schemas/authUser.d.ts +1 -1
  69. package/dist/setupController.js +3 -2
  70. package/dist/shared/backupMetadataSchema.d.ts +94 -0
  71. package/dist/shared/backupMetadataSchema.js +38 -0
  72. package/dist/shared/backupTracking.d.ts +18 -0
  73. package/dist/shared/backupTracking.js +176 -0
  74. package/dist/shared/confirmationDialogs.js +15 -15
  75. package/dist/shared/errorUtils.d.ts +54 -0
  76. package/dist/shared/errorUtils.js +95 -0
  77. package/dist/shared/functionManager.js +20 -19
  78. package/dist/shared/indexManager.js +12 -11
  79. package/dist/shared/jsonSchemaGenerator.js +10 -26
  80. package/dist/shared/logging.d.ts +51 -0
  81. package/dist/shared/logging.js +70 -0
  82. package/dist/shared/messageFormatter.d.ts +2 -0
  83. package/dist/shared/messageFormatter.js +10 -0
  84. package/dist/shared/migrationHelpers.d.ts +6 -16
  85. package/dist/shared/migrationHelpers.js +24 -21
  86. package/dist/shared/operationLogger.d.ts +8 -1
  87. package/dist/shared/operationLogger.js +11 -24
  88. package/dist/shared/operationQueue.d.ts +28 -1
  89. package/dist/shared/operationQueue.js +268 -66
  90. package/dist/shared/operationsTable.d.ts +26 -0
  91. package/dist/shared/operationsTable.js +286 -0
  92. package/dist/shared/operationsTableSchema.d.ts +48 -0
  93. package/dist/shared/operationsTableSchema.js +35 -0
  94. package/dist/shared/relationshipExtractor.d.ts +56 -0
  95. package/dist/shared/relationshipExtractor.js +138 -0
  96. package/dist/shared/schemaGenerator.d.ts +19 -1
  97. package/dist/shared/schemaGenerator.js +56 -75
  98. package/dist/storage/backupCompression.d.ts +20 -0
  99. package/dist/storage/backupCompression.js +67 -0
  100. package/dist/storage/methods.d.ts +16 -2
  101. package/dist/storage/methods.js +98 -14
  102. package/dist/users/methods.js +9 -8
  103. package/dist/utils/configDiscovery.d.ts +78 -0
  104. package/dist/utils/configDiscovery.js +430 -0
  105. package/dist/utils/directoryUtils.d.ts +22 -0
  106. package/dist/utils/directoryUtils.js +59 -0
  107. package/dist/utils/getClientFromConfig.d.ts +17 -8
  108. package/dist/utils/getClientFromConfig.js +162 -17
  109. package/dist/utils/helperFunctions.d.ts +16 -2
  110. package/dist/utils/helperFunctions.js +19 -5
  111. package/dist/utils/loadConfigs.d.ts +34 -9
  112. package/dist/utils/loadConfigs.js +236 -316
  113. package/dist/utils/pathResolvers.d.ts +53 -0
  114. package/dist/utils/pathResolvers.js +72 -0
  115. package/dist/utils/projectConfig.d.ts +119 -0
  116. package/dist/utils/projectConfig.js +171 -0
  117. package/dist/utils/retryFailedPromises.js +4 -2
  118. package/dist/utils/sessionAuth.d.ts +48 -0
  119. package/dist/utils/sessionAuth.js +164 -0
  120. package/dist/utils/sessionPreservationExample.d.ts +1666 -0
  121. package/dist/utils/sessionPreservationExample.js +101 -0
  122. package/dist/utils/setupFiles.js +301 -41
  123. package/dist/utils/typeGuards.d.ts +35 -0
  124. package/dist/utils/typeGuards.js +57 -0
  125. package/dist/utils/versionDetection.js +145 -9
  126. package/dist/utils/yamlConverter.d.ts +53 -3
  127. package/dist/utils/yamlConverter.js +232 -13
  128. package/dist/utils/yamlLoader.d.ts +70 -0
  129. package/dist/utils/yamlLoader.js +263 -0
  130. package/dist/utilsController.d.ts +36 -3
  131. package/dist/utilsController.js +186 -56
  132. package/package.json +12 -2
  133. package/src/adapters/AdapterFactory.ts +263 -35
  134. package/src/adapters/TablesDBAdapter.ts +225 -36
  135. package/src/backups/operations/bucketBackup.ts +277 -0
  136. package/src/backups/operations/collectionBackup.ts +310 -0
  137. package/src/backups/operations/comprehensiveBackup.ts +342 -0
  138. package/src/backups/schemas/bucketManifest.ts +78 -0
  139. package/src/backups/schemas/comprehensiveManifest.ts +76 -0
  140. package/src/backups/tracking/centralizedTracking.ts +352 -0
  141. package/src/cli/commands/configCommands.ts +194 -0
  142. package/src/cli/commands/databaseCommands.ts +635 -0
  143. package/src/cli/commands/functionCommands.ts +379 -0
  144. package/src/cli/commands/schemaCommands.ts +163 -0
  145. package/src/cli/commands/transferCommands.ts +457 -0
  146. package/src/collections/attributes.ts +900 -621
  147. package/src/collections/attributes.ts.backup +1555 -0
  148. package/src/collections/indexes.ts +116 -114
  149. package/src/collections/methods.ts +295 -968
  150. package/src/collections/transferOperations.ts +516 -0
  151. package/src/collections/wipeOperations.ts +501 -0
  152. package/src/config/README.md +274 -0
  153. package/src/config/configMigration.ts +575 -0
  154. package/src/config/configValidation.ts +445 -0
  155. package/src/config/yamlConfig.ts +168 -55
  156. package/src/databases/methods.ts +3 -2
  157. package/src/databases/setup.ts +11 -138
  158. package/src/examples/yamlTerminologyExample.ts +341 -0
  159. package/src/functions/deployments.ts +14 -12
  160. package/src/functions/methods.ts +11 -11
  161. package/src/functions/templates/hono-typescript/README.md +286 -0
  162. package/src/functions/templates/hono-typescript/package.json +26 -0
  163. package/src/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
  164. package/src/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
  165. package/src/functions/templates/hono-typescript/src/app.ts +180 -0
  166. package/src/functions/templates/hono-typescript/src/context.ts +103 -0
  167. package/src/functions/templates/hono-typescript/src/index.ts +54 -0
  168. package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
  169. package/src/functions/templates/hono-typescript/tsconfig.json +20 -0
  170. package/src/functions/templates/typescript-node/package.json +2 -1
  171. package/src/functions/templates/typescript-node/src/context.ts +103 -0
  172. package/src/functions/templates/typescript-node/src/index.ts +18 -12
  173. package/src/functions/templates/uv/pyproject.toml +1 -0
  174. package/src/functions/templates/uv/src/context.py +125 -0
  175. package/src/functions/templates/uv/src/index.py +35 -5
  176. package/src/init.ts +9 -11
  177. package/src/interactiveCLI.ts +274 -1563
  178. package/src/main.ts +418 -24
  179. package/src/migrations/afterImportActions.ts +71 -44
  180. package/src/migrations/appwriteToX.ts +100 -34
  181. package/src/migrations/dataLoader.ts +48 -34
  182. package/src/migrations/importController.ts +44 -39
  183. package/src/migrations/relationships.ts +28 -18
  184. package/src/migrations/services/ImportOrchestrator.ts +24 -27
  185. package/src/migrations/transfer.ts +159 -121
  186. package/src/migrations/yaml/YamlImportConfigLoader.ts +11 -4
  187. package/src/migrations/yaml/YamlImportIntegration.ts +47 -20
  188. package/src/migrations/yaml/generateImportSchemas.ts +751 -12
  189. package/src/setupController.ts +3 -2
  190. package/src/shared/backupMetadataSchema.ts +93 -0
  191. package/src/shared/backupTracking.ts +211 -0
  192. package/src/shared/confirmationDialogs.ts +19 -19
  193. package/src/shared/errorUtils.ts +110 -0
  194. package/src/shared/functionManager.ts +21 -20
  195. package/src/shared/indexManager.ts +12 -11
  196. package/src/shared/jsonSchemaGenerator.ts +38 -52
  197. package/src/shared/logging.ts +75 -0
  198. package/src/shared/messageFormatter.ts +14 -1
  199. package/src/shared/migrationHelpers.ts +45 -38
  200. package/src/shared/operationLogger.ts +11 -36
  201. package/src/shared/operationQueue.ts +322 -93
  202. package/src/shared/operationsTable.ts +338 -0
  203. package/src/shared/operationsTableSchema.ts +60 -0
  204. package/src/shared/relationshipExtractor.ts +214 -0
  205. package/src/shared/schemaGenerator.ts +179 -219
  206. package/src/storage/backupCompression.ts +88 -0
  207. package/src/storage/methods.ts +131 -34
  208. package/src/users/methods.ts +11 -9
  209. package/src/utils/configDiscovery.ts +502 -0
  210. package/src/utils/directoryUtils.ts +61 -0
  211. package/src/utils/getClientFromConfig.ts +205 -22
  212. package/src/utils/helperFunctions.ts +23 -5
  213. package/src/utils/loadConfigs.ts +313 -345
  214. package/src/utils/pathResolvers.ts +81 -0
  215. package/src/utils/projectConfig.ts +299 -0
  216. package/src/utils/retryFailedPromises.ts +4 -2
  217. package/src/utils/sessionAuth.ts +230 -0
  218. package/src/utils/setupFiles.ts +322 -54
  219. package/src/utils/typeGuards.ts +65 -0
  220. package/src/utils/versionDetection.ts +218 -64
  221. package/src/utils/yamlConverter.ts +296 -13
  222. package/src/utils/yamlLoader.ts +364 -0
  223. package/src/utilsController.ts +314 -110
  224. package/tests/README.md +497 -0
  225. package/tests/adapters/AdapterFactory.test.ts +277 -0
  226. package/tests/integration/syncOperations.test.ts +463 -0
  227. package/tests/jest.config.js +25 -0
  228. package/tests/migration/configMigration.test.ts +546 -0
  229. package/tests/setup.ts +62 -0
  230. package/tests/testUtils.ts +340 -0
  231. package/tests/utils/loadConfigs.test.ts +350 -0
  232. package/tests/validation/configValidation.test.ts +412 -0
  233. package/src/utils/schemaStrings.ts +0 -517
package/CHANGELOG.md ADDED
@@ -0,0 +1,199 @@
1
+ # Changelog
2
+
3
+ All notable changes to the appwrite-utils-cli package will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.6.1] - 2025-10-02
9
+
10
+ ### Changed
11
+ - **Code Organization**: Major refactoring to improve maintainability
12
+ - Extracted wipe operations into dedicated module (501 lines)
13
+ - Extracted transfer operations into dedicated module (516 lines)
14
+ - Extracted config discovery logic into separate file (502 lines)
15
+ - Split interactive CLI into 5 focused command modules (1,595 lines total)
16
+ - Reduced large file sizes by 30-60% while maintaining all functionality
17
+ - **Logging Standardization**: Unified logging across entire codebase
18
+ - Replaced ~500 console.* calls with MessageFormatter
19
+ - Consistent prefixes and formatting for better debugging
20
+ - Integrated with Winston structured logging
21
+ - **New Utilities**: Added shared utility modules for better code reuse
22
+ - errorUtils.ts for centralized error handling
23
+ - directoryUtils.ts for file system operations
24
+ - typeGuards.ts for TypeScript type safety
25
+ - pathResolvers.ts for consistent path resolution
26
+
27
+ ## [1.6.0] - 2025-01-27
28
+
29
+ ### Added
30
+ - **Session Authentication Integration**: Complete integration with Appwrite CLI session authentication
31
+ - New CLI flags: `--use-session`, `--session`, `--sessionCookie` for flexible authentication
32
+ - Automatic detection and usage of sessions from `~/.appwrite/prefs.json`
33
+ - Priority authentication system: explicit session → session from prefs → API key → error
34
+ - Enhanced error messages with available session listing and login guidance
35
+ - Seamless integration maintaining backward compatibility with API key workflows
36
+
37
+ - **Native Project Configuration Support**: Full support for appwrite.json/appwrite.config.json files
38
+ - Automatic project configuration detection and loading from current directory tree
39
+ - Support for both Collections and TablesDB project formats from official Appwrite CLI
40
+ - Enhanced project context awareness for better tooling integration
41
+ - Conversion between project config and internal AppwriteConfig formats
42
+ - Priority system: CLI args → project config → YAML config → interactive prompt
43
+
44
+ - **Intelligent Version-Aware Setup**: Enhanced setup command with smart detection
45
+ - **Project-First Detection**: Automatically detects project type from existing appwrite.json
46
+ - **Session-Powered Version Detection**: Uses session auth for server version checking when available
47
+ - **Context-Aware Templates**: Generates tables/columns templates for TablesDB (1.8.0+)
48
+ - **Legacy Support**: Generates collections/attributes templates for older versions
49
+ - **Smart Schema Generation**: Creates appropriate JSON schemas (table.schema.json vs collection.schema.json)
50
+ - **Enhanced Examples**: TablesDB templates include unique constraints and row-level security features
51
+
52
+ - **Enhanced Client Creation**: Completely overhauled authentication flow
53
+ - New `getClientWithAuth()` function with intelligent fallback system
54
+ - Session validation and endpoint matching for security
55
+ - Enhanced `UtilsController` with session authentication support
56
+ - Automatic session discovery when no API key provided
57
+ - Clear authentication method logging and error reporting
58
+
59
+ - **Hono-TypeScript Function Template**: New web framework template for modern API development
60
+ - Complete Hono.dev integration with Appwrite functions
61
+ - Request/response adapters for seamless Appwrite-Hono bridge
62
+ - Built-in middleware for logging, error handling, and context injection
63
+ - Example API endpoints with database operations and authentication
64
+ - Comprehensive documentation and usage examples
65
+
66
+ - **Enhanced Function Templates**: Improved TypeScript and Python templates
67
+ - Complete Pydantic models for Python functions with proper type hints
68
+ - Enhanced Zod schemas for TypeScript functions with full validation
69
+ - Better error handling and context validation in templates
70
+ - Updated dependencies (Hono, Zod, Pydantic) in template configurations
71
+
72
+ - **Dual Collections/Tables Support**: Full support for both legacy and TablesDB APIs
73
+ - Enhanced YAML loading from both `collections/` and `tables/` directories simultaneously
74
+ - Automatic conflict detection and resolution between folder structures
75
+ - Version-aware folder selection based on Appwrite API detection
76
+ - Backward compatibility with existing projects
77
+
78
+ - **Interactive CLI Enhancements**: Improved user experience and database association
79
+ - Better collection/table selection with type indicators (🟢 Collection, 🔵 Table)
80
+ - Enhanced database filtering using optional `databaseId` for tables
81
+ - Improved prompts and contextual information display
82
+ - Better organization of mixed collection/table scenarios
83
+
84
+ - **Configuration Validation & Migration**: Comprehensive validation and migration tools
85
+ - New CLI flags: `--validate`, `--validate-strict`, `--migrate-collections-to-tables`
86
+ - Configuration validation with detailed error reporting and suggestions
87
+ - Multiple migration strategies for different project needs
88
+ - Integration with config loading for automatic validation
89
+
90
+ - **Enhanced Sync Operations**: Fixed and improved sync-from-Appwrite functionality
91
+ - **Fixed Database Syncing**: Remote databases now properly sync into `config.yaml`
92
+ - **Version-Aware YAML Generation**: Correct schema references and folder selection
93
+ - **Improved Error Handling**: Better user feedback and error recovery
94
+ - **Enhanced Logging**: Comprehensive operation tracking and debugging
95
+
96
+ ### Changed
97
+ - **Authentication Priority**: Complete overhaul of authentication handling throughout CLI
98
+ - Session authentication now preferred over API key when available
99
+ - Enhanced error messages guide users to proper authentication setup
100
+ - Better integration with existing Appwrite CLI workflows
101
+ - Maintained full backward compatibility with existing projects
102
+
103
+ - **Setup Command Experience**: Major improvements to project initialization
104
+ - Intelligent detection provides better user feedback about project type
105
+ - Version-aware terminology throughout setup process
106
+ - Enhanced console output with detection source information
107
+ - Better guidance for TablesDB features and capabilities
108
+
109
+ - **Configuration Loading**: Enhanced to work with multiple configuration sources
110
+ - Project configuration loading from appwrite.json files
111
+ - Better conflict resolution between different config sources
112
+ - Enhanced validation and error handling for mixed scenarios
113
+
114
+ - **Enhanced Logging Infrastructure**: Comprehensive logging throughout the CLI
115
+ - Structured JSON logging with operation context and timing
116
+ - Version detection and adapter selection logging
117
+ - Attribute min/max value processing logs with before/after values
118
+ - Performance timing for bottleneck identification
119
+
120
+ - **Improved Template System**: Better function template organization and options
121
+ - Added "TypeScript with Hono Web Framework" option to CLI
122
+ - Enhanced template variable replacement system
123
+ - Better template defaults and configuration
124
+ - Improved template documentation and examples
125
+
126
+ ### Fixed
127
+ - **Authentication Error Handling**: Resolved issues with missing authentication
128
+ - Better fallback logic when session authentication unavailable
129
+ - Clear error messages with actionable guidance
130
+ - Proper handling of invalid or expired session cookies
131
+ - Enhanced validation of authentication methods
132
+
133
+ - **Type Safety**: Resolved TypeScript compilation issues
134
+ - Fixed session authentication type definitions
135
+ - Proper null/undefined handling in project configuration
136
+ - Enhanced type inference throughout authentication flow
137
+ - Better error message types and interfaces
138
+
139
+ - **Version Detection**: Improved reliability of server version detection
140
+ - Better error handling when version detection fails
141
+ - Enhanced fallback mechanisms for offline scenarios
142
+ - Improved session-based version detection accuracy
143
+
144
+ - **Integer/Float Min/Max Handling**: Resolved issues with extreme values in attribute creation
145
+ - Implemented 10 billion threshold logic for min/max values
146
+ - Proper undefined value handling for Appwrite API compatibility
147
+ - Consistent normalization between create and update operations
148
+ - Better comparison logic for determining when updates are needed
149
+
150
+ - **Collection Re-pushing Prevention**: Eliminated unnecessary collection processing
151
+ - Intelligent state management prevents duplicate operations
152
+ - Surgical queue processing for relationship attributes only
153
+ - Better cache management and state tracking
154
+ - Performance improvements for large collection push operations
155
+
156
+ - **Version-Aware Attribute Creation**: Proper API mode detection and routing
157
+ - All attribute operations now route through adapter pattern
158
+ - TablesDB vs Legacy API terminology used correctly
159
+ - Fixed direct SDK calls that bypassed version detection
160
+ - Maintained backward compatibility with pre-1.8.0 Appwrite
161
+
162
+ - **Sync-from-Appwrite Issues**: Comprehensive fixes for YAML generation
163
+ - Database definitions now properly added to configuration
164
+ - Version-aware folder structure (tables/ vs collections/)
165
+ - Correct schema references in generated YAML files
166
+ - Enhanced error handling and user feedback
167
+
168
+ ### Technical Improvements
169
+ - **New Utilities**: Added comprehensive session and project management utilities
170
+ - `sessionAuth.ts` - Complete session management and validation
171
+ - `projectConfig.ts` - Appwrite project configuration handling
172
+ - Enhanced `getClientFromConfig.ts` with session authentication support
173
+ - Improved `setupFiles.ts` with intelligent version detection
174
+
175
+ - **Enhanced Type Definitions**: Better TypeScript support throughout
176
+ - Comprehensive session authentication types
177
+ - Project configuration interfaces and validation
178
+ - Enhanced error handling and message formatting
179
+ - Better integration between authentication methods
180
+
181
+ - **Improved Error Handling**: More helpful and actionable error messages
182
+ - Authentication method reporting and guidance
183
+ - Session availability checking and listing
184
+ - Project configuration validation feedback
185
+ - Version detection status and fallback information
186
+
187
+ - **Full TypeScript Type Safety**: Enhanced type definitions throughout
188
+ - **Comprehensive Test Coverage**: Extensive testing for all new features
189
+ - **Performance Optimizations**: Reduced redundant operations and improved efficiency
190
+ - **Enhanced Debugging**: Better visibility into CLI operations and state changes
191
+
192
+ ## [1.5.2] - 2024-XX-XX
193
+
194
+ ### Previous
195
+ - Earlier version features and improvements
196
+
197
+ ## Earlier Versions
198
+
199
+ Please refer to git history for changes prior to v1.6.0.
package/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- `appwrite-utils-cli` is a powerful, YAML-first command-line interface tool designed for Appwrite developers who need to manage database migrations, schema generation, data import, and comprehensive project management. Built on a modular architecture with enhanced performance, this CLI tool facilitates complex tasks like setting up databases, running migrations, generating schemas, and managing backups efficiently. With version 1.0.0, the CLI introduces a completely refactored import system with 50%+ complexity reduction, YAML-first configuration, and sophisticated data handling capabilities.
5
+ `appwrite-utils-cli` is a powerful, YAML-first command-line interface tool designed for Appwrite developers who need to manage database migrations, schema generation, data import, and comprehensive project management. Built on a modular architecture with enhanced performance, this CLI tool facilitates complex tasks like setting up databases, running migrations, generating schemas, and managing backups efficiently.
6
+
7
+ **Version 1.6.1**: Major refactoring for improved code organization - extracted operations into focused modules, standardized logging across the codebase, and added utility libraries for better maintainability.
6
8
 
7
9
  ## Features
8
10
 
@@ -13,6 +15,13 @@
13
15
  - **Enhanced Performance**: Configurable rate limiting and batch processing for optimal performance
14
16
  - **Safety First**: Smart confirmation dialogs for destructive operations with explicit confirmations
15
17
 
18
+ ### Dual API Support (Collections & TablesDB)
19
+ - **Collections API**: Traditional Appwrite database operations with document-based terminology
20
+ - **TablesDB API**: New high-performance table API with column-based terminology
21
+ - **Automatic Detection**: Smart API mode detection based on configuration and available packages
22
+ - **Seamless Migration**: Zero-downtime migration between Collections and TablesDB APIs
23
+ - **Terminology Flexibility**: Support for both `collections/documents/attributes` and `tables/rows/columns`
24
+
16
25
  ### Data Management
17
26
  - **Advanced Data Import**: YAML-configured imports with sophisticated file handling, URL support, and user deduplication
18
27
  - **Relationship Resolution**: Intelligent cross-collection relationship mapping and ID resolution
@@ -44,6 +53,87 @@ npx --package=appwrite-utils-cli@latest appwrite-migrate [options]
44
53
 
45
54
  **Note: Do not install this locally into your project. It is meant to be used as a command-line tool only.**
46
55
 
56
+ ## TablesDB Support
57
+
58
+ `appwrite-utils-cli` provides comprehensive support for both traditional Appwrite Collections API and the new TablesDB API, enabling high-performance database operations with modern terminology.
59
+
60
+ ### API Mode Detection
61
+
62
+ The CLI automatically detects which API to use based on:
63
+
64
+ 1. **Package Detection**: Checks for `node-appwrite-tablesdb` package installation
65
+ 2. **Configuration**: Detects `collections` vs `tables` in YAML configuration
66
+ 3. **Environment**: Falls back to Collections API if TablesDB is not available
67
+
68
+ ### Installing TablesDB Support
69
+
70
+ To enable TablesDB functionality, install the TablesDB package alongside the CLI:
71
+
72
+ ```bash
73
+ # For global CLI usage
74
+ npm install -g node-appwrite-tablesdb
75
+
76
+ # For project-specific usage
77
+ npm install node-appwrite-tablesdb
78
+ npx --package=appwrite-utils-cli@latest --package=node-appwrite-tablesdb@latest appwrite-migrate --it
79
+ ```
80
+
81
+ ### Configuration Comparison
82
+
83
+ #### Collections API (Traditional)
84
+ ```yaml
85
+ # .appwrite/config.yaml
86
+ databases:
87
+ - name: "main"
88
+ id: "main"
89
+ collections: # Collections terminology
90
+ - name: "Users"
91
+ id: "users"
92
+ attributes:
93
+ - key: "email"
94
+ type: "string"
95
+ required: true
96
+ ```
97
+
98
+ #### TablesDB API (New)
99
+ ```yaml
100
+ # .appwrite/config.yaml
101
+ databases:
102
+ - name: "main"
103
+ id: "main"
104
+ tables: # TablesDB terminology
105
+ - name: "Users"
106
+ id: "users"
107
+ attributes: # Internally consistent
108
+ - key: "email"
109
+ type: "string"
110
+ required: true
111
+ ```
112
+
113
+ ### Performance Benefits
114
+
115
+ TablesDB provides significant performance improvements:
116
+
117
+ - **Bulk Operations**: Native support for bulk inserts, updates, and deletes
118
+ - **Advanced Queries**: Enhanced query capabilities with better optimization
119
+ - **Reduced Latency**: Direct table operations without document overhead
120
+ - **Scalability**: Better performance with large datasets
121
+
122
+ ### Migration Commands
123
+
124
+ The CLI provides seamless migration between APIs:
125
+
126
+ ```bash
127
+ # Migrate Collections config to TablesDB format
128
+ npx appwrite-utils-cli appwrite-migrate --migrate-to-tablesdb
129
+
130
+ # Convert existing Collections to Tables (when TablesDB is available)
131
+ npx appwrite-utils-cli appwrite-migrate --sync --use-tablesdb
132
+
133
+ # Generate schemas for TablesDB
134
+ npx appwrite-utils-cli appwrite-migrate --generate --api-mode=tablesdb
135
+ ```
136
+
47
137
  ## YAML-First Configuration
48
138
 
49
139
  Version 1.0.0 introduces a YAML-first approach for better cross-platform compatibility and enhanced developer experience.
@@ -55,8 +145,9 @@ The CLI automatically detects configuration files in this order:
55
145
  2. `appwrite.yaml`
56
146
  3. `appwriteConfig.ts` (legacy, still supported)
57
147
 
58
- ### YAML Configuration Example
148
+ ### YAML Configuration Examples
59
149
 
150
+ #### Collections API Configuration
60
151
  ```yaml
61
152
  # .appwrite/config.yaml with JSON Schema support
62
153
  # yaml-language-server: $schema=./.yaml_schemas/appwrite-config.schema.json
@@ -68,7 +159,7 @@ appwriteKey: "your-api-key"
68
159
  databases:
69
160
  - name: "main"
70
161
  id: "main"
71
- collections:
162
+ collections: # Collections terminology
72
163
  - name: "Users"
73
164
  id: "users"
74
165
  attributes:
@@ -76,6 +167,46 @@ databases:
76
167
  type: "string"
77
168
  required: true
78
169
  format: "email"
170
+ - key: "name"
171
+ type: "string"
172
+ required: true
173
+
174
+ buckets:
175
+ - name: "documents"
176
+ id: "documents"
177
+ permissions:
178
+ - target: "any"
179
+ permission: "read"
180
+
181
+ logging:
182
+ enabled: false # Disabled by default
183
+ level: "info"
184
+ console: true
185
+ ```
186
+
187
+ #### TablesDB API Configuration
188
+ ```yaml
189
+ # .appwrite/config.yaml for TablesDB
190
+ # yaml-language-server: $schema=./.yaml_schemas/appwrite-config.schema.json
191
+
192
+ appwriteEndpoint: "https://cloud.appwrite.io/v1"
193
+ appwriteProject: "your-project-id"
194
+ appwriteKey: "your-api-key"
195
+
196
+ databases:
197
+ - name: "main"
198
+ id: "main"
199
+ tables: # TablesDB terminology
200
+ - name: "Users"
201
+ id: "users"
202
+ attributes: # Internal compatibility
203
+ - key: "email"
204
+ type: "string"
205
+ required: true
206
+ format: "email"
207
+ - key: "name"
208
+ type: "string"
209
+ required: true
79
210
 
80
211
  buckets:
81
212
  - name: "documents"
@@ -120,8 +251,9 @@ npx --package=appwrite-utils-cli@latest appwrite-migrate [options]
120
251
 
121
252
  Version 1.0.0 introduces a powerful YAML-based import system with sophisticated data handling capabilities.
122
253
 
123
- ### Import Configuration Example
254
+ ### Import Configuration Examples
124
255
 
256
+ #### Collections API Import
125
257
  ```yaml
126
258
  # .appwrite/import/users-import.yaml
127
259
  # yaml-language-server: $schema=../.yaml_schemas/import-config.schema.json
@@ -132,7 +264,7 @@ source:
132
264
  type: "json"
133
265
 
134
266
  target:
135
- collection: "Users"
267
+ collection: "Users" # Collections terminology
136
268
  type: "create"
137
269
  primaryKey: "user_id"
138
270
  createUsers: true
@@ -165,6 +297,51 @@ options:
165
297
  continueOnError: true
166
298
  ```
167
299
 
300
+ #### TablesDB API Import
301
+ ```yaml
302
+ # .appwrite/import/users-tablesdb-import.yaml
303
+ # yaml-language-server: $schema=../.yaml_schemas/import-config.schema.json
304
+
305
+ source:
306
+ file: "importData/users.json"
307
+ basePath: "RECORDS"
308
+ type: "json"
309
+
310
+ target:
311
+ table: "Users" # TablesDB terminology (alternatively: collection: "Users" works too)
312
+ type: "create"
313
+ primaryKey: "user_id"
314
+ createUsers: true
315
+
316
+ mapping:
317
+ attributes: # Note: Still uses 'attributes' for compatibility
318
+ - oldKey: "user_id"
319
+ targetKey: "userId"
320
+ converters: ["anyToString"]
321
+ validation:
322
+ - rule: "required"
323
+ params: ["{userId}"]
324
+
325
+ - oldKey: "profile_image_url"
326
+ targetKey: "avatar"
327
+ fileData:
328
+ path: "{profile_image_url}"
329
+ name: "{user_id}_avatar"
330
+ afterImport:
331
+ - action: "createFileAndUpdateRowField" # TablesDB-specific action
332
+ params: ["{dbId}", "{tableId}", "{rowId}", "avatar", "{bucketId}", "{filePath}", "{fileName}"]
333
+
334
+ relationships:
335
+ - sourceField: "department_id"
336
+ targetField: "departmentId"
337
+ targetTable: "Departments" # TablesDB terminology
338
+
339
+ options:
340
+ batchSize: 100 # TablesDB supports larger batches
341
+ continueOnError: true
342
+ useBulkOperations: true # Enable TablesDB bulk operations
343
+ ```
344
+
168
345
  ### Import System Features
169
346
 
170
347
  - **File Handling**: Complete support for URL downloads and local file search
@@ -188,12 +365,19 @@ Available options:
188
365
 
189
366
  ### Data Management
190
367
  - `--dbIds`: Comma-separated list of database IDs to operate on
191
- - `--collectionIds`: Comma-separated list of collection IDs to operate on
368
+ - `--collectionIds`: Comma-separated list of collection IDs to operate on (also accepts `--tableIds`)
192
369
  - `--bucketIds`: Comma-separated list of bucket IDs to operate on
193
370
  - `--wipe`: Wipe data with smart confirmation (all: everything, docs: only documents, users: only user data)
194
- - `--wipeCollections`: Non-destructively wipe specified collections
371
+ - `--wipeCollections`: Non-destructively wipe specified collections (also `--wipeTables`)
195
372
  - `--writeData`: Write converted imported data to file for validation
196
373
 
374
+ ### TablesDB-Specific Options
375
+ - `--api-mode`: Force API mode (`collections` or `tablesdb`)
376
+ - `--use-tablesdb`: Force TablesDB API usage when available
377
+ - `--migrate-to-tablesdb`: Convert Collections configuration to TablesDB format
378
+ - `--bulk-operations`: Enable bulk operations for TablesDB (default: true when available)
379
+ - `--tableIds`: Comma-separated list of table IDs (alias for `--collectionIds`)
380
+
197
381
  ### Configuration & Synchronization
198
382
  - `--push`: Push local YAML/TypeScript config to Appwrite project
199
383
  - `--sync`: Synchronize by pulling config from Appwrite project
@@ -282,6 +466,44 @@ Transfer specific collections from one place to another, with all of their data:
282
466
  npx appwrite-utils-cli appwrite-migrate --transfer --fromDbId sourceDbId --toDbId targetDbId --fromCollectionId sourceCollectionId --toCollectionId targetCollectionId --remoteEndpoint https://appwrite.otherserver.com --remoteProjectId yourProjectId --remoteApiKey yourApiKey
283
467
  ```
284
468
 
469
+ ### TablesDB Examples
470
+
471
+ #### Enable TablesDB Mode
472
+ ```bash
473
+ # Force TablesDB API usage
474
+ npx appwrite-utils-cli appwrite-migrate --sync --use-tablesdb
475
+
476
+ # Generate schemas with TablesDB terminology
477
+ npx appwrite-utils-cli appwrite-migrate --generate --api-mode=tablesdb
478
+ ```
479
+
480
+ #### Migration from Collections to TablesDB
481
+ ```bash
482
+ # Convert Collections configuration to TablesDB format
483
+ npx appwrite-utils-cli appwrite-migrate --migrate-to-tablesdb
484
+
485
+ # Sync with TablesDB API (requires node-appwrite-tablesdb)
486
+ npx --package=node-appwrite-tablesdb appwrite-utils-cli appwrite-migrate --sync --use-tablesdb
487
+ ```
488
+
489
+ #### Bulk Operations with TablesDB
490
+ ```bash
491
+ # Import with bulk operations enabled
492
+ npx appwrite-utils-cli appwrite-migrate --import --bulk-operations
493
+
494
+ # Transfer tables with high-performance bulk operations
495
+ npx appwrite-utils-cli appwrite-migrate --transfer --fromDbId sourceDb --toDbId targetDb --tableIds table1,table2 --use-tablesdb
496
+ ```
497
+
498
+ #### Working with Tables (TablesDB terminology)
499
+ ```bash
500
+ # Wipe specific tables
501
+ npx appwrite-utils-cli appwrite-migrate --wipeTables --tableIds users,posts
502
+
503
+ # Generate constants with table terminology
504
+ npx appwrite-utils-cli appwrite-migrate --generateConstants --api-mode=tablesdb
505
+ ```
506
+
285
507
  ### Transfer Buckets
286
508
 
287
509
  Transfer files between buckets:
@@ -325,28 +547,28 @@ Available specifications:
325
547
 
326
548
  This updated CLI ensures that developers have robust tools at their fingertips to manage complex Appwrite projects effectively from the command line, with both interactive and non-interactive modes available for flexibility.
327
549
 
328
- ## Changelog
329
-
330
- ### 1.5.0 - Recursive Zod v4 Schemas + One‑Way Relationship Support
331
-
332
- Highlights
333
- - Recursive getters: Generated schemas now use Zod v4 recursive getters (no `z.lazy`, no `BaseSchema` layering). Cleaner types and fully inferred mutual recursion.
334
- - One‑way relationships: Relationship attributes are now included even when `twoWay: false`. Related imports resolve collection IDs to names.
335
- - Required semantics: Relationship getters respect `required` and `array`:
336
- - required scalar → `RelatedSchema`
337
- - optional scalar → `RelatedSchema.nullish()`
338
- - required array → `RelatedSchema.array()`
339
- - optional array → `RelatedSchema.array().nullish()`
340
- - JSON Schemas: `$ref` definitions use resolved collection names when YAML provides IDs.
341
-
342
- Validation changes
343
- - Relationship schema: `twoWayKey` and `side` are now required only when `twoWay` is `true`.
344
- - Helpful errors: Keeps strong validation but removes false negatives for one‑way relationships.
345
-
346
- Developer notes
347
- - Imports: Schema generators import only `...Schema` from related collections (no type imports needed).
348
- - Example YAML: `Posts.yaml` demonstrates a required `manyToMany` (`categories`) and a one‑way `manyToOne` (`author`).
349
-
550
+ ## Changelog
551
+
552
+ ### 1.5.0 - Recursive Zod v4 Schemas + One‑Way Relationship Support
553
+
554
+ Highlights
555
+ - Recursive getters: Generated schemas now use Zod v4 recursive getters (no `z.lazy`, no `BaseSchema` layering). Cleaner types and fully inferred mutual recursion.
556
+ - One‑way relationships: Relationship attributes are now included even when `twoWay: false`. Related imports resolve collection IDs to names.
557
+ - Required semantics: Relationship getters respect `required` and `array`:
558
+ - required scalar → `RelatedSchema`
559
+ - optional scalar → `RelatedSchema.nullish()`
560
+ - required array → `RelatedSchema.array()`
561
+ - optional array → `RelatedSchema.array().nullish()`
562
+ - JSON Schemas: `$ref` definitions use resolved collection names when YAML provides IDs.
563
+
564
+ Validation changes
565
+ - Relationship schema: `twoWayKey` and `side` are now required only when `twoWay` is `true`.
566
+ - Helpful errors: Keeps strong validation but removes false negatives for one‑way relationships.
567
+
568
+ Developer notes
569
+ - Imports: Schema generators import only `...Schema` from related collections (no type imports needed).
570
+ - Example YAML: `Posts.yaml` demonstrates a required `manyToMany` (`categories`) and a one‑way `manyToOne` (`author`).
571
+
350
572
 
351
573
  ### 1.3.0 - Zod v4 Upgrade & Collection Management Fixes
352
574
 
@@ -11,9 +11,12 @@ import type { DatabaseAdapter } from './DatabaseAdapter.js';
11
11
  export interface AdapterFactoryConfig {
12
12
  appwriteEndpoint: string;
13
13
  appwriteProject: string;
14
- appwriteKey: string;
14
+ appwriteKey?: string;
15
15
  apiMode?: 'auto' | 'legacy' | 'tablesdb';
16
16
  forceRefresh?: boolean;
17
+ sessionCookie?: string;
18
+ authMethod?: 'session' | 'apikey' | 'auto';
19
+ preConfiguredClient?: any;
17
20
  }
18
21
  export interface AdapterFactoryResult {
19
22
  adapter: DatabaseAdapter;
@@ -59,6 +62,10 @@ export declare class AdapterFactory {
59
62
  * Clear adapter cache (useful for testing)
60
63
  */
61
64
  static clearCache(): void;
65
+ /**
66
+ * Validate authentication configuration
67
+ */
68
+ private static validateAuthConfig;
62
69
  /**
63
70
  * Test connection and API capabilities
64
71
  */
@@ -72,11 +79,11 @@ export declare class AdapterFactory {
72
79
  /**
73
80
  * Convenience function for quick adapter creation
74
81
  */
75
- export declare function createDatabaseAdapter(endpoint: string, project: string, apiKey: string, mode?: 'auto' | 'legacy' | 'tablesdb'): Promise<DatabaseAdapter>;
82
+ export declare function createDatabaseAdapter(endpoint: string, project: string, apiKey?: string, mode?: 'auto' | 'legacy' | 'tablesdb', sessionCookie?: string): Promise<DatabaseAdapter>;
76
83
  /**
77
84
  * Helper function to get adapter metadata without creating full adapter
78
85
  */
79
- export declare function getApiCapabilities(endpoint: string, project: string, apiKey: string): Promise<{
86
+ export declare function getApiCapabilities(endpoint: string, project: string, apiKey?: string, sessionCookie?: string): Promise<{
80
87
  apiMode: ApiMode;
81
88
  terminology: {
82
89
  container: string;