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.
Files changed (250) hide show
  1. package/{src/adapters/index.ts → dist/adapters/index.d.ts} +0 -1
  2. package/dist/adapters/index.js +10 -0
  3. package/dist/backups/operations/bucketBackup.d.ts +19 -0
  4. package/dist/backups/operations/bucketBackup.js +197 -0
  5. package/dist/backups/operations/collectionBackup.d.ts +30 -0
  6. package/dist/backups/operations/collectionBackup.js +201 -0
  7. package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
  8. package/dist/backups/operations/comprehensiveBackup.js +238 -0
  9. package/dist/backups/schemas/bucketManifest.d.ts +93 -0
  10. package/dist/backups/schemas/bucketManifest.js +33 -0
  11. package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
  12. package/dist/backups/schemas/comprehensiveManifest.js +32 -0
  13. package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
  14. package/dist/backups/tracking/centralizedTracking.js +274 -0
  15. package/dist/cli/commands/configCommands.d.ts +8 -0
  16. package/dist/cli/commands/configCommands.js +210 -0
  17. package/dist/cli/commands/databaseCommands.d.ts +14 -0
  18. package/dist/cli/commands/databaseCommands.js +696 -0
  19. package/dist/cli/commands/functionCommands.d.ts +7 -0
  20. package/dist/cli/commands/functionCommands.js +330 -0
  21. package/dist/cli/commands/importFileCommands.d.ts +7 -0
  22. package/dist/cli/commands/importFileCommands.js +674 -0
  23. package/dist/cli/commands/schemaCommands.d.ts +7 -0
  24. package/dist/cli/commands/schemaCommands.js +169 -0
  25. package/dist/cli/commands/storageCommands.d.ts +5 -0
  26. package/dist/cli/commands/storageCommands.js +142 -0
  27. package/dist/cli/commands/transferCommands.d.ts +5 -0
  28. package/dist/cli/commands/transferCommands.js +382 -0
  29. package/dist/collections/columns.d.ts +13 -0
  30. package/dist/collections/columns.js +1339 -0
  31. package/dist/collections/indexes.d.ts +12 -0
  32. package/dist/collections/indexes.js +215 -0
  33. package/dist/collections/methods.d.ts +19 -0
  34. package/dist/collections/methods.js +605 -0
  35. package/dist/collections/tableOperations.d.ts +87 -0
  36. package/dist/collections/tableOperations.js +466 -0
  37. package/dist/collections/transferOperations.d.ts +8 -0
  38. package/dist/collections/transferOperations.js +411 -0
  39. package/dist/collections/wipeOperations.d.ts +17 -0
  40. package/dist/collections/wipeOperations.js +306 -0
  41. package/dist/databases/methods.d.ts +6 -0
  42. package/dist/databases/methods.js +35 -0
  43. package/dist/databases/setup.d.ts +5 -0
  44. package/dist/databases/setup.js +45 -0
  45. package/dist/examples/yamlTerminologyExample.d.ts +42 -0
  46. package/dist/examples/yamlTerminologyExample.js +272 -0
  47. package/dist/functions/deployments.d.ts +4 -0
  48. package/dist/functions/deployments.js +146 -0
  49. package/dist/functions/fnConfigDiscovery.d.ts +3 -0
  50. package/dist/functions/fnConfigDiscovery.js +108 -0
  51. package/dist/functions/methods.d.ts +16 -0
  52. package/dist/functions/methods.js +174 -0
  53. package/dist/init.d.ts +2 -0
  54. package/dist/init.js +57 -0
  55. package/dist/interactiveCLI.d.ts +36 -0
  56. package/dist/interactiveCLI.js +952 -0
  57. package/dist/main.d.ts +2 -0
  58. package/dist/main.js +1125 -0
  59. package/dist/migrations/afterImportActions.d.ts +17 -0
  60. package/dist/migrations/afterImportActions.js +305 -0
  61. package/dist/migrations/appwriteToX.d.ts +211 -0
  62. package/dist/migrations/appwriteToX.js +493 -0
  63. package/dist/migrations/comprehensiveTransfer.d.ts +147 -0
  64. package/dist/migrations/comprehensiveTransfer.js +1315 -0
  65. package/dist/migrations/dataLoader.d.ts +755 -0
  66. package/dist/migrations/dataLoader.js +1272 -0
  67. package/dist/migrations/importController.d.ts +25 -0
  68. package/dist/migrations/importController.js +283 -0
  69. package/dist/migrations/importDataActions.d.ts +50 -0
  70. package/dist/migrations/importDataActions.js +230 -0
  71. package/dist/migrations/relationships.d.ts +29 -0
  72. package/dist/migrations/relationships.js +203 -0
  73. package/dist/migrations/services/DataTransformationService.d.ts +55 -0
  74. package/dist/migrations/services/DataTransformationService.js +158 -0
  75. package/dist/migrations/services/FileHandlerService.d.ts +75 -0
  76. package/dist/migrations/services/FileHandlerService.js +236 -0
  77. package/dist/migrations/services/ImportOrchestrator.d.ts +99 -0
  78. package/dist/migrations/services/ImportOrchestrator.js +493 -0
  79. package/dist/migrations/services/RateLimitManager.d.ts +138 -0
  80. package/dist/migrations/services/RateLimitManager.js +279 -0
  81. package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
  82. package/dist/migrations/services/RelationshipResolver.js +332 -0
  83. package/dist/migrations/services/UserMappingService.d.ts +109 -0
  84. package/dist/migrations/services/UserMappingService.js +277 -0
  85. package/dist/migrations/services/ValidationService.d.ts +74 -0
  86. package/dist/migrations/services/ValidationService.js +260 -0
  87. package/dist/migrations/transfer.d.ts +30 -0
  88. package/dist/migrations/transfer.js +661 -0
  89. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +131 -0
  90. package/dist/migrations/yaml/YamlImportConfigLoader.js +383 -0
  91. package/dist/migrations/yaml/YamlImportIntegration.d.ts +93 -0
  92. package/dist/migrations/yaml/YamlImportIntegration.js +341 -0
  93. package/dist/migrations/yaml/generateImportSchemas.d.ts +30 -0
  94. package/dist/migrations/yaml/generateImportSchemas.js +1327 -0
  95. package/dist/schemas/authUser.d.ts +24 -0
  96. package/dist/schemas/authUser.js +17 -0
  97. package/dist/setup.d.ts +2 -0
  98. package/{src/setup.ts → dist/setup.js} +0 -3
  99. package/dist/setupCommands.d.ts +58 -0
  100. package/dist/setupCommands.js +489 -0
  101. package/dist/setupController.d.ts +9 -0
  102. package/dist/setupController.js +34 -0
  103. package/dist/shared/backupMetadataSchema.d.ts +94 -0
  104. package/dist/shared/backupMetadataSchema.js +38 -0
  105. package/dist/shared/backupTracking.d.ts +18 -0
  106. package/dist/shared/backupTracking.js +176 -0
  107. package/dist/shared/confirmationDialogs.d.ts +75 -0
  108. package/dist/shared/confirmationDialogs.js +236 -0
  109. package/dist/shared/migrationHelpers.d.ts +61 -0
  110. package/dist/shared/migrationHelpers.js +145 -0
  111. package/{src/shared/operationLogger.ts → dist/shared/operationLogger.d.ts} +1 -11
  112. package/dist/shared/operationLogger.js +12 -0
  113. package/dist/shared/operationQueue.d.ts +40 -0
  114. package/dist/shared/operationQueue.js +310 -0
  115. package/dist/shared/operationsTable.d.ts +26 -0
  116. package/dist/shared/operationsTable.js +287 -0
  117. package/dist/shared/operationsTableSchema.d.ts +48 -0
  118. package/dist/shared/operationsTableSchema.js +35 -0
  119. package/dist/shared/progressManager.d.ts +62 -0
  120. package/dist/shared/progressManager.js +215 -0
  121. package/dist/shared/relationshipExtractor.d.ts +56 -0
  122. package/dist/shared/relationshipExtractor.js +138 -0
  123. package/dist/shared/selectionDialogs.d.ts +220 -0
  124. package/dist/shared/selectionDialogs.js +588 -0
  125. package/dist/storage/backupCompression.d.ts +20 -0
  126. package/dist/storage/backupCompression.js +67 -0
  127. package/dist/storage/methods.d.ts +44 -0
  128. package/dist/storage/methods.js +475 -0
  129. package/dist/storage/schemas.d.ts +842 -0
  130. package/dist/storage/schemas.js +175 -0
  131. package/dist/tables/indexManager.d.ts +65 -0
  132. package/dist/tables/indexManager.js +294 -0
  133. package/{src/types.ts → dist/types.d.ts} +1 -6
  134. package/dist/types.js +3 -0
  135. package/dist/users/methods.d.ts +16 -0
  136. package/dist/users/methods.js +276 -0
  137. package/dist/utils/configMigration.d.ts +1 -0
  138. package/dist/utils/configMigration.js +261 -0
  139. package/dist/utils/index.js +2 -0
  140. package/dist/utils/loadConfigs.d.ts +50 -0
  141. package/dist/utils/loadConfigs.js +357 -0
  142. package/dist/utils/setupFiles.d.ts +4 -0
  143. package/dist/utils/setupFiles.js +1190 -0
  144. package/dist/utilsController.d.ts +114 -0
  145. package/dist/utilsController.js +898 -0
  146. package/package.json +6 -3
  147. package/CHANGELOG.md +0 -35
  148. package/CONFIG_TODO.md +0 -1189
  149. package/SELECTION_DIALOGS.md +0 -146
  150. package/SERVICE_IMPLEMENTATION_REPORT.md +0 -462
  151. package/scripts/copy-templates.ts +0 -23
  152. package/src/backups/operations/bucketBackup.ts +0 -277
  153. package/src/backups/operations/collectionBackup.ts +0 -310
  154. package/src/backups/operations/comprehensiveBackup.ts +0 -342
  155. package/src/backups/schemas/bucketManifest.ts +0 -78
  156. package/src/backups/schemas/comprehensiveManifest.ts +0 -76
  157. package/src/backups/tracking/centralizedTracking.ts +0 -352
  158. package/src/cli/commands/configCommands.ts +0 -265
  159. package/src/cli/commands/databaseCommands.ts +0 -931
  160. package/src/cli/commands/functionCommands.ts +0 -419
  161. package/src/cli/commands/importFileCommands.ts +0 -815
  162. package/src/cli/commands/schemaCommands.ts +0 -200
  163. package/src/cli/commands/storageCommands.ts +0 -151
  164. package/src/cli/commands/transferCommands.ts +0 -454
  165. package/src/collections/attributes.ts.backup +0 -1555
  166. package/src/collections/columns.ts +0 -2025
  167. package/src/collections/indexes.ts +0 -350
  168. package/src/collections/methods.ts +0 -714
  169. package/src/collections/tableOperations.ts +0 -542
  170. package/src/collections/transferOperations.ts +0 -589
  171. package/src/collections/wipeOperations.ts +0 -449
  172. package/src/databases/methods.ts +0 -49
  173. package/src/databases/setup.ts +0 -77
  174. package/src/examples/yamlTerminologyExample.ts +0 -346
  175. package/src/functions/deployments.ts +0 -221
  176. package/src/functions/fnConfigDiscovery.ts +0 -103
  177. package/src/functions/methods.ts +0 -284
  178. package/src/init.ts +0 -62
  179. package/src/interactiveCLI.ts +0 -1201
  180. package/src/main.ts +0 -1517
  181. package/src/migrations/afterImportActions.ts +0 -579
  182. package/src/migrations/appwriteToX.ts +0 -668
  183. package/src/migrations/comprehensiveTransfer.ts +0 -2285
  184. package/src/migrations/dataLoader.ts +0 -1729
  185. package/src/migrations/importController.ts +0 -440
  186. package/src/migrations/importDataActions.ts +0 -315
  187. package/src/migrations/relationships.ts +0 -333
  188. package/src/migrations/services/DataTransformationService.ts +0 -196
  189. package/src/migrations/services/FileHandlerService.ts +0 -311
  190. package/src/migrations/services/ImportOrchestrator.ts +0 -675
  191. package/src/migrations/services/RateLimitManager.ts +0 -363
  192. package/src/migrations/services/RelationshipResolver.ts +0 -461
  193. package/src/migrations/services/UserMappingService.ts +0 -345
  194. package/src/migrations/services/ValidationService.ts +0 -349
  195. package/src/migrations/transfer.ts +0 -1113
  196. package/src/migrations/yaml/YamlImportConfigLoader.ts +0 -439
  197. package/src/migrations/yaml/YamlImportIntegration.ts +0 -446
  198. package/src/migrations/yaml/generateImportSchemas.ts +0 -1354
  199. package/src/schemas/authUser.ts +0 -23
  200. package/src/setupCommands.ts +0 -602
  201. package/src/setupController.ts +0 -43
  202. package/src/shared/backupMetadataSchema.ts +0 -93
  203. package/src/shared/backupTracking.ts +0 -211
  204. package/src/shared/confirmationDialogs.ts +0 -327
  205. package/src/shared/migrationHelpers.ts +0 -232
  206. package/src/shared/operationQueue.ts +0 -376
  207. package/src/shared/operationsTable.ts +0 -338
  208. package/src/shared/operationsTableSchema.ts +0 -60
  209. package/src/shared/progressManager.ts +0 -278
  210. package/src/shared/relationshipExtractor.ts +0 -214
  211. package/src/shared/selectionDialogs.ts +0 -802
  212. package/src/storage/backupCompression.ts +0 -88
  213. package/src/storage/methods.ts +0 -711
  214. package/src/storage/schemas.ts +0 -205
  215. package/src/tables/indexManager.ts +0 -409
  216. package/src/types/node-appwrite-tablesdb.d.ts +0 -44
  217. package/src/users/methods.ts +0 -358
  218. package/src/utils/configMigration.ts +0 -348
  219. package/src/utils/loadConfigs.ts +0 -457
  220. package/src/utils/setupFiles.ts +0 -1236
  221. package/src/utilsController.ts +0 -1263
  222. package/tests/README.md +0 -497
  223. package/tests/adapters/AdapterFactory.test.ts +0 -277
  224. package/tests/integration/syncOperations.test.ts +0 -463
  225. package/tests/jest.config.js +0 -25
  226. package/tests/migration/configMigration.test.ts +0 -546
  227. package/tests/setup.ts +0 -62
  228. package/tests/testUtils.ts +0 -340
  229. package/tests/utils/loadConfigs.test.ts +0 -350
  230. package/tests/validation/configValidation.test.ts +0 -412
  231. package/tsconfig.json +0 -44
  232. /package/{src → dist}/functions/templates/count-docs-in-collection/README.md +0 -0
  233. /package/{src → dist}/functions/templates/count-docs-in-collection/src/main.ts +0 -0
  234. /package/{src → dist}/functions/templates/count-docs-in-collection/src/request.ts +0 -0
  235. /package/{src → dist}/functions/templates/hono-typescript/README.md +0 -0
  236. /package/{src → dist}/functions/templates/hono-typescript/src/adapters/request.ts +0 -0
  237. /package/{src → dist}/functions/templates/hono-typescript/src/adapters/response.ts +0 -0
  238. /package/{src → dist}/functions/templates/hono-typescript/src/app.ts +0 -0
  239. /package/{src → dist}/functions/templates/hono-typescript/src/context.ts +0 -0
  240. /package/{src → dist}/functions/templates/hono-typescript/src/main.ts +0 -0
  241. /package/{src → dist}/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -0
  242. /package/{src → dist}/functions/templates/typescript-node/README.md +0 -0
  243. /package/{src → dist}/functions/templates/typescript-node/src/context.ts +0 -0
  244. /package/{src → dist}/functions/templates/typescript-node/src/main.ts +0 -0
  245. /package/{src → dist}/functions/templates/uv/README.md +0 -0
  246. /package/{src → dist}/functions/templates/uv/pyproject.toml +0 -0
  247. /package/{src → dist}/functions/templates/uv/src/__init__.py +0 -0
  248. /package/{src → dist}/functions/templates/uv/src/context.py +0 -0
  249. /package/{src → dist}/functions/templates/uv/src/main.py +0 -0
  250. /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
@@ -0,0 +1,1190 @@
1
+ import { mkdirSync, writeFileSync, existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { findAppwriteConfig } from "./loadConfigs.js";
4
+ import { loadYamlConfig, findYamlConfig, generateYamlConfigTemplate } from "appwrite-utils-helpers";
5
+ import { fetchServerVersion, isVersionAtLeast } from 'appwrite-utils-helpers';
6
+ import { ID } from "node-appwrite";
7
+ import { ulid } from "ulidx";
8
+ import { loadAppwriteProjectConfig, findAppwriteProjectConfig, getProjectDirectoryName, isTablesDBProject } from 'appwrite-utils-helpers';
9
+ import { hasSessionAuth, getSessionAuth } from 'appwrite-utils-helpers';
10
+ import { MessageFormatter } from "appwrite-utils-helpers";
11
+ // Example base configuration using types from appwrite-utils
12
+ const baseConfig = {
13
+ appwriteEndpoint: "https://cloud.appwrite.io/v1",
14
+ appwriteProject: "YOUR_PROJECT_ID",
15
+ appwriteKey: "YOUR_API_KEY",
16
+ appwriteClient: null,
17
+ apiMode: "auto", // Enable dual API support - auto-detect TablesDB vs legacy
18
+ authMethod: "auto", // Default to auto-detect authentication method
19
+ logging: {
20
+ enabled: false,
21
+ level: "info",
22
+ console: false,
23
+ },
24
+ enableBackups: true,
25
+ backupInterval: 3600,
26
+ backupRetention: 30,
27
+ enableBackupCleanup: true,
28
+ enableMockData: false,
29
+ documentBucketId: "documents",
30
+ usersCollectionName: "Members",
31
+ databases: [
32
+ {
33
+ $id: "main",
34
+ name: "Main",
35
+ bucket: {
36
+ $id: "main_bucket",
37
+ name: "Main Bucket",
38
+ enabled: true,
39
+ maximumFileSize: 30000000,
40
+ allowedFileExtensions: [],
41
+ encryption: true,
42
+ antivirus: true,
43
+ },
44
+ },
45
+ {
46
+ $id: "staging",
47
+ name: "Staging",
48
+ bucket: {
49
+ $id: "staging_bucket",
50
+ name: "Staging Bucket",
51
+ enabled: true,
52
+ maximumFileSize: 30000000,
53
+ allowedFileExtensions: [],
54
+ encryption: true,
55
+ antivirus: true,
56
+ },
57
+ },
58
+ {
59
+ $id: "dev",
60
+ name: "Development",
61
+ bucket: {
62
+ $id: "dev_bucket",
63
+ name: "Development Bucket",
64
+ enabled: true,
65
+ maximumFileSize: 30000000,
66
+ allowedFileExtensions: [],
67
+ encryption: true,
68
+ antivirus: true,
69
+ },
70
+ },
71
+ ],
72
+ buckets: [
73
+ {
74
+ $id: "global_bucket",
75
+ name: "Global Bucket",
76
+ enabled: true,
77
+ maximumFileSize: 30000000,
78
+ allowedFileExtensions: [],
79
+ encryption: true,
80
+ antivirus: true,
81
+ },
82
+ ],
83
+ };
84
+ const collectionsConfig = [
85
+ {
86
+ name: "ExampleCollection",
87
+ content: `import type { CollectionCreate } from "appwrite-utils";
88
+
89
+ const ExampleCollection: Partial<CollectionCreate> = {
90
+ name: 'ExampleCollection',
91
+ $id: '${ulid()}',
92
+ documentSecurity: false,
93
+ enabled: true,
94
+ $permissions: [
95
+ { permission: 'read', target: 'any' },
96
+ { permission: 'create', target: 'users' },
97
+ { permission: 'update', target: 'users' },
98
+ { permission: 'delete', target: 'users' }
99
+ ],
100
+ attributes: [
101
+ { key: 'alterEgoName', type: 'string', size: 255, required: false },
102
+ // Add more attributes here
103
+ ],
104
+ indexes: [
105
+ { key: 'alterEgoName_search', type: 'fulltext', attributes: ['alterEgoName'] }
106
+ ],
107
+ importDefs: [
108
+ // Define import definitions here
109
+ ]
110
+ };
111
+
112
+ export default ExampleCollection;`,
113
+ },
114
+ // Add more collections here
115
+ ];
116
+ // Define our YAML files
117
+ // Define our YAML files
118
+ const configFileExample = `d`;
119
+ export const customDefinitionsFile = `import type { ConverterFunctions, ValidationRules, AfterImportActions } from "appwrite-utils";
120
+
121
+ export const customConverterFunctions: ConverterFunctions = {
122
+ // Add your custom converter functions here
123
+ }
124
+ export const customValidationRules: ValidationRules = {
125
+ // Add your custom validation rules here
126
+ }
127
+ export const customAfterImportActions: AfterImportActions = {
128
+ // Add your custom after import actions here
129
+ }`;
130
+ export const createEmptyCollection = (collectionName) => {
131
+ const currentDir = process.cwd();
132
+ // Check for YAML config first (preferred)
133
+ const yamlConfigPath = findYamlConfig(currentDir);
134
+ const tsConfigPath = findAppwriteConfig(currentDir);
135
+ let configDir;
136
+ let isYamlProject = false;
137
+ if (yamlConfigPath) {
138
+ configDir = path.dirname(yamlConfigPath);
139
+ isYamlProject = true;
140
+ }
141
+ else if (tsConfigPath) {
142
+ configDir = path.dirname(tsConfigPath);
143
+ isYamlProject = false;
144
+ }
145
+ else {
146
+ // No config found - assume .appwrite directory and use YAML as default
147
+ configDir = path.join(currentDir, ".appwrite");
148
+ isYamlProject = true;
149
+ // Create .appwrite directory if it doesn't exist
150
+ if (!existsSync(configDir)) {
151
+ mkdirSync(configDir, { recursive: true });
152
+ }
153
+ }
154
+ const collectionsFolder = path.join(configDir, "collections");
155
+ if (!existsSync(collectionsFolder)) {
156
+ mkdirSync(collectionsFolder, { recursive: true });
157
+ }
158
+ if (isYamlProject) {
159
+ // Create YAML collection
160
+ const yamlCollection = `# yaml-language-server: $schema=../.yaml_schemas/collection.schema.json
161
+ # Collection Definition: ${collectionName}
162
+ name: ${collectionName}
163
+ id: ${ulid()}
164
+ documentSecurity: false
165
+ enabled: true
166
+ permissions:
167
+ - permission: read
168
+ target: any
169
+ - permission: create
170
+ target: users
171
+ - permission: update
172
+ target: users
173
+ - permission: delete
174
+ target: users
175
+ attributes:
176
+ # Add your attributes here
177
+ # Example:
178
+ # - key: title
179
+ # type: string
180
+ # size: 255
181
+ # required: true
182
+ # description: "The title of the item"
183
+ indexes:
184
+ # Add your indexes here
185
+ # Example:
186
+ # - key: title_search
187
+ # type: fulltext
188
+ # attributes:
189
+ # - title
190
+ importDefs: []
191
+ `;
192
+ const collectionFilePath = path.join(collectionsFolder, `${collectionName}.yaml`);
193
+ writeFileSync(collectionFilePath, yamlCollection);
194
+ MessageFormatter.success(`Created YAML collection: ${collectionFilePath}`, { prefix: "Setup" });
195
+ }
196
+ else {
197
+ // Create TypeScript collection
198
+ const emptyCollection = `import type { CollectionCreate } from "appwrite-utils";
199
+
200
+ const ${collectionName}: Partial<CollectionCreate> = {
201
+ $id: '${ulid()}',
202
+ documentSecurity: false,
203
+ enabled: true,
204
+ name: '${collectionName}',
205
+ $permissions: [
206
+ { permission: 'read', target: 'any' },
207
+ { permission: 'create', target: 'users' },
208
+ { permission: 'update', target: 'users' },
209
+ { permission: 'delete', target: 'users' }
210
+ ],
211
+ attributes: [
212
+ // Add more attributes here
213
+ ],
214
+ indexes: [
215
+ // Add more indexes here
216
+ ],
217
+ };
218
+
219
+ export default ${collectionName};`;
220
+ const collectionFilePath = path.join(collectionsFolder, `${collectionName}.ts`);
221
+ writeFileSync(collectionFilePath, emptyCollection);
222
+ MessageFormatter.success(`Created TypeScript collection: ${collectionFilePath}`, { prefix: "Setup" });
223
+ }
224
+ };
225
+ export const generateYamlConfig = (currentDir, useAppwriteDir = true) => {
226
+ const basePath = currentDir || process.cwd();
227
+ const configDir = useAppwriteDir ? path.join(basePath, ".appwrite") : basePath;
228
+ if (!existsSync(configDir)) {
229
+ mkdirSync(configDir, { recursive: true });
230
+ }
231
+ const configPath = path.join(configDir, "config.yaml");
232
+ generateYamlConfigTemplate(configPath);
233
+ MessageFormatter.success(`Generated YAML config template at: ${configPath}`, { prefix: "Setup" });
234
+ MessageFormatter.info("Please update the configuration with your Appwrite project details.", { prefix: "Setup" });
235
+ return configPath;
236
+ };
237
+ export const setupDirsFiles = async (example = false, currentDir, useYaml = true) => {
238
+ const basePath = currentDir || process.cwd();
239
+ // Create .appwrite folder directly in project root
240
+ const appwriteFolder = path.join(basePath, ".appwrite");
241
+ const appwriteConfigFile = path.join(appwriteFolder, "appwriteConfig.ts");
242
+ const appwriteCustomDefsFile = path.join(appwriteFolder, "customDefinitions.ts");
243
+ const appwriteSchemaFolder = path.join(appwriteFolder, "schemas");
244
+ const appwriteYamlSchemaFolder = path.join(appwriteFolder, ".yaml_schemas");
245
+ const appwriteDataFolder = path.join(appwriteFolder, "importData");
246
+ // Enhanced version detection with multiple sources
247
+ let useTables = false;
248
+ let detectionSource = "default";
249
+ try {
250
+ // Priority 1: Check for existing appwrite.json project config
251
+ const projectConfigPath = findAppwriteProjectConfig(basePath);
252
+ if (projectConfigPath) {
253
+ const projectConfig = loadAppwriteProjectConfig(projectConfigPath);
254
+ if (projectConfig) {
255
+ useTables = isTablesDBProject(projectConfig);
256
+ detectionSource = "appwrite.json";
257
+ MessageFormatter.info(`Detected ${useTables ? 'TablesDB' : 'Collections'} project from ${projectConfigPath}`, { prefix: "Setup" });
258
+ }
259
+ }
260
+ // Priority 2: Try reading existing YAML config for version detection
261
+ if (!useTables && detectionSource === "default") {
262
+ const yamlPath = findYamlConfig(basePath);
263
+ if (yamlPath) {
264
+ const cfg = await loadYamlConfig(yamlPath);
265
+ if (cfg) {
266
+ // Try session auth first, then API key for version detection
267
+ let endpoint = cfg.appwriteEndpoint;
268
+ let projectId = cfg.appwriteProject;
269
+ if (hasSessionAuth(endpoint, projectId)) {
270
+ MessageFormatter.info("Using session authentication for version detection", { prefix: "Setup" });
271
+ }
272
+ const ver = await fetchServerVersion(endpoint);
273
+ if (isVersionAtLeast(ver || undefined, '1.8.0')) {
274
+ useTables = true;
275
+ detectionSource = "server-version";
276
+ MessageFormatter.info(`Detected TablesDB support (Appwrite ${ver})`, { prefix: "Setup" });
277
+ }
278
+ else {
279
+ MessageFormatter.info(`Using Collections API (Appwrite ${ver || 'unknown'})`, { prefix: "Setup" });
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ catch (error) {
286
+ MessageFormatter.warning(`Version detection failed, defaulting to Collections API: ${error instanceof Error ? error.message : String(error)}`, { prefix: "Setup" });
287
+ }
288
+ const targetFolderName = useTables ? "tables" : "collections";
289
+ const collectionsFolder = path.join(appwriteFolder, targetFolderName);
290
+ // Create directory structure
291
+ if (!existsSync(appwriteFolder)) {
292
+ mkdirSync(appwriteFolder, { recursive: true });
293
+ }
294
+ if (!existsSync(collectionsFolder)) {
295
+ mkdirSync(collectionsFolder, { recursive: true });
296
+ }
297
+ // Handle configuration file creation - YAML is now default
298
+ if (useYaml) {
299
+ // Generate YAML config in .appwrite directory
300
+ const configPath = path.join(appwriteFolder, "config.yaml");
301
+ generateYamlConfigTemplate(configPath);
302
+ }
303
+ else if (!existsSync(appwriteConfigFile)) {
304
+ if (example) {
305
+ writeFileSync(appwriteConfigFile, configFileExample);
306
+ }
307
+ else {
308
+ const baseConfigContent = `import { type AppwriteConfig } from "appwrite-utils";
309
+
310
+ const appwriteConfig: AppwriteConfig = ${JSON.stringify(baseConfig, null, 2)};
311
+
312
+ export default appwriteConfig;
313
+ `;
314
+ writeFileSync(appwriteConfigFile, baseConfigContent);
315
+ }
316
+ }
317
+ // Create TypeScript files for each collection only if not using YAML
318
+ if (!useYaml) {
319
+ collectionsConfig.forEach((collection) => {
320
+ const collectionFilePath = path.join(collectionsFolder, `${collection.name}.ts`);
321
+ writeFileSync(collectionFilePath, collection.content);
322
+ });
323
+ }
324
+ // Create YAML collection/table example if using YAML config
325
+ if (useYaml) {
326
+ const terminology = useTables
327
+ ? {
328
+ container: "table",
329
+ fields: "columns",
330
+ security: "rowSecurity",
331
+ schemaRef: "table.schema.json",
332
+ containerName: "Table",
333
+ fieldName: "Column"
334
+ }
335
+ : {
336
+ container: "collection",
337
+ fields: "attributes",
338
+ security: "documentSecurity",
339
+ schemaRef: "collection.schema.json",
340
+ containerName: "Collection",
341
+ fieldName: "Attribute"
342
+ };
343
+ const yamlExample = `# yaml-language-server: $schema=../.yaml_schemas/${terminology.schemaRef}
344
+ # Example ${terminology.containerName} Definition
345
+ name: Example${terminology.containerName}
346
+ id: example_${terminology.container}_${Date.now()}
347
+ ${terminology.security}: false
348
+ enabled: true
349
+ permissions:
350
+ - permission: read
351
+ target: any
352
+ - permission: create
353
+ target: users
354
+ - permission: update
355
+ target: users
356
+ - permission: delete
357
+ target: users
358
+ ${terminology.fields}:
359
+ - key: title
360
+ type: string
361
+ size: 255
362
+ required: true
363
+ description: "The title of the item"
364
+ - key: description
365
+ type: string
366
+ size: 1000
367
+ required: false
368
+ description: "A longer description"
369
+ - key: isActive
370
+ type: boolean
371
+ required: false
372
+ default: true${useTables ? `
373
+ - key: uniqueCode
374
+ type: string
375
+ size: 50
376
+ required: false
377
+ unique: true
378
+ description: "Unique identifier code (TablesDB feature)"` : ''}
379
+ indexes:
380
+ - key: title_search
381
+ type: fulltext
382
+ attributes:
383
+ - title
384
+ importDefs: []
385
+ `;
386
+ const yamlExamplePath = path.join(collectionsFolder, `Example${terminology.containerName}.yaml`);
387
+ writeFileSync(yamlExamplePath, yamlExample);
388
+ MessageFormatter.info(`Created example ${terminology.container} definition with ${terminology.fields} terminology`, { prefix: "Setup" });
389
+ // Create JSON schema for collection/table definitions
390
+ const containerJsonSchema = useTables ? {
391
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
392
+ "$id": "https://appwrite-utils.dev/schemas/table.schema.json",
393
+ "title": "Appwrite Table Definition",
394
+ "description": "Schema for defining Appwrite tables in YAML (TablesDB API)",
395
+ "type": "object",
396
+ "properties": {
397
+ "name": {
398
+ "type": "string",
399
+ "description": "The name of the table"
400
+ },
401
+ "id": {
402
+ "type": "string",
403
+ "description": "The ID of the table (optional, auto-generated if not provided)",
404
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
405
+ },
406
+ "rowSecurity": {
407
+ "type": "boolean",
408
+ "default": false,
409
+ "description": "Enable row-level permissions"
410
+ },
411
+ "enabled": {
412
+ "type": "boolean",
413
+ "default": true,
414
+ "description": "Whether the table is enabled"
415
+ },
416
+ "permissions": {
417
+ "type": "array",
418
+ "description": "Table-level permissions",
419
+ "items": {
420
+ "type": "object",
421
+ "properties": {
422
+ "permission": {
423
+ "type": "string",
424
+ "enum": ["read", "create", "update", "delete"],
425
+ "description": "The permission type"
426
+ },
427
+ "target": {
428
+ "type": "string",
429
+ "description": "Permission target (e.g., 'any', 'users', 'users/verified', 'label:admin')"
430
+ }
431
+ },
432
+ "required": ["permission", "target"],
433
+ "additionalProperties": false
434
+ }
435
+ },
436
+ "columns": {
437
+ "type": "array",
438
+ "description": "Table columns (fields)",
439
+ "items": {
440
+ "type": "object",
441
+ "properties": {
442
+ "key": {
443
+ "type": "string",
444
+ "description": "Column name",
445
+ "pattern": "^[a-zA-Z][a-zA-Z0-9]*$"
446
+ },
447
+ "type": {
448
+ "type": "string",
449
+ "enum": ["string", "integer", "double", "boolean", "datetime", "email", "ip", "url", "enum", "relationship"],
450
+ "description": "Column data type"
451
+ },
452
+ "size": {
453
+ "type": "number",
454
+ "description": "Maximum size for string columns",
455
+ "minimum": 1,
456
+ "maximum": 1073741824
457
+ },
458
+ "required": {
459
+ "type": "boolean",
460
+ "default": false,
461
+ "description": "Whether the column is required"
462
+ },
463
+ "array": {
464
+ "type": "boolean",
465
+ "default": false,
466
+ "description": "Whether the column is an array"
467
+ },
468
+ "unique": {
469
+ "type": "boolean",
470
+ "default": false,
471
+ "description": "Whether the column values must be unique (TablesDB feature)"
472
+ },
473
+ "default": {
474
+ "description": "Default value for the column"
475
+ },
476
+ "description": {
477
+ "type": "string",
478
+ "description": "Column description"
479
+ },
480
+ "encrypt": {
481
+ "type": "boolean",
482
+ "description": "Whether the column should be encrypted"
483
+ },
484
+ "format": {
485
+ "type": "string",
486
+ "description": "Format for string columns"
487
+ },
488
+ "min": {
489
+ "type": "number",
490
+ "description": "Minimum value for numeric columns"
491
+ },
492
+ "max": {
493
+ "type": "number",
494
+ "description": "Maximum value for numeric columns"
495
+ },
496
+ "elements": {
497
+ "type": "array",
498
+ "items": {
499
+ "type": "string"
500
+ },
501
+ "description": "Allowed values for enum columns"
502
+ },
503
+ "relatedCollection": {
504
+ "type": "string",
505
+ "description": "Related table name for relationship columns"
506
+ },
507
+ "relationType": {
508
+ "type": "string",
509
+ "enum": ["oneToOne", "oneToMany", "manyToOne", "manyToMany"],
510
+ "description": "Type of relationship"
511
+ },
512
+ "twoWay": {
513
+ "type": "boolean",
514
+ "description": "Whether the relationship is bidirectional"
515
+ },
516
+ "twoWayKey": {
517
+ "type": "string",
518
+ "description": "Key name for the reverse relationship"
519
+ },
520
+ "onDelete": {
521
+ "type": "string",
522
+ "enum": ["cascade", "restrict", "setNull"],
523
+ "description": "Action to take when related row is deleted"
524
+ },
525
+ "side": {
526
+ "type": "string",
527
+ "enum": ["parent", "child"],
528
+ "description": "Side of the relationship"
529
+ }
530
+ },
531
+ "required": ["key", "type"],
532
+ "additionalProperties": false,
533
+ "allOf": [
534
+ {
535
+ "if": {
536
+ "properties": { "type": { "const": "enum" } }
537
+ },
538
+ "then": {
539
+ "required": ["elements"]
540
+ }
541
+ },
542
+ {
543
+ "if": {
544
+ "properties": { "type": { "const": "relationship" } }
545
+ },
546
+ "then": {
547
+ "required": ["relatedCollection", "relationType"]
548
+ }
549
+ }
550
+ ]
551
+ }
552
+ },
553
+ "indexes": {
554
+ "type": "array",
555
+ "description": "Database indexes for the table",
556
+ "items": {
557
+ "type": "object",
558
+ "properties": {
559
+ "key": {
560
+ "type": "string",
561
+ "description": "Index name"
562
+ },
563
+ "type": {
564
+ "type": "string",
565
+ "enum": ["key", "fulltext", "unique"],
566
+ "description": "Index type"
567
+ },
568
+ "attributes": {
569
+ "type": "array",
570
+ "items": {
571
+ "type": "string"
572
+ },
573
+ "description": "Columns to index",
574
+ "minItems": 1
575
+ },
576
+ "orders": {
577
+ "type": "array",
578
+ "items": {
579
+ "type": "string",
580
+ "enum": ["ASC", "DESC"]
581
+ },
582
+ "description": "Sort order for each column"
583
+ }
584
+ },
585
+ "required": ["key", "type", "attributes"],
586
+ "additionalProperties": false
587
+ }
588
+ },
589
+ "importDefs": {
590
+ "type": "array",
591
+ "description": "Import definitions for data migration",
592
+ "default": []
593
+ }
594
+ },
595
+ "required": ["name"],
596
+ "additionalProperties": false
597
+ } : {
598
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
599
+ "$id": "https://appwrite-utils.dev/schemas/collection.schema.json",
600
+ "title": "Appwrite Collection Definition",
601
+ "description": "Schema for defining Appwrite collections in YAML",
602
+ "type": "object",
603
+ "properties": {
604
+ "name": {
605
+ "type": "string",
606
+ "description": "The name of the collection"
607
+ },
608
+ "id": {
609
+ "type": "string",
610
+ "description": "The ID of the collection (optional, auto-generated if not provided)",
611
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
612
+ },
613
+ "documentSecurity": {
614
+ "type": "boolean",
615
+ "default": false,
616
+ "description": "Enable document-level permissions"
617
+ },
618
+ "enabled": {
619
+ "type": "boolean",
620
+ "default": true,
621
+ "description": "Whether the collection is enabled"
622
+ },
623
+ "permissions": {
624
+ "type": "array",
625
+ "description": "Collection-level permissions",
626
+ "items": {
627
+ "type": "object",
628
+ "properties": {
629
+ "permission": {
630
+ "type": "string",
631
+ "enum": ["read", "create", "update", "delete"],
632
+ "description": "The permission type"
633
+ },
634
+ "target": {
635
+ "type": "string",
636
+ "description": "Permission target (e.g., 'any', 'users', 'users/verified', 'label:admin')"
637
+ }
638
+ },
639
+ "required": ["permission", "target"],
640
+ "additionalProperties": false
641
+ }
642
+ },
643
+ "attributes": {
644
+ "type": "array",
645
+ "description": "Collection attributes (fields)",
646
+ "items": {
647
+ "type": "object",
648
+ "properties": {
649
+ "key": {
650
+ "type": "string",
651
+ "description": "Attribute name",
652
+ "pattern": "^[a-zA-Z][a-zA-Z0-9]*$"
653
+ },
654
+ "type": {
655
+ "type": "string",
656
+ "enum": ["string", "integer", "double", "boolean", "datetime", "email", "ip", "url", "enum", "relationship"],
657
+ "description": "Attribute data type"
658
+ },
659
+ "size": {
660
+ "type": "number",
661
+ "description": "Maximum size for string attributes",
662
+ "minimum": 1,
663
+ "maximum": 1073741824
664
+ },
665
+ "required": {
666
+ "type": "boolean",
667
+ "default": false,
668
+ "description": "Whether the attribute is required"
669
+ },
670
+ "array": {
671
+ "type": "boolean",
672
+ "default": false,
673
+ "description": "Whether the attribute is an array"
674
+ },
675
+ "default": {
676
+ "description": "Default value for the attribute"
677
+ },
678
+ "description": {
679
+ "type": "string",
680
+ "description": "Attribute description"
681
+ },
682
+ "encrypt": {
683
+ "type": "boolean",
684
+ "description": "Whether the attribute should be encrypted"
685
+ },
686
+ "format": {
687
+ "type": "string",
688
+ "description": "Format for string attributes"
689
+ },
690
+ "min": {
691
+ "type": "number",
692
+ "description": "Minimum value for numeric attributes"
693
+ },
694
+ "max": {
695
+ "type": "number",
696
+ "description": "Maximum value for numeric attributes"
697
+ },
698
+ "elements": {
699
+ "type": "array",
700
+ "items": {
701
+ "type": "string"
702
+ },
703
+ "description": "Allowed values for enum attributes"
704
+ },
705
+ "relatedCollection": {
706
+ "type": "string",
707
+ "description": "Related collection name for relationship attributes"
708
+ },
709
+ "relationType": {
710
+ "type": "string",
711
+ "enum": ["oneToOne", "oneToMany", "manyToOne", "manyToMany"],
712
+ "description": "Type of relationship"
713
+ },
714
+ "twoWay": {
715
+ "type": "boolean",
716
+ "description": "Whether the relationship is bidirectional"
717
+ },
718
+ "twoWayKey": {
719
+ "type": "string",
720
+ "description": "Key name for the reverse relationship"
721
+ },
722
+ "onDelete": {
723
+ "type": "string",
724
+ "enum": ["cascade", "restrict", "setNull"],
725
+ "description": "Action to take when related document is deleted"
726
+ },
727
+ "side": {
728
+ "type": "string",
729
+ "enum": ["parent", "child"],
730
+ "description": "Side of the relationship"
731
+ }
732
+ },
733
+ "required": ["key", "type"],
734
+ "additionalProperties": false,
735
+ "allOf": [
736
+ {
737
+ "if": {
738
+ "properties": { "type": { "const": "enum" } }
739
+ },
740
+ "then": {
741
+ "required": ["elements"]
742
+ }
743
+ },
744
+ {
745
+ "if": {
746
+ "properties": { "type": { "const": "relationship" } }
747
+ },
748
+ "then": {
749
+ "required": ["relatedCollection", "relationType"]
750
+ }
751
+ }
752
+ ]
753
+ }
754
+ },
755
+ "indexes": {
756
+ "type": "array",
757
+ "description": "Database indexes for the collection",
758
+ "items": {
759
+ "type": "object",
760
+ "properties": {
761
+ "key": {
762
+ "type": "string",
763
+ "description": "Index name"
764
+ },
765
+ "type": {
766
+ "type": "string",
767
+ "enum": ["key", "fulltext", "unique"],
768
+ "description": "Index type"
769
+ },
770
+ "attributes": {
771
+ "type": "array",
772
+ "items": {
773
+ "type": "string"
774
+ },
775
+ "description": "Attributes to index",
776
+ "minItems": 1
777
+ },
778
+ "orders": {
779
+ "type": "array",
780
+ "items": {
781
+ "type": "string",
782
+ "enum": ["ASC", "DESC"]
783
+ },
784
+ "description": "Sort order for each attribute"
785
+ }
786
+ },
787
+ "required": ["key", "type", "attributes"],
788
+ "additionalProperties": false
789
+ }
790
+ },
791
+ "importDefs": {
792
+ "type": "array",
793
+ "description": "Import definitions for data migration",
794
+ "default": []
795
+ }
796
+ },
797
+ "required": ["name"],
798
+ "additionalProperties": false
799
+ };
800
+ // Ensure YAML schemas directory exists before writing schema
801
+ if (!existsSync(appwriteYamlSchemaFolder)) {
802
+ mkdirSync(appwriteYamlSchemaFolder, { recursive: true });
803
+ }
804
+ const schemaFileName = useTables ? "table.schema.json" : "collection.schema.json";
805
+ const containerSchemaPath = path.join(appwriteYamlSchemaFolder, schemaFileName);
806
+ writeFileSync(containerSchemaPath, JSON.stringify(containerJsonSchema, null, 2));
807
+ // Create JSON schema for appwriteConfig.yaml
808
+ const configJsonSchema = {
809
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
810
+ "$id": "https://appwrite-utils.dev/schemas/appwrite-config.schema.json",
811
+ "title": "Appwrite Configuration",
812
+ "description": "Schema for Appwrite project configuration in YAML",
813
+ "type": "object",
814
+ "properties": {
815
+ "appwrite": {
816
+ "type": "object",
817
+ "description": "Appwrite connection settings",
818
+ "properties": {
819
+ "endpoint": {
820
+ "type": "string",
821
+ "default": "https://cloud.appwrite.io/v1",
822
+ "description": "Appwrite server endpoint URL"
823
+ },
824
+ "project": {
825
+ "type": "string",
826
+ "description": "Appwrite project ID"
827
+ },
828
+ "key": {
829
+ "type": "string",
830
+ "description": "Appwrite API key with appropriate permissions"
831
+ }
832
+ },
833
+ "required": ["project", "key"],
834
+ "additionalProperties": false
835
+ },
836
+ "logging": {
837
+ "type": "object",
838
+ "description": "Logging configuration",
839
+ "properties": {
840
+ "enabled": {
841
+ "type": "boolean",
842
+ "default": false,
843
+ "description": "Enable file logging"
844
+ },
845
+ "level": {
846
+ "type": "string",
847
+ "enum": ["error", "warn", "info", "debug"],
848
+ "default": "info",
849
+ "description": "Logging level"
850
+ },
851
+ "directory": {
852
+ "type": "string",
853
+ "description": "Custom log directory path (optional)"
854
+ },
855
+ "console": {
856
+ "type": "boolean",
857
+ "default": false,
858
+ "description": "Enable console logging"
859
+ }
860
+ },
861
+ "additionalProperties": false
862
+ },
863
+ "backups": {
864
+ "type": "object",
865
+ "description": "Backup configuration",
866
+ "properties": {
867
+ "enabled": {
868
+ "type": "boolean",
869
+ "default": true,
870
+ "description": "Enable automatic backups"
871
+ },
872
+ "interval": {
873
+ "type": "number",
874
+ "default": 3600,
875
+ "description": "Backup interval in seconds"
876
+ },
877
+ "retention": {
878
+ "type": "number",
879
+ "default": 30,
880
+ "description": "Backup retention in days"
881
+ },
882
+ "cleanup": {
883
+ "type": "boolean",
884
+ "default": true,
885
+ "description": "Enable automatic backup cleanup"
886
+ }
887
+ },
888
+ "additionalProperties": false
889
+ },
890
+ "data": {
891
+ "type": "object",
892
+ "description": "Data management settings",
893
+ "properties": {
894
+ "enableMockData": {
895
+ "type": "boolean",
896
+ "default": false,
897
+ "description": "Enable mock data generation"
898
+ },
899
+ "documentBucketId": {
900
+ "type": "string",
901
+ "default": "documents",
902
+ "description": "Default bucket ID for document attachments"
903
+ },
904
+ "usersCollectionName": {
905
+ "type": "string",
906
+ "default": "Members",
907
+ "description": "Name of the users/members collection"
908
+ },
909
+ "importDirectory": {
910
+ "type": "string",
911
+ "default": "importData",
912
+ "description": "Directory containing import data files"
913
+ }
914
+ },
915
+ "additionalProperties": false
916
+ },
917
+ "schemas": {
918
+ "type": "object",
919
+ "description": "Schema generation settings",
920
+ "properties": {
921
+ "outputDirectory": {
922
+ "type": "string",
923
+ "default": "schemas",
924
+ "description": "Directory where generated schemas are saved"
925
+ },
926
+ "yamlSchemaDirectory": {
927
+ "type": "string",
928
+ "default": ".yaml_schemas",
929
+ "description": "Directory containing YAML validation schemas"
930
+ }
931
+ },
932
+ "additionalProperties": false
933
+ },
934
+ "migrations": {
935
+ "type": "object",
936
+ "description": "Migration settings",
937
+ "properties": {
938
+ "enabled": {
939
+ "type": "boolean",
940
+ "default": true,
941
+ "description": "Enable migration tracking database"
942
+ }
943
+ },
944
+ "additionalProperties": false
945
+ },
946
+ "databases": {
947
+ "type": "array",
948
+ "description": "Database configurations",
949
+ "items": {
950
+ "type": "object",
951
+ "properties": {
952
+ "id": {
953
+ "type": "string",
954
+ "description": "Database ID",
955
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
956
+ },
957
+ "name": {
958
+ "type": "string",
959
+ "description": "Database display name"
960
+ },
961
+ "bucket": {
962
+ "type": "object",
963
+ "description": "Associated storage bucket",
964
+ "properties": {
965
+ "id": {
966
+ "type": "string",
967
+ "description": "Bucket ID"
968
+ },
969
+ "name": {
970
+ "type": "string",
971
+ "description": "Bucket display name"
972
+ },
973
+ "permissions": {
974
+ "type": "array",
975
+ "items": {
976
+ "type": "string"
977
+ },
978
+ "description": "Bucket permissions"
979
+ },
980
+ "fileSecurity": {
981
+ "type": "boolean",
982
+ "description": "Enable file-level security"
983
+ },
984
+ "enabled": {
985
+ "type": "boolean",
986
+ "default": true,
987
+ "description": "Enable the bucket"
988
+ },
989
+ "maximumFileSize": {
990
+ "type": "number",
991
+ "default": 30000000,
992
+ "description": "Maximum file size in bytes"
993
+ },
994
+ "allowedFileExtensions": {
995
+ "type": "array",
996
+ "items": {
997
+ "type": "string"
998
+ },
999
+ "description": "Allowed file extensions (empty = all allowed)"
1000
+ },
1001
+ "compression": {
1002
+ "type": "string",
1003
+ "enum": ["none", "gzip", "zstd"],
1004
+ "default": "none",
1005
+ "description": "Compression algorithm"
1006
+ },
1007
+ "encryption": {
1008
+ "type": "boolean",
1009
+ "default": false,
1010
+ "description": "Enable file encryption"
1011
+ },
1012
+ "antivirus": {
1013
+ "type": "boolean",
1014
+ "default": false,
1015
+ "description": "Enable antivirus scanning"
1016
+ }
1017
+ },
1018
+ "required": ["id", "name"],
1019
+ "additionalProperties": false
1020
+ }
1021
+ },
1022
+ "required": ["id", "name"],
1023
+ "additionalProperties": false
1024
+ }
1025
+ },
1026
+ "buckets": {
1027
+ "type": "array",
1028
+ "description": "Global storage buckets",
1029
+ "items": {
1030
+ "type": "object",
1031
+ "properties": {
1032
+ "id": {
1033
+ "type": "string",
1034
+ "description": "Bucket ID"
1035
+ },
1036
+ "name": {
1037
+ "type": "string",
1038
+ "description": "Bucket display name"
1039
+ },
1040
+ "permissions": {
1041
+ "type": "array",
1042
+ "items": {
1043
+ "type": "string"
1044
+ },
1045
+ "description": "Bucket permissions"
1046
+ },
1047
+ "fileSecurity": {
1048
+ "type": "boolean",
1049
+ "description": "Enable file-level security"
1050
+ },
1051
+ "enabled": {
1052
+ "type": "boolean",
1053
+ "default": true,
1054
+ "description": "Enable the bucket"
1055
+ },
1056
+ "maximumFileSize": {
1057
+ "type": "number",
1058
+ "default": 30000000,
1059
+ "description": "Maximum file size in bytes"
1060
+ },
1061
+ "allowedFileExtensions": {
1062
+ "type": "array",
1063
+ "items": {
1064
+ "type": "string"
1065
+ },
1066
+ "description": "Allowed file extensions (empty = all allowed)"
1067
+ },
1068
+ "compression": {
1069
+ "type": "string",
1070
+ "enum": ["none", "gzip", "zstd"],
1071
+ "default": "none",
1072
+ "description": "Compression algorithm"
1073
+ },
1074
+ "encryption": {
1075
+ "type": "boolean",
1076
+ "default": false,
1077
+ "description": "Enable file encryption"
1078
+ },
1079
+ "antivirus": {
1080
+ "type": "boolean",
1081
+ "default": false,
1082
+ "description": "Enable antivirus scanning"
1083
+ }
1084
+ },
1085
+ "required": ["id", "name"],
1086
+ "additionalProperties": false
1087
+ }
1088
+ },
1089
+ "functions": {
1090
+ "type": "array",
1091
+ "description": "Appwrite Functions",
1092
+ "items": {
1093
+ "type": "object",
1094
+ "properties": {
1095
+ "id": {
1096
+ "type": "string",
1097
+ "description": "Function ID"
1098
+ },
1099
+ "name": {
1100
+ "type": "string",
1101
+ "description": "Function name"
1102
+ },
1103
+ "runtime": {
1104
+ "type": "string",
1105
+ "description": "Runtime environment"
1106
+ },
1107
+ "execute": {
1108
+ "type": "array",
1109
+ "items": {
1110
+ "type": "string"
1111
+ },
1112
+ "description": "Execution permissions"
1113
+ },
1114
+ "events": {
1115
+ "type": "array",
1116
+ "items": {
1117
+ "type": "string"
1118
+ },
1119
+ "description": "Event triggers"
1120
+ },
1121
+ "schedule": {
1122
+ "type": "string",
1123
+ "description": "Cron schedule"
1124
+ },
1125
+ "timeout": {
1126
+ "type": "number",
1127
+ "default": 15,
1128
+ "description": "Execution timeout in seconds"
1129
+ },
1130
+ "enabled": {
1131
+ "type": "boolean",
1132
+ "default": true,
1133
+ "description": "Enable the function"
1134
+ },
1135
+ "logging": {
1136
+ "type": "boolean",
1137
+ "default": true,
1138
+ "description": "Enable function logging"
1139
+ },
1140
+ "entrypoint": {
1141
+ "type": "string",
1142
+ "description": "Function entrypoint file"
1143
+ },
1144
+ "commands": {
1145
+ "type": "string",
1146
+ "description": "Build commands"
1147
+ }
1148
+ },
1149
+ "required": ["id", "name", "runtime"],
1150
+ "additionalProperties": false
1151
+ }
1152
+ }
1153
+ },
1154
+ "required": ["appwrite"],
1155
+ "additionalProperties": false
1156
+ };
1157
+ const configSchemaPath = path.join(appwriteYamlSchemaFolder, "appwrite-config.schema.json");
1158
+ writeFileSync(configSchemaPath, JSON.stringify(configJsonSchema, null, 2));
1159
+ }
1160
+ if (!existsSync(appwriteSchemaFolder)) {
1161
+ mkdirSync(appwriteSchemaFolder, { recursive: true });
1162
+ }
1163
+ if (!existsSync(appwriteDataFolder)) {
1164
+ mkdirSync(appwriteDataFolder, { recursive: true });
1165
+ }
1166
+ // Remove the nested .appwrite folder creation since we're using .appwrite as the main folder
1167
+ const configType = useYaml ? "YAML" : "TypeScript";
1168
+ const terminology = useTables ? "tables" : "collections";
1169
+ const containerType = useTables ? "TablesDB" : "Collections";
1170
+ MessageFormatter.success(`Created ${configType} config and setup files/directories in .appwrite/ folder.`, { prefix: "Setup" });
1171
+ MessageFormatter.info(`Project configured for ${containerType} API (${detectionSource} detection)`, { prefix: "Setup" });
1172
+ if (useYaml) {
1173
+ MessageFormatter.info("You can now configure your project in .appwrite/config.yaml", { prefix: "Setup" });
1174
+ MessageFormatter.info(`${useTables ? 'Tables' : 'Collections'} can be defined in .appwrite/${terminology}/ as .ts or .yaml files`, { prefix: "Setup" });
1175
+ MessageFormatter.info("Schemas will be generated in .appwrite/schemas/", { prefix: "Setup" });
1176
+ MessageFormatter.info("Import data can be placed in .appwrite/importData/", { prefix: "Setup" });
1177
+ if (useTables) {
1178
+ MessageFormatter.info("TablesDB features: unique constraints, enhanced performance, row-level security", { prefix: "Setup" });
1179
+ }
1180
+ }
1181
+ else {
1182
+ MessageFormatter.info("You can now configure logging in your .appwrite/appwriteConfig.ts file:", { prefix: "Setup" });
1183
+ MessageFormatter.info(" logging: {", { prefix: "Setup" });
1184
+ MessageFormatter.info(" enabled: true,", { prefix: "Setup" });
1185
+ MessageFormatter.info(" level: 'info',", { prefix: "Setup" });
1186
+ MessageFormatter.info(" console: true,", { prefix: "Setup" });
1187
+ MessageFormatter.info(" logDirectory: './logs' // optional custom directory", { prefix: "Setup" });
1188
+ MessageFormatter.info(" }", { prefix: "Setup" });
1189
+ }
1190
+ };