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