appwrite-utils-cli 0.10.86 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
  2. package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
  3. package/.appwrite/collections/Categories.yaml +182 -0
  4. package/.appwrite/collections/ExampleCollection.yaml +36 -0
  5. package/.appwrite/collections/Posts.yaml +227 -0
  6. package/.appwrite/collections/Users.yaml +149 -0
  7. package/.appwrite/config.yaml +109 -0
  8. package/.appwrite/import/README.md +148 -0
  9. package/.appwrite/import/categories-import.yaml +129 -0
  10. package/.appwrite/import/posts-import.yaml +208 -0
  11. package/.appwrite/import/users-import.yaml +130 -0
  12. package/.appwrite/importData/categories.json +194 -0
  13. package/.appwrite/importData/posts.json +270 -0
  14. package/.appwrite/importData/users.json +220 -0
  15. package/.appwrite/schemas/categories.json +128 -0
  16. package/.appwrite/schemas/exampleCollection.json +52 -0
  17. package/.appwrite/schemas/posts.json +173 -0
  18. package/.appwrite/schemas/users.json +125 -0
  19. package/README.md +260 -33
  20. package/dist/collections/attributes.js +3 -2
  21. package/dist/collections/methods.js +56 -38
  22. package/dist/config/yamlConfig.d.ts +501 -0
  23. package/dist/config/yamlConfig.js +452 -0
  24. package/dist/databases/setup.d.ts +6 -0
  25. package/dist/databases/setup.js +119 -0
  26. package/dist/functions/methods.d.ts +1 -1
  27. package/dist/functions/methods.js +5 -2
  28. package/dist/functions/openapi.d.ts +4 -0
  29. package/dist/functions/openapi.js +60 -0
  30. package/dist/interactiveCLI.d.ts +5 -0
  31. package/dist/interactiveCLI.js +194 -49
  32. package/dist/main.js +91 -30
  33. package/dist/migrations/afterImportActions.js +2 -2
  34. package/dist/migrations/appwriteToX.d.ts +10 -0
  35. package/dist/migrations/appwriteToX.js +15 -4
  36. package/dist/migrations/backup.d.ts +16 -16
  37. package/dist/migrations/dataLoader.d.ts +83 -1
  38. package/dist/migrations/dataLoader.js +4 -4
  39. package/dist/migrations/importController.js +25 -18
  40. package/dist/migrations/importDataActions.js +2 -2
  41. package/dist/migrations/logging.d.ts +9 -1
  42. package/dist/migrations/logging.js +41 -22
  43. package/dist/migrations/migrationHelper.d.ts +4 -4
  44. package/dist/migrations/relationships.js +1 -1
  45. package/dist/migrations/services/DataTransformationService.d.ts +55 -0
  46. package/dist/migrations/services/DataTransformationService.js +158 -0
  47. package/dist/migrations/services/FileHandlerService.d.ts +75 -0
  48. package/dist/migrations/services/FileHandlerService.js +236 -0
  49. package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
  50. package/dist/migrations/services/ImportOrchestrator.js +488 -0
  51. package/dist/migrations/services/RateLimitManager.d.ts +138 -0
  52. package/dist/migrations/services/RateLimitManager.js +279 -0
  53. package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
  54. package/dist/migrations/services/RelationshipResolver.js +332 -0
  55. package/dist/migrations/services/UserMappingService.d.ts +109 -0
  56. package/dist/migrations/services/UserMappingService.js +277 -0
  57. package/dist/migrations/services/ValidationService.d.ts +74 -0
  58. package/dist/migrations/services/ValidationService.js +260 -0
  59. package/dist/migrations/transfer.d.ts +0 -6
  60. package/dist/migrations/transfer.js +16 -132
  61. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
  62. package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
  63. package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
  64. package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
  65. package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
  66. package/dist/migrations/yaml/generateImportSchemas.js +575 -0
  67. package/dist/schemas/authUser.d.ts +9 -9
  68. package/dist/shared/attributeManager.d.ts +17 -0
  69. package/dist/shared/attributeManager.js +273 -0
  70. package/dist/shared/confirmationDialogs.d.ts +75 -0
  71. package/dist/shared/confirmationDialogs.js +236 -0
  72. package/dist/shared/functionManager.d.ts +48 -0
  73. package/dist/shared/functionManager.js +322 -0
  74. package/dist/shared/indexManager.d.ts +24 -0
  75. package/dist/shared/indexManager.js +150 -0
  76. package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
  77. package/dist/shared/jsonSchemaGenerator.js +313 -0
  78. package/dist/shared/logging.d.ts +10 -0
  79. package/dist/shared/logging.js +46 -0
  80. package/dist/shared/messageFormatter.d.ts +37 -0
  81. package/dist/shared/messageFormatter.js +152 -0
  82. package/dist/shared/migrationHelpers.d.ts +173 -0
  83. package/dist/shared/migrationHelpers.js +142 -0
  84. package/dist/shared/operationLogger.d.ts +3 -0
  85. package/dist/shared/operationLogger.js +25 -0
  86. package/dist/shared/operationQueue.d.ts +13 -0
  87. package/dist/shared/operationQueue.js +79 -0
  88. package/dist/shared/progressManager.d.ts +62 -0
  89. package/dist/shared/progressManager.js +215 -0
  90. package/dist/shared/schemaGenerator.d.ts +18 -0
  91. package/dist/shared/schemaGenerator.js +523 -0
  92. package/dist/storage/methods.d.ts +3 -1
  93. package/dist/storage/methods.js +144 -55
  94. package/dist/storage/schemas.d.ts +56 -16
  95. package/dist/types.d.ts +2 -2
  96. package/dist/types.js +1 -1
  97. package/dist/users/methods.d.ts +16 -0
  98. package/dist/users/methods.js +276 -0
  99. package/dist/utils/configMigration.d.ts +1 -0
  100. package/dist/utils/configMigration.js +156 -0
  101. package/dist/utils/dataConverters.d.ts +46 -0
  102. package/dist/utils/dataConverters.js +139 -0
  103. package/dist/utils/loadConfigs.d.ts +15 -4
  104. package/dist/utils/loadConfigs.js +377 -51
  105. package/dist/utils/schemaStrings.js +2 -1
  106. package/dist/utils/setupFiles.d.ts +2 -1
  107. package/dist/utils/setupFiles.js +723 -28
  108. package/dist/utils/validationRules.d.ts +43 -0
  109. package/dist/utils/validationRules.js +42 -0
  110. package/dist/utils/yamlConverter.d.ts +48 -0
  111. package/dist/utils/yamlConverter.js +98 -0
  112. package/dist/utilsController.js +65 -43
  113. package/package.json +19 -15
  114. package/src/collections/attributes.ts +3 -2
  115. package/src/collections/methods.ts +85 -51
  116. package/src/config/yamlConfig.ts +488 -0
  117. package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
  118. package/src/functions/methods.ts +8 -4
  119. package/src/functions/templates/count-docs-in-collection/package.json +25 -0
  120. package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
  121. package/src/functions/templates/typescript-node/package.json +24 -0
  122. package/src/functions/templates/typescript-node/tsconfig.json +28 -0
  123. package/src/functions/templates/uv/README.md +31 -0
  124. package/src/functions/templates/uv/pyproject.toml +29 -0
  125. package/src/interactiveCLI.ts +226 -61
  126. package/src/main.ts +111 -37
  127. package/src/migrations/afterImportActions.ts +2 -2
  128. package/src/migrations/appwriteToX.ts +17 -4
  129. package/src/migrations/dataLoader.ts +4 -4
  130. package/src/migrations/importController.ts +30 -22
  131. package/src/migrations/importDataActions.ts +2 -2
  132. package/src/migrations/relationships.ts +1 -1
  133. package/src/migrations/services/DataTransformationService.ts +196 -0
  134. package/src/migrations/services/FileHandlerService.ts +311 -0
  135. package/src/migrations/services/ImportOrchestrator.ts +669 -0
  136. package/src/migrations/services/RateLimitManager.ts +363 -0
  137. package/src/migrations/services/RelationshipResolver.ts +461 -0
  138. package/src/migrations/services/UserMappingService.ts +345 -0
  139. package/src/migrations/services/ValidationService.ts +349 -0
  140. package/src/migrations/transfer.ts +22 -228
  141. package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
  142. package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
  143. package/src/migrations/yaml/generateImportSchemas.ts +589 -0
  144. package/src/shared/attributeManager.ts +429 -0
  145. package/src/shared/confirmationDialogs.ts +327 -0
  146. package/src/shared/functionManager.ts +515 -0
  147. package/src/shared/indexManager.ts +253 -0
  148. package/src/shared/jsonSchemaGenerator.ts +403 -0
  149. package/src/shared/logging.ts +74 -0
  150. package/src/shared/messageFormatter.ts +195 -0
  151. package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
  152. package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
  153. package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
  154. package/src/shared/progressManager.ts +278 -0
  155. package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
  156. package/src/storage/methods.ts +199 -78
  157. package/src/types.ts +2 -2
  158. package/src/{migrations/users.ts → users/methods.ts} +2 -2
  159. package/src/utils/configMigration.ts +212 -0
  160. package/src/utils/loadConfigs.ts +414 -52
  161. package/src/utils/schemaStrings.ts +2 -1
  162. package/src/utils/setupFiles.ts +742 -40
  163. package/src/{migrations → utils}/validationRules.ts +1 -1
  164. package/src/utils/yamlConverter.ts +131 -0
  165. package/src/utilsController.ts +75 -54
  166. package/src/functions/templates/poetry/README.md +0 -30
  167. package/src/functions/templates/poetry/pyproject.toml +0 -16
  168. package/src/migrations/attributes.ts +0 -561
  169. package/src/migrations/backup.ts +0 -205
  170. package/src/migrations/databases.ts +0 -39
  171. package/src/migrations/dbHelpers.ts +0 -92
  172. package/src/migrations/indexes.ts +0 -40
  173. package/src/migrations/logging.ts +0 -29
  174. package/src/migrations/storage.ts +0 -538
  175. /package/src/{migrations → functions}/openapi.ts +0 -0
  176. /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
  177. /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
  178. /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
@@ -4,84 +4,410 @@ import {} from "appwrite-utils";
4
4
  import { register } from "tsx/esm/api"; // Import the register function
5
5
  import { pathToFileURL } from "node:url";
6
6
  import chalk from "chalk";
7
+ import { findYamlConfig, loadYamlConfig } from "../config/yamlConfig.js";
8
+ import yaml from "js-yaml";
9
+ import { z } from "zod";
7
10
  /**
8
- * Recursively searches for a file named 'appwriteConfig.ts' starting from the given directory.
11
+ * Recursively searches for configuration files starting from the given directory.
12
+ * Priority: 1) YAML configs in .appwrite directories, 2) appwriteConfig.ts files in subdirectories
9
13
  * @param dir The directory to start the search from.
10
- * @returns The path to the file if found, or null if not found.
14
+ * @returns The directory path where the config was found, suitable for passing to loadConfig().
11
15
  */
12
16
  export const findAppwriteConfig = (dir) => {
13
- if (dir === "node_modules") {
17
+ // First try to find YAML config (already searches recursively for .appwrite dirs)
18
+ const yamlConfig = findYamlConfig(dir);
19
+ if (yamlConfig) {
20
+ // Return the directory containing the config file
21
+ return path.dirname(yamlConfig);
22
+ }
23
+ // Fall back to TypeScript config search
24
+ const tsConfigPath = findAppwriteConfigTS(dir);
25
+ if (tsConfigPath) {
26
+ return path.dirname(tsConfigPath);
27
+ }
28
+ return null;
29
+ };
30
+ const shouldIgnoreDirectory = (dirName) => {
31
+ const ignoredDirs = [
32
+ 'node_modules',
33
+ 'dist',
34
+ 'build',
35
+ 'coverage',
36
+ '.next',
37
+ '.nuxt',
38
+ '.cache',
39
+ '.git',
40
+ '.svn',
41
+ '.hg',
42
+ '__pycache__',
43
+ '.pytest_cache',
44
+ '.mypy_cache',
45
+ 'venv',
46
+ '.venv',
47
+ 'env',
48
+ '.env',
49
+ 'target',
50
+ 'out',
51
+ 'bin',
52
+ 'obj',
53
+ '.vs',
54
+ '.vscode',
55
+ '.idea',
56
+ 'temp',
57
+ 'tmp',
58
+ '.tmp',
59
+ 'logs',
60
+ 'log',
61
+ '.DS_Store',
62
+ 'Thumbs.db'
63
+ ];
64
+ return ignoredDirs.includes(dirName) ||
65
+ dirName.startsWith('.git') ||
66
+ dirName.startsWith('node_modules') ||
67
+ dirName.startsWith('.');
68
+ };
69
+ const findAppwriteConfigTS = (dir, depth = 0) => {
70
+ // Limit search depth to prevent infinite recursion
71
+ if (depth > 5) {
14
72
  return null;
15
73
  }
16
- const files = fs.readdirSync(dir, { withFileTypes: true });
17
- for (const file of files) {
18
- if (file.isDirectory() && file.name !== "node_modules") {
19
- const result = findAppwriteConfig(path.join(dir, file.name));
20
- if (result)
21
- return result;
74
+ if (shouldIgnoreDirectory(path.basename(dir))) {
75
+ return null;
76
+ }
77
+ try {
78
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
79
+ // First check current directory for appwriteConfig.ts
80
+ for (const entry of entries) {
81
+ if (entry.isFile() && entry.name === "appwriteConfig.ts") {
82
+ return path.join(dir, entry.name);
83
+ }
22
84
  }
23
- else if (file.name === "appwriteConfig.ts") {
24
- return path.join(dir, file.name);
85
+ // Then search subdirectories
86
+ for (const entry of entries) {
87
+ if (entry.isDirectory() && !shouldIgnoreDirectory(entry.name)) {
88
+ const result = findAppwriteConfigTS(path.join(dir, entry.name), depth + 1);
89
+ if (result)
90
+ return result;
91
+ }
25
92
  }
26
93
  }
94
+ catch (error) {
95
+ // Ignore directory access errors
96
+ }
27
97
  return null;
28
98
  };
99
+ /**
100
+ * Loads the Appwrite configuration and returns both config and the path where it was found.
101
+ * @param configDir The directory to search for config files.
102
+ * @returns Object containing the config and the actual path where it was found.
103
+ */
104
+ export const loadConfigWithPath = async (configDir) => {
105
+ let config = null;
106
+ let actualConfigPath = null;
107
+ // Check if we're given the .appwrite directory directly
108
+ if (configDir.endsWith('.appwrite')) {
109
+ // Look for config files directly in this directory
110
+ const possibleYamlFiles = ['config.yaml', 'config.yml', 'appwriteConfig.yaml', 'appwriteConfig.yml'];
111
+ for (const fileName of possibleYamlFiles) {
112
+ const yamlPath = path.join(configDir, fileName);
113
+ if (fs.existsSync(yamlPath)) {
114
+ config = await loadYamlConfig(yamlPath);
115
+ actualConfigPath = yamlPath;
116
+ break;
117
+ }
118
+ }
119
+ }
120
+ else {
121
+ // Original logic: search for .appwrite directories
122
+ const yamlConfigPath = findYamlConfig(configDir);
123
+ if (yamlConfigPath) {
124
+ config = await loadYamlConfig(yamlConfigPath);
125
+ actualConfigPath = yamlConfigPath;
126
+ }
127
+ }
128
+ // Fall back to TypeScript config if YAML not found or failed to load
129
+ if (!config) {
130
+ const configPath = path.join(configDir, "appwriteConfig.ts");
131
+ // Only try to load TypeScript config if the file exists
132
+ if (fs.existsSync(configPath)) {
133
+ const unregister = register(); // Register tsx enhancement
134
+ try {
135
+ console.log(`Loading TypeScript config from: ${configPath}`);
136
+ const configUrl = pathToFileURL(configPath).href;
137
+ const configModule = (await import(configUrl));
138
+ config = configModule.default?.default || configModule.default || configModule;
139
+ if (!config) {
140
+ throw new Error("Failed to load config");
141
+ }
142
+ actualConfigPath = configPath;
143
+ }
144
+ finally {
145
+ unregister(); // Unregister tsx when done
146
+ }
147
+ }
148
+ }
149
+ if (!config || !actualConfigPath) {
150
+ throw new Error("No valid configuration found");
151
+ }
152
+ // Determine collections directory based on actual config file location
153
+ let collectionsDir;
154
+ const configFileDir = path.dirname(actualConfigPath);
155
+ // Check if config is in .appwrite directory
156
+ if (configFileDir.endsWith('.appwrite')) {
157
+ collectionsDir = path.join(configFileDir, "collections");
158
+ }
159
+ else {
160
+ // Config is in root or other directory
161
+ collectionsDir = path.join(configFileDir, "collections");
162
+ }
163
+ // Load collections if they exist
164
+ if (fs.existsSync(collectionsDir)) {
165
+ const unregister = register(); // Register tsx for collections
166
+ try {
167
+ const collectionFiles = fs.readdirSync(collectionsDir);
168
+ config.collections = [];
169
+ for (const file of collectionFiles) {
170
+ if (file === "index.ts") {
171
+ continue;
172
+ }
173
+ const filePath = path.join(collectionsDir, file);
174
+ // Handle YAML collections
175
+ if (file.endsWith('.yaml') || file.endsWith('.yml')) {
176
+ const collection = loadYamlCollection(filePath);
177
+ if (collection) {
178
+ config.collections.push(collection);
179
+ }
180
+ continue;
181
+ }
182
+ // Handle TypeScript collections
183
+ if (file.endsWith('.ts')) {
184
+ const fileUrl = pathToFileURL(filePath).href;
185
+ const collectionModule = (await import(fileUrl));
186
+ const collection = collectionModule.default?.default || collectionModule.default || collectionModule;
187
+ if (collection) {
188
+ // Ensure importDefs are properly loaded
189
+ if (collectionModule.importDefs || collection.importDefs) {
190
+ collection.importDefs = collectionModule.importDefs || collection.importDefs;
191
+ }
192
+ config.collections.push(collection);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ finally {
198
+ unregister(); // Unregister tsx when done
199
+ }
200
+ }
201
+ return { config, actualConfigPath };
202
+ };
29
203
  /**
30
204
  * Loads the Appwrite configuration and all collection configurations from a specified directory.
31
- * @param configDir The directory containing the appwriteConfig.ts and collections folder.
205
+ * Supports both YAML and TypeScript config formats with backward compatibility.
206
+ * @param configDir The directory containing the config file and collections folder.
32
207
  * @returns The loaded Appwrite configuration including collections.
33
208
  */
34
209
  export const loadConfig = async (configDir) => {
35
- const unregister = register(); // Register tsx enhancement
36
- try {
210
+ let config = null;
211
+ let actualConfigPath = null;
212
+ // First try to find and load YAML config
213
+ const yamlConfigPath = findYamlConfig(configDir);
214
+ if (yamlConfigPath) {
215
+ console.log(`Loading YAML config from: ${yamlConfigPath}`);
216
+ config = await loadYamlConfig(yamlConfigPath);
217
+ actualConfigPath = yamlConfigPath;
218
+ }
219
+ // Fall back to TypeScript config if YAML not found or failed to load
220
+ if (!config) {
37
221
  const configPath = path.join(configDir, "appwriteConfig.ts");
38
- console.log(`Loading config from: ${configPath}`);
39
- const configUrl = pathToFileURL(configPath).href;
40
- const configModule = (await import(configUrl));
41
- const config = configModule.default?.default || configModule.default || configModule;
42
- if (!config) {
43
- throw new Error("Failed to load config");
44
- }
45
- const collectionsDir = path.join(configDir, "collections");
46
- const collectionFiles = fs.readdirSync(collectionsDir);
47
- config.collections = [];
48
- for (const file of collectionFiles) {
49
- if (file === "index.ts") {
50
- continue;
222
+ // Only try to load TypeScript config if the file exists
223
+ if (fs.existsSync(configPath)) {
224
+ const unregister = register(); // Register tsx enhancement
225
+ try {
226
+ console.log(`Loading TypeScript config from: ${configPath}`);
227
+ const configUrl = pathToFileURL(configPath).href;
228
+ const configModule = (await import(configUrl));
229
+ config = configModule.default?.default || configModule.default || configModule;
230
+ if (!config) {
231
+ throw new Error("Failed to load config");
232
+ }
233
+ actualConfigPath = configPath;
234
+ }
235
+ finally {
236
+ unregister(); // Unregister tsx when done
51
237
  }
52
- const filePath = path.join(collectionsDir, file);
53
- const fileUrl = pathToFileURL(filePath).href;
54
- const collectionModule = (await import(fileUrl));
55
- const collection = collectionModule.default?.default || collectionModule.default || collectionModule;
56
- if (collection) {
57
- // Ensure importDefs are properly loaded
58
- if (collectionModule.importDefs || collection.importDefs) {
59
- collection.importDefs = collectionModule.importDefs || collection.importDefs;
238
+ }
239
+ }
240
+ if (!config) {
241
+ throw new Error("No valid configuration found");
242
+ }
243
+ // Determine collections directory based on actual config file location
244
+ let collectionsDir;
245
+ if (actualConfigPath) {
246
+ const configFileDir = path.dirname(actualConfigPath);
247
+ // Check if config is in .appwrite directory
248
+ if (configFileDir.endsWith('.appwrite')) {
249
+ collectionsDir = path.join(configFileDir, "collections");
250
+ }
251
+ else {
252
+ // Config is in root or other directory
253
+ collectionsDir = path.join(configFileDir, "collections");
254
+ }
255
+ }
256
+ else {
257
+ // Fallback to original behavior if no actual config path found
258
+ collectionsDir = path.join(configDir, "collections");
259
+ }
260
+ // Load collections if they exist
261
+ if (fs.existsSync(collectionsDir)) {
262
+ const unregister = register(); // Register tsx for collections
263
+ try {
264
+ const collectionFiles = fs.readdirSync(collectionsDir);
265
+ config.collections = [];
266
+ for (const file of collectionFiles) {
267
+ if (file === "index.ts") {
268
+ continue;
269
+ }
270
+ const filePath = path.join(collectionsDir, file);
271
+ // Handle YAML collections
272
+ if (file.endsWith('.yaml') || file.endsWith('.yml')) {
273
+ const collection = loadYamlCollection(filePath);
274
+ if (collection) {
275
+ config.collections.push(collection);
276
+ }
277
+ continue;
278
+ }
279
+ // Handle TypeScript collections
280
+ if (file.endsWith('.ts')) {
281
+ const fileUrl = pathToFileURL(filePath).href;
282
+ const collectionModule = (await import(fileUrl));
283
+ const collection = collectionModule.default?.default || collectionModule.default || collectionModule;
284
+ if (collection) {
285
+ // Ensure importDefs are properly loaded
286
+ if (collectionModule.importDefs || collection.importDefs) {
287
+ collection.importDefs = collectionModule.importDefs || collection.importDefs;
288
+ }
289
+ config.collections.push(collection);
290
+ }
60
291
  }
61
- config.collections.push(collection);
62
292
  }
63
293
  }
64
- return config;
294
+ finally {
295
+ unregister(); // Unregister tsx when done
296
+ }
65
297
  }
66
- finally {
67
- unregister(); // Unregister tsx when done
298
+ else {
299
+ config.collections = config.collections || [];
68
300
  }
301
+ return config;
69
302
  };
70
- export const findFunctionsDir = (dir) => {
71
- if (dir === "node_modules") {
303
+ export const findFunctionsDir = (dir, depth = 0) => {
304
+ // Limit search depth to prevent infinite recursion
305
+ if (depth > 5) {
72
306
  return null;
73
307
  }
74
- const files = fs.readdirSync(dir, { withFileTypes: true });
75
- for (const entry of files) {
76
- if (!entry.isDirectory() || entry.name === "node_modules") {
77
- continue;
78
- }
79
- if (entry.name === "functions") {
80
- return path.join(dir, entry.name);
308
+ if (shouldIgnoreDirectory(path.basename(dir))) {
309
+ return null;
310
+ }
311
+ try {
312
+ const files = fs.readdirSync(dir, { withFileTypes: true });
313
+ for (const entry of files) {
314
+ if (!entry.isDirectory() || shouldIgnoreDirectory(entry.name)) {
315
+ continue;
316
+ }
317
+ if (entry.name === "functions") {
318
+ return path.join(dir, entry.name);
319
+ }
320
+ const result = findFunctionsDir(path.join(dir, entry.name), depth + 1);
321
+ if (result)
322
+ return result;
81
323
  }
82
- const result = findFunctionsDir(path.join(dir, entry.name));
83
- if (result)
84
- return result;
324
+ }
325
+ catch (error) {
326
+ // Ignore directory access errors
85
327
  }
86
328
  return null;
87
329
  };
330
+ // YAML Collection Schema
331
+ const YamlCollectionSchema = z.object({
332
+ name: z.string(),
333
+ id: z.string().optional(),
334
+ documentSecurity: z.boolean().default(false),
335
+ enabled: z.boolean().default(true),
336
+ permissions: z.array(z.object({
337
+ permission: z.string(),
338
+ target: z.string()
339
+ })).optional().default([]),
340
+ attributes: z.array(z.object({
341
+ key: z.string(),
342
+ type: z.string(),
343
+ size: z.number().optional(),
344
+ required: z.boolean().default(false),
345
+ array: z.boolean().optional(),
346
+ default: z.any().optional(),
347
+ description: z.string().optional(),
348
+ min: z.number().optional(),
349
+ max: z.number().optional(),
350
+ elements: z.array(z.string()).optional(),
351
+ relatedCollection: z.string().optional(),
352
+ relationType: z.string().optional(),
353
+ twoWay: z.boolean().optional(),
354
+ twoWayKey: z.string().optional(),
355
+ onDelete: z.string().optional(),
356
+ side: z.string().optional()
357
+ })).optional().default([]),
358
+ indexes: z.array(z.object({
359
+ key: z.string(),
360
+ type: z.string(),
361
+ attributes: z.array(z.string()),
362
+ orders: z.array(z.string()).optional()
363
+ })).optional().default([]),
364
+ importDefs: z.array(z.any()).optional().default([])
365
+ });
366
+ const loadYamlCollection = (filePath) => {
367
+ try {
368
+ const fileContent = fs.readFileSync(filePath, "utf8");
369
+ const yamlData = yaml.load(fileContent);
370
+ const parsedCollection = YamlCollectionSchema.parse(yamlData);
371
+ // Convert YAML collection to CollectionCreate format
372
+ const collection = {
373
+ name: parsedCollection.name,
374
+ $id: parsedCollection.id || parsedCollection.name.toLowerCase().replace(/\s+/g, '_'),
375
+ documentSecurity: parsedCollection.documentSecurity,
376
+ enabled: parsedCollection.enabled,
377
+ $permissions: parsedCollection.permissions.map(p => ({
378
+ permission: p.permission,
379
+ target: p.target
380
+ })),
381
+ attributes: parsedCollection.attributes.map(attr => ({
382
+ key: attr.key,
383
+ type: attr.type,
384
+ size: attr.size,
385
+ required: attr.required,
386
+ array: attr.array,
387
+ xdefault: attr.default,
388
+ description: attr.description,
389
+ min: attr.min,
390
+ max: attr.max,
391
+ elements: attr.elements,
392
+ relatedCollection: attr.relatedCollection,
393
+ relationType: attr.relationType,
394
+ twoWay: attr.twoWay,
395
+ twoWayKey: attr.twoWayKey,
396
+ onDelete: attr.onDelete,
397
+ side: attr.side
398
+ })),
399
+ indexes: parsedCollection.indexes.map(idx => ({
400
+ key: idx.key,
401
+ type: idx.type,
402
+ attributes: idx.attributes,
403
+ orders: idx.orders
404
+ })),
405
+ importDefs: parsedCollection.importDefs
406
+ };
407
+ return collection;
408
+ }
409
+ catch (error) {
410
+ console.error(`Error loading YAML collection from ${filePath}:`, error);
411
+ return null;
412
+ }
413
+ };
@@ -337,7 +337,8 @@ export class SchemaGenerator {
337
337
  baseSchemaCode += ".nullish()";
338
338
  }
339
339
  break;
340
- case "float":
340
+ case "double":
341
+ case "float": // Backward compatibility
341
342
  baseSchemaCode = "z.number()";
342
343
  if (finalAttribute.min !== undefined) {
343
344
  baseSchemaCode += `.min(${finalAttribute.min}, "Minimum value of ${finalAttribute.min} not met")`;
@@ -1,3 +1,4 @@
1
1
  export declare const customDefinitionsFile = "import type { ConverterFunctions, ValidationRules, AfterImportActions } from \"appwrite-utils\";\n\nexport const customConverterFunctions: ConverterFunctions = {\n // Add your custom converter functions here\n}\nexport const customValidationRules: ValidationRules = {\n // Add your custom validation rules here\n}\nexport const customAfterImportActions: AfterImportActions = {\n // Add your custom after import actions here\n}";
2
2
  export declare const createEmptyCollection: (collectionName: string) => void;
3
- export declare const setupDirsFiles: (example?: boolean, currentDir?: string) => Promise<void>;
3
+ export declare const generateYamlConfig: (currentDir?: string, useAppwriteDir?: boolean) => string;
4
+ export declare const setupDirsFiles: (example?: boolean, currentDir?: string, useYaml?: boolean) => Promise<void>;