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,205 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- attributeSchema,
4
- type Attribute,
5
- parseAttribute,
6
- CollectionCreateSchema,
7
- } from "appwrite-utils";
8
-
9
- export const BackupSchema = z.object({
10
- $id: z.string(),
11
- $createdAt: z.string(),
12
- $updatedAt: z.string(),
13
- database: z.string(),
14
- collections: z.array(z.string()),
15
- documents: z
16
- .array(
17
- z.object({
18
- collectionId: z.string(),
19
- data: z.string(),
20
- })
21
- )
22
- .default([]),
23
- });
24
-
25
- export type Backup = z.infer<typeof BackupSchema>;
26
-
27
- export const BackupCreateSchema = BackupSchema.omit({
28
- $id: true,
29
- $createdAt: true,
30
- $updatedAt: true,
31
- });
32
-
33
- export type BackupCreate = z.infer<typeof BackupCreateSchema>;
34
-
35
- export const BatchSchema = z.object({
36
- $id: z.string(),
37
- $createdAt: z.string(),
38
- $updatedAt: z.string(),
39
- data: z.string().describe("The serialized data for this batch"),
40
- processed: z
41
- .boolean()
42
- .default(false)
43
- .describe("Whether the batch has been processed"),
44
- });
45
-
46
- export type Batch = z.infer<typeof BatchSchema>;
47
-
48
- export const BatchCreateSchema = BatchSchema.omit({
49
- $id: true,
50
- $createdAt: true,
51
- $updatedAt: true,
52
- });
53
-
54
- export type BatchCreate = z.infer<typeof BatchCreateSchema>;
55
-
56
- export const OperationSchema = z.object({
57
- $id: z.string(),
58
- $createdAt: z.string(),
59
- $updatedAt: z.string(),
60
- operationType: z.string(),
61
- collectionId: z.string(),
62
- data: z.any(),
63
- batches: z.array(z.string()).default([]).optional(),
64
- progress: z.number(),
65
- total: z.number(),
66
- error: z.string(),
67
- status: z
68
- .enum([
69
- "pending",
70
- "ready",
71
- "in_progress",
72
- "completed",
73
- "error",
74
- "cancelled",
75
- ])
76
- .default("pending"),
77
- });
78
-
79
- export type Operation = z.infer<typeof OperationSchema>;
80
-
81
- export const OperationCreateSchema = OperationSchema.omit({
82
- $id: true,
83
- $createdAt: true,
84
- $updatedAt: true,
85
- });
86
-
87
- export type OperationCreate = z.infer<typeof OperationCreateSchema>;
88
-
89
- export const getMigrationCollectionSchemas = () => {
90
- const currentOperationsAttributes: Attribute[] = [
91
- parseAttribute({
92
- key: "operationType",
93
- type: "string",
94
- error: "Invalid Operation Type",
95
- size: 50,
96
- required: true,
97
- array: false,
98
- xdefault: null,
99
- }),
100
- attributeSchema.parse({
101
- key: "collectionId",
102
- type: "string",
103
- error: "Invalid Collection Id",
104
- size: 50,
105
- array: false,
106
- xdefault: null,
107
- }),
108
- attributeSchema.parse({
109
- key: "batches",
110
- type: "string",
111
- error: "Invalid Batches",
112
- size: 1073741824,
113
- array: true,
114
- }),
115
- attributeSchema.parse({
116
- key: "data",
117
- type: "string",
118
- error: "Invalid Data",
119
- size: 1073741824,
120
- }),
121
- attributeSchema.parse({
122
- key: "progress",
123
- type: "integer",
124
- error: "Invalid Progress",
125
- required: true,
126
- array: false,
127
- }),
128
- attributeSchema.parse({
129
- key: "total",
130
- type: "integer",
131
- error: "Invalid Total",
132
- required: true,
133
- array: false,
134
- }),
135
- attributeSchema.parse({
136
- key: "error",
137
- type: "string",
138
- error: "Operation Error",
139
- required: false,
140
- array: false,
141
- }),
142
- attributeSchema.parse({
143
- key: "status",
144
- type: "enum",
145
- elements: [
146
- "pending",
147
- "ready",
148
- "in_progress",
149
- "completed",
150
- "error",
151
- "cancelled",
152
- ],
153
- error: "Invalid Status",
154
- array: false,
155
- xdefault: "pending",
156
- }),
157
- ];
158
-
159
- const currentOperationsConfig = CollectionCreateSchema.parse({
160
- name: "CurrentOperations",
161
- enabled: true,
162
- documentSecurity: false,
163
- attributes: [],
164
- indexes: [],
165
- });
166
-
167
- const batchesAttributes: Attribute[] = [
168
- attributeSchema.parse({
169
- key: "data",
170
- type: "string",
171
- size: 1073741824,
172
- error: "Invalid Data",
173
- required: true,
174
- array: false,
175
- }),
176
- attributeSchema.parse({
177
- key: "processed",
178
- type: "boolean",
179
- error: "Invalid Processed",
180
- required: true,
181
- array: false,
182
- xdefault: false,
183
- }),
184
- ];
185
-
186
- const batchesConfig = CollectionCreateSchema.parse({
187
- name: "Batches",
188
- enabled: true,
189
- documentSecurity: false,
190
- attributes: [],
191
- indexes: [],
192
- });
193
-
194
- const toReturn = {
195
- CurrentOperations: {
196
- collection: currentOperationsConfig,
197
- attributes: currentOperationsAttributes,
198
- },
199
- Batches: {
200
- collection: batchesConfig,
201
- attributes: batchesAttributes,
202
- },
203
- };
204
- return toReturn;
205
- };
@@ -1,409 +0,0 @@
1
- import type { Index } from "appwrite-utils";
2
- import type { DatabaseAdapter } from "appwrite-utils-helpers";
3
- import type { Models } from "node-appwrite";
4
- import { isIndexEqualToIndex } from "../collections/tableOperations.js";
5
- import { MessageFormatter } from "appwrite-utils-helpers";
6
- import { delay, tryAwaitWithRetry } from "appwrite-utils-helpers";
7
-
8
- // Enhanced index operation interfaces
9
- export interface IndexOperation {
10
- type: 'create' | 'update' | 'skip' | 'delete';
11
- index: Index;
12
- existingIndex?: Models.Index;
13
- reason?: string;
14
- }
15
-
16
- export interface IndexOperationPlan {
17
- toCreate: IndexOperation[];
18
- toUpdate: IndexOperation[];
19
- toSkip: IndexOperation[];
20
- toDelete: IndexOperation[];
21
- }
22
-
23
- export interface IndexExecutionResult {
24
- created: string[];
25
- updated: string[];
26
- skipped: string[];
27
- deleted: string[];
28
- errors: Array<{ key: string; error: string }>;
29
- summary: {
30
- total: number;
31
- created: number;
32
- updated: number;
33
- skipped: number;
34
- deleted: number;
35
- errors: number;
36
- };
37
- }
38
-
39
- /**
40
- * Plan index operations by comparing desired indexes with existing ones
41
- * Uses the existing isIndexEqualToIndex function for consistent comparison
42
- */
43
- export function planIndexOperations(
44
- desiredIndexes: Index[],
45
- existingIndexes: Models.Index[]
46
- ): IndexOperationPlan {
47
- const plan: IndexOperationPlan = {
48
- toCreate: [],
49
- toUpdate: [],
50
- toSkip: [],
51
- toDelete: []
52
- };
53
-
54
- for (const desiredIndex of desiredIndexes) {
55
- const existingIndex = existingIndexes.find(idx => idx.key === desiredIndex.key);
56
-
57
- if (!existingIndex) {
58
- // Index doesn't exist - create it
59
- plan.toCreate.push({
60
- type: 'create',
61
- index: desiredIndex,
62
- reason: 'New index'
63
- });
64
- } else if (isIndexEqualToIndex(existingIndex, desiredIndex)) {
65
- // Index exists and is identical - skip it
66
- plan.toSkip.push({
67
- type: 'skip',
68
- index: desiredIndex,
69
- existingIndex,
70
- reason: 'Index unchanged'
71
- });
72
- } else {
73
- // Index exists but is different - update it
74
- plan.toUpdate.push({
75
- type: 'update',
76
- index: desiredIndex,
77
- existingIndex,
78
- reason: 'Index configuration changed'
79
- });
80
- }
81
- }
82
-
83
- return plan;
84
- }
85
-
86
- /**
87
- * Plan index deletions for indexes that exist but aren't in the desired configuration
88
- */
89
- export function planIndexDeletions(
90
- desiredIndexKeys: Set<string>,
91
- existingIndexes: Models.Index[]
92
- ): IndexOperation[] {
93
- const deletions: IndexOperation[] = [];
94
-
95
- for (const existingIndex of existingIndexes) {
96
- if (!desiredIndexKeys.has(existingIndex.key)) {
97
- deletions.push({
98
- type: 'delete',
99
- index: existingIndex as Index, // Convert Models.Index to Index for compatibility
100
- reason: 'Obsolete index'
101
- });
102
- }
103
- }
104
-
105
- return deletions;
106
- }
107
-
108
- /**
109
- * Execute index operations with proper error handling and status monitoring
110
- */
111
- export async function executeIndexOperations(
112
- adapter: DatabaseAdapter,
113
- databaseId: string,
114
- tableId: string,
115
- plan: IndexOperationPlan
116
- ): Promise<IndexExecutionResult> {
117
- const result: IndexExecutionResult = {
118
- created: [],
119
- updated: [],
120
- skipped: [],
121
- deleted: [],
122
- errors: [],
123
- summary: {
124
- total: 0,
125
- created: 0,
126
- updated: 0,
127
- skipped: 0,
128
- deleted: 0,
129
- errors: 0
130
- }
131
- };
132
-
133
- // Execute creates
134
- for (const operation of plan.toCreate) {
135
- try {
136
- await adapter.createIndex({
137
- databaseId,
138
- tableId,
139
- key: operation.index.key,
140
- type: operation.index.type,
141
- attributes: operation.index.attributes,
142
- orders: operation.index.orders || []
143
- });
144
-
145
- result.created.push(operation.index.key);
146
- MessageFormatter.success(`Created index ${operation.index.key}`, { prefix: 'Indexes' });
147
-
148
- // Wait for index to become available
149
- await waitForIndexAvailable(adapter, databaseId, tableId, operation.index.key);
150
-
151
- await delay(150); // Brief delay between operations
152
- } catch (error) {
153
- const errorMessage = error instanceof Error ? error.message : String(error);
154
- result.errors.push({ key: operation.index.key, error: errorMessage });
155
- MessageFormatter.error(`Failed to create index ${operation.index.key}`, error instanceof Error ? error : new Error(String(error)), { prefix: 'Indexes' });
156
- }
157
- }
158
-
159
- // Execute updates (delete + recreate)
160
- for (const operation of plan.toUpdate) {
161
- try {
162
- // Delete existing index first
163
- await adapter.deleteIndex({
164
- databaseId,
165
- tableId,
166
- key: operation.index.key
167
- });
168
-
169
- await delay(100); // Brief delay for deletion to settle
170
-
171
- // Create new index
172
- await adapter.createIndex({
173
- databaseId,
174
- tableId,
175
- key: operation.index.key,
176
- type: operation.index.type,
177
- attributes: operation.index.attributes,
178
- orders: operation.index.orders || operation.existingIndex?.orders || []
179
- });
180
-
181
- result.updated.push(operation.index.key);
182
- MessageFormatter.success(`Updated index ${operation.index.key}`, { prefix: 'Indexes' });
183
-
184
- // Wait for index to become available
185
- await waitForIndexAvailable(adapter, databaseId, tableId, operation.index.key);
186
-
187
- await delay(150); // Brief delay between operations
188
- } catch (error) {
189
- const errorMessage = error instanceof Error ? error.message : String(error);
190
- result.errors.push({ key: operation.index.key, error: errorMessage });
191
- MessageFormatter.error(`Failed to update index ${operation.index.key}`, error instanceof Error ? error : new Error(String(error)), { prefix: 'Indexes' });
192
- }
193
- }
194
-
195
- // Execute skips
196
- for (const operation of plan.toSkip) {
197
- result.skipped.push(operation.index.key);
198
- MessageFormatter.info(`Index ${operation.index.key} unchanged`, { prefix: 'Indexes' });
199
- }
200
-
201
- // Calculate summary
202
- result.summary.total = result.created.length + result.updated.length + result.skipped.length + result.deleted.length;
203
- result.summary.created = result.created.length;
204
- result.summary.updated = result.updated.length;
205
- result.summary.skipped = result.skipped.length;
206
- result.summary.deleted = result.deleted.length;
207
- result.summary.errors = result.errors.length;
208
-
209
- return result;
210
- }
211
-
212
- /**
213
- * Execute index deletions with proper error handling
214
- */
215
- export async function executeIndexDeletions(
216
- adapter: DatabaseAdapter,
217
- databaseId: string,
218
- tableId: string,
219
- deletions: IndexOperation[]
220
- ): Promise<{ deleted: string[]; errors: Array<{ key: string; error: string }> }> {
221
- const result = {
222
- deleted: [] as string[],
223
- errors: [] as Array<{ key: string; error: string }>
224
- };
225
-
226
- for (const operation of deletions) {
227
- try {
228
- await adapter.deleteIndex({
229
- databaseId,
230
- tableId,
231
- key: operation.index.key
232
- });
233
-
234
- result.deleted.push(operation.index.key);
235
- MessageFormatter.info(`Deleted obsolete index ${operation.index.key}`, { prefix: 'Indexes' });
236
-
237
- // Wait briefly for deletion to settle
238
- await delay(500);
239
- } catch (error) {
240
- const errorMessage = error instanceof Error ? error.message : String(error);
241
- result.errors.push({ key: operation.index.key, error: errorMessage });
242
- MessageFormatter.error(`Failed to delete index ${operation.index.key}`, error instanceof Error ? error : new Error(String(error)), { prefix: 'Indexes' });
243
- }
244
- }
245
-
246
- return result;
247
- }
248
-
249
- /**
250
- * Wait for an index to become available with timeout and retry logic
251
- * This is an adapter-aware version of the logic from collections/indexes.ts
252
- */
253
- async function waitForIndexAvailable(
254
- adapter: DatabaseAdapter,
255
- databaseId: string,
256
- tableId: string,
257
- indexKey: string,
258
- maxWaitTime: number = 60000, // 1 minute
259
- checkInterval: number = 2000 // 2 seconds
260
- ): Promise<boolean> {
261
- const startTime = Date.now();
262
-
263
- while (Date.now() - startTime < maxWaitTime) {
264
- try {
265
- const indexList = await adapter.listIndexes({ databaseId, tableId });
266
- const indexes: any[] = (indexList as any).data || (indexList as any).indexes || [];
267
- const index = indexes.find((idx: any) => idx.key === indexKey);
268
-
269
- if (!index) {
270
- MessageFormatter.error(`Index '${indexKey}' not found after creation`, undefined, { prefix: 'Indexes' });
271
- return false;
272
- }
273
-
274
- switch (index.status) {
275
- case 'available':
276
- return true;
277
-
278
- case 'failed':
279
- MessageFormatter.error(`Index '${indexKey}' failed: ${index.error || 'unknown error'}`, undefined, { prefix: 'Indexes' });
280
- return false;
281
-
282
- case 'stuck':
283
- MessageFormatter.warning(`Index '${indexKey}' is stuck`, { prefix: 'Indexes' });
284
- return false;
285
-
286
- case 'processing':
287
- case 'deleting':
288
- // Continue waiting
289
- break;
290
-
291
- default:
292
- MessageFormatter.warning(`Unknown status '${index.status}' for index '${indexKey}'`, { prefix: 'Indexes' });
293
- break;
294
- }
295
- } catch (error) {
296
- MessageFormatter.error(`Error checking index '${indexKey}' status: ${error}`, undefined, { prefix: 'Indexes' });
297
- }
298
-
299
- await delay(checkInterval);
300
- }
301
-
302
- MessageFormatter.warning(`Timeout waiting for index '${indexKey}' to become available (${maxWaitTime}ms)`, { prefix: 'Indexes' });
303
- return false;
304
- }
305
-
306
- /**
307
- * Main function to create/update indexes via adapter
308
- * This replaces the messy inline code in methods.ts
309
- */
310
- export async function createOrUpdateIndexesViaAdapter(
311
- adapter: DatabaseAdapter,
312
- databaseId: string,
313
- tableId: string,
314
- desiredIndexes: Index[],
315
- configIndexes?: Index[]
316
- ): Promise<void> {
317
- if (!desiredIndexes || desiredIndexes.length === 0) {
318
- MessageFormatter.info('No indexes to process', { prefix: 'Indexes' });
319
- return;
320
- }
321
-
322
- MessageFormatter.info(`Processing ${desiredIndexes.length} indexes for table ${tableId}`, { prefix: 'Indexes' });
323
-
324
- try {
325
- // Get existing indexes
326
- const existingIdxRes = await adapter.listIndexes({ databaseId, tableId });
327
- const existingIndexes: Models.Index[] = (existingIdxRes as any).data || (existingIdxRes as any).indexes || [];
328
-
329
- // Plan operations
330
- const plan = planIndexOperations(desiredIndexes, existingIndexes);
331
-
332
- // Show plan with icons (consistent with attribute handling)
333
- const planParts: string[] = [];
334
- if (plan.toCreate.length) planParts.push(`➕ ${plan.toCreate.length} (${plan.toCreate.map(op => op.index.key).join(', ')})`);
335
- if (plan.toUpdate.length) planParts.push(`🔧 ${plan.toUpdate.length} (${plan.toUpdate.map(op => op.index.key).join(', ')})`);
336
- if (plan.toSkip.length) planParts.push(`⏭️ ${plan.toSkip.length}`);
337
-
338
- MessageFormatter.info(`Plan → ${planParts.join(' | ') || 'no changes'}`, { prefix: 'Indexes' });
339
-
340
- // Execute operations
341
- const result = await executeIndexOperations(adapter, databaseId, tableId, plan);
342
-
343
- // Show summary
344
- MessageFormatter.info(
345
- `Summary → ➕ ${result.summary.created} | 🔧 ${result.summary.updated} | ⏭️ ${result.summary.skipped}`,
346
- { prefix: 'Indexes' }
347
- );
348
-
349
- // Handle errors if any
350
- if (result.errors.length > 0) {
351
- MessageFormatter.error(`${result.errors.length} index operations failed:`, undefined, { prefix: 'Indexes' });
352
- for (const error of result.errors) {
353
- MessageFormatter.error(` ${error.key}: ${error.error}`, undefined, { prefix: 'Indexes' });
354
- }
355
- }
356
-
357
- } catch (error) {
358
- MessageFormatter.error('Failed to process indexes', error instanceof Error ? error : new Error(String(error)), { prefix: 'Indexes' });
359
- throw error;
360
- }
361
- }
362
-
363
- /**
364
- * Handle index deletions for obsolete indexes
365
- */
366
- export async function deleteObsoleteIndexesViaAdapter(
367
- adapter: DatabaseAdapter,
368
- databaseId: string,
369
- tableId: string,
370
- desiredIndexKeys: Set<string>
371
- ): Promise<void> {
372
- try {
373
- // Get existing indexes
374
- const existingIdxRes = await adapter.listIndexes({ databaseId, tableId });
375
- const existingIndexes: Models.Index[] = (existingIdxRes as any).data || (existingIdxRes as any).indexes || [];
376
-
377
- // Plan deletions
378
- const deletions = planIndexDeletions(desiredIndexKeys, existingIndexes);
379
-
380
- if (deletions.length === 0) {
381
- MessageFormatter.info('Plan → 🗑️ 0 indexes', { prefix: 'Indexes' });
382
- return;
383
- }
384
-
385
- // Show deletion plan
386
- MessageFormatter.info(
387
- `Plan → 🗑️ ${deletions.length} (${deletions.map(op => op.index.key).join(', ')})`,
388
- { prefix: 'Indexes' }
389
- );
390
-
391
- // Execute deletions
392
- const result = await executeIndexDeletions(adapter, databaseId, tableId, deletions);
393
-
394
- // Show results
395
- if (result.deleted.length > 0) {
396
- MessageFormatter.success(`Deleted ${result.deleted.length} indexes: ${result.deleted.join(', ')}`, { prefix: 'Indexes' });
397
- }
398
-
399
- if (result.errors.length > 0) {
400
- MessageFormatter.error(`${result.errors.length} index deletions failed:`, undefined, { prefix: 'Indexes' });
401
- for (const error of result.errors) {
402
- MessageFormatter.error(` ${error.key}: ${error.error}`, undefined, { prefix: 'Indexes' });
403
- }
404
- }
405
-
406
- } catch (error) {
407
- MessageFormatter.warning(`Could not evaluate index deletions: ${(error as Error)?.message || error}`, { prefix: 'Indexes' });
408
- }
409
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * Type declarations for optional node-appwrite-tablesdb module
3
- * This allows compilation when the module is not installed
4
- */
5
-
6
- declare module 'node-appwrite-tablesdb' {
7
- export class Client {
8
- setEndpoint(endpoint: string): this;
9
- setProject(project: string): this;
10
- setKey(key: string): this;
11
- }
12
-
13
- export class TablesDB {
14
- constructor(client: Client);
15
-
16
- // Core methods based on TablesDB API
17
- listTables(databaseId: string, queries?: any[]): Promise<any>;
18
- createTable(databaseId: string, id: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean): Promise<any>;
19
- updateTable(databaseId: string, id: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean): Promise<any>;
20
- deleteTable(databaseId: string, tableId: string): Promise<void>;
21
- getTable(databaseId: string, tableId: string): Promise<any>;
22
-
23
- listRows(databaseId: string, tableId: string, queries?: any[]): Promise<any>;
24
- createRow(databaseId: string, tableId: string, id: string, data: any, permissions?: string[]): Promise<any>;
25
- updateRow(databaseId: string, tableId: string, id: string, data?: any, permissions?: string[]): Promise<any>;
26
- deleteRow(databaseId: string, tableId: string, id: string): Promise<void>;
27
- getRow(databaseId: string, tableId: string, id: string): Promise<any>;
28
-
29
- // Bulk operations (if supported)
30
- bulkCreateRows?(databaseId: string, tableId: string, rows: any[]): Promise<any>;
31
- bulkUpsertRows?(databaseId: string, tableId: string, rows: any[]): Promise<any>;
32
- bulkDeleteRows?(databaseId: string, tableId: string, rowIds: string[]): Promise<any>;
33
-
34
- // Index operations
35
- listIndexes(databaseId: string, tableId: string, queries?: any[]): Promise<any>;
36
- createIndex(databaseId: string, tableId: string, key: string, type: string, attributes: string[], orders?: string[]): Promise<any>;
37
- deleteIndex(databaseId: string, tableId: string, key: string): Promise<void>;
38
-
39
- // Attribute operations
40
- createAttribute(databaseId: string, tableId: string, key: string, type: string, ...args: any[]): Promise<any>;
41
- updateAttribute(databaseId: string, tableId: string, key: string, required?: boolean, defaultValue?: any): Promise<any>;
42
- deleteAttribute(databaseId: string, tableId: string, key: string): Promise<void>;
43
- }
44
- }