appwrite-utils-cli 0.10.85 → 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 +261 -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 +196 -52
  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 +230 -63
  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
@@ -0,0 +1,215 @@
1
+ import cliProgress from "cli-progress";
2
+ import chalk from "chalk";
3
+ import { MessageFormatter } from "./messageFormatter.js";
4
+ export class ProgressManager {
5
+ static instances = new Map();
6
+ bar;
7
+ startTime;
8
+ totalItems;
9
+ completed = 0;
10
+ id;
11
+ title;
12
+ constructor(id, total, options = {}) {
13
+ this.id = id;
14
+ this.totalItems = total;
15
+ this.startTime = Date.now();
16
+ this.title = options.title || "Processing";
17
+ const format = options.format ||
18
+ `${chalk.cyan(this.title)} ${chalk.yellow("[{bar}]")} {percentage}% | {value}/{total} | ETA: {eta}s | Speed: {speed}/s`;
19
+ this.bar = new cliProgress.SingleBar({
20
+ format,
21
+ barCompleteChar: '█',
22
+ barIncompleteChar: '░',
23
+ hideCursor: true,
24
+ clearOnComplete: false,
25
+ stopOnComplete: true,
26
+ ...options,
27
+ }, cliProgress.Presets.shades_classic);
28
+ this.bar.start(total, 0);
29
+ }
30
+ static create(id, total, options = {}) {
31
+ if (ProgressManager.instances.has(id)) {
32
+ const existing = ProgressManager.instances.get(id);
33
+ existing.stop();
34
+ }
35
+ const instance = new ProgressManager(id, total, options);
36
+ ProgressManager.instances.set(id, instance);
37
+ return instance;
38
+ }
39
+ static get(id) {
40
+ return ProgressManager.instances.get(id);
41
+ }
42
+ update(current, detail) {
43
+ this.completed = current;
44
+ // Calculate speed
45
+ const elapsed = (Date.now() - this.startTime) / 1000;
46
+ const speed = elapsed > 0 ? Math.round(current / elapsed) : 0;
47
+ this.bar.update(current, {
48
+ speed,
49
+ detail: detail || '',
50
+ });
51
+ if (detail) {
52
+ // Update the payload for custom formatting
53
+ this.bar.update(current, { detail });
54
+ }
55
+ }
56
+ increment(amount = 1, detail) {
57
+ this.update(this.completed + amount, detail);
58
+ }
59
+ setTotal(total) {
60
+ this.totalItems = total;
61
+ this.bar.setTotal(total);
62
+ }
63
+ stop(showSummary = true) {
64
+ this.bar.stop();
65
+ if (showSummary) {
66
+ const duration = Date.now() - this.startTime;
67
+ const rate = this.completed / (duration / 1000);
68
+ MessageFormatter.success(`${this.title} completed`, {
69
+ prefix: `${this.completed}/${this.totalItems} items in ${MessageFormatter.formatDuration(duration)} (${rate.toFixed(1)}/s)`
70
+ });
71
+ }
72
+ ProgressManager.instances.delete(this.id);
73
+ }
74
+ fail(error) {
75
+ this.bar.stop();
76
+ MessageFormatter.error(`${this.title} failed: ${error}`);
77
+ ProgressManager.instances.delete(this.id);
78
+ }
79
+ getStats() {
80
+ const duration = Date.now() - this.startTime;
81
+ const rate = this.completed / (duration / 1000);
82
+ return {
83
+ completed: this.completed,
84
+ total: this.totalItems,
85
+ percentage: (this.completed / this.totalItems) * 100,
86
+ duration,
87
+ rate,
88
+ remaining: this.totalItems - this.completed,
89
+ eta: this.completed > 0 ? ((this.totalItems - this.completed) / rate) * 1000 : 0,
90
+ };
91
+ }
92
+ static stopAll() {
93
+ for (const [id, instance] of ProgressManager.instances) {
94
+ instance.stop(false);
95
+ }
96
+ ProgressManager.instances.clear();
97
+ }
98
+ }
99
+ export class MultiProgressManager {
100
+ multiBar;
101
+ bars = new Map();
102
+ startTime;
103
+ constructor(options = {}) {
104
+ this.startTime = Date.now();
105
+ this.multiBar = new cliProgress.MultiBar({
106
+ clearOnComplete: false,
107
+ hideCursor: true,
108
+ format: options.format || `${chalk.cyan("{title}")} ${chalk.yellow("[{bar}]")} {percentage}% | {value}/{total} | {detail}`,
109
+ barCompleteChar: '█',
110
+ barIncompleteChar: '░',
111
+ }, cliProgress.Presets.shades_classic);
112
+ }
113
+ addTask(id, total, title) {
114
+ const bar = this.multiBar.create(total, 0, {
115
+ title: title.padEnd(20),
116
+ detail: '',
117
+ });
118
+ this.bars.set(id, bar);
119
+ }
120
+ updateTask(id, current, detail) {
121
+ const bar = this.bars.get(id);
122
+ if (bar) {
123
+ bar.update(current, {
124
+ detail: detail || '',
125
+ });
126
+ }
127
+ }
128
+ incrementTask(id, amount = 1, detail) {
129
+ const bar = this.bars.get(id);
130
+ if (bar) {
131
+ const currentValue = bar.getProgress() * bar.getTotal();
132
+ this.updateTask(id, currentValue + amount, detail);
133
+ }
134
+ }
135
+ completeTask(id) {
136
+ const bar = this.bars.get(id);
137
+ if (bar) {
138
+ bar.update(bar.getTotal());
139
+ }
140
+ }
141
+ failTask(id, error) {
142
+ const bar = this.bars.get(id);
143
+ if (bar) {
144
+ bar.update(bar.getProgress() * bar.getTotal(), {
145
+ detail: chalk.red(`Failed: ${error}`),
146
+ });
147
+ }
148
+ }
149
+ stop(showSummary = true) {
150
+ this.multiBar.stop();
151
+ if (showSummary) {
152
+ const duration = Date.now() - this.startTime;
153
+ MessageFormatter.success(`All tasks completed in ${MessageFormatter.formatDuration(duration)}`);
154
+ }
155
+ }
156
+ getTaskStats(id) {
157
+ const bar = this.bars.get(id);
158
+ if (!bar)
159
+ return null;
160
+ const progress = bar.getProgress();
161
+ const total = bar.getTotal();
162
+ const completed = Math.floor(progress * total);
163
+ return {
164
+ completed,
165
+ total,
166
+ percentage: progress * 100,
167
+ remaining: total - completed,
168
+ };
169
+ }
170
+ getAllStats() {
171
+ const stats = new Map();
172
+ for (const [id, bar] of this.bars) {
173
+ stats.set(id, this.getTaskStats(id));
174
+ }
175
+ return stats;
176
+ }
177
+ }
178
+ // Utility functions for common progress scenarios
179
+ export const ProgressUtils = {
180
+ async withProgress(id, total, title, operation) {
181
+ const progress = ProgressManager.create(id, total, { title });
182
+ try {
183
+ const result = await operation(progress);
184
+ progress.stop();
185
+ return result;
186
+ }
187
+ catch (error) {
188
+ progress.fail(error instanceof Error ? error.message : String(error));
189
+ throw error;
190
+ }
191
+ },
192
+ async processArrayWithProgress(items, processor, options = {}) {
193
+ const { title = "Processing items", batchSize = 1, showDetail = true } = options;
194
+ const progress = ProgressManager.create(`process-${Date.now()}`, items.length, { title });
195
+ const results = [];
196
+ try {
197
+ for (let i = 0; i < items.length; i += batchSize) {
198
+ const batch = items.slice(i, i + batchSize);
199
+ const batchResults = await Promise.all(batch.map(async (item, batchIndex) => {
200
+ const result = await processor(item, i + batchIndex);
201
+ const detail = showDetail ? `Item ${i + batchIndex + 1}: ${String(item).slice(0, 30)}...` : undefined;
202
+ progress.update(i + batchIndex + 1, detail);
203
+ return result;
204
+ }));
205
+ results.push(...batchResults);
206
+ }
207
+ progress.stop();
208
+ return results;
209
+ }
210
+ catch (error) {
211
+ progress.fail(error instanceof Error ? error.message : String(error));
212
+ throw error;
213
+ }
214
+ },
215
+ };
@@ -0,0 +1,18 @@
1
+ import type { AppwriteConfig, Attribute } from "appwrite-utils";
2
+ export declare class SchemaGenerator {
3
+ private relationshipMap;
4
+ private config;
5
+ private appwriteFolderPath;
6
+ constructor(config: AppwriteConfig, appwriteFolderPath: string);
7
+ updateYamlCollections(): void;
8
+ updateTsSchemas(): void;
9
+ updateConfig(config: AppwriteConfig): void;
10
+ private extractRelationships;
11
+ private addRelationship;
12
+ generateSchemas(options?: {
13
+ format?: "zod" | "json" | "both";
14
+ verbose?: boolean;
15
+ }): void;
16
+ createSchemaString: (name: string, attributes: Attribute[]) => string;
17
+ typeToZod: (attribute: Attribute) => string;
18
+ }