@njdamstra/appwrite-utils-cli 1.8.9 → 1.10.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 (284) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/CONFIG_TODO.md +1189 -0
  3. package/SELECTION_DIALOGS.md +146 -0
  4. package/SERVICE_IMPLEMENTATION_REPORT.md +462 -0
  5. package/dist/adapters/index.d.ts +7 -8
  6. package/dist/adapters/index.js +7 -9
  7. package/dist/backups/operations/bucketBackup.js +2 -2
  8. package/dist/backups/operations/collectionBackup.d.ts +1 -1
  9. package/dist/backups/operations/collectionBackup.js +3 -3
  10. package/dist/backups/operations/comprehensiveBackup.d.ts +1 -1
  11. package/dist/backups/operations/comprehensiveBackup.js +2 -2
  12. package/dist/backups/tracking/centralizedTracking.d.ts +1 -1
  13. package/dist/backups/tracking/centralizedTracking.js +2 -2
  14. package/dist/cli/commands/configCommands.js +51 -7
  15. package/dist/cli/commands/databaseCommands.d.ts +1 -0
  16. package/dist/cli/commands/databaseCommands.js +119 -9
  17. package/dist/cli/commands/functionCommands.js +3 -3
  18. package/dist/cli/commands/importFileCommands.d.ts +7 -0
  19. package/dist/cli/commands/importFileCommands.js +674 -0
  20. package/dist/cli/commands/schemaCommands.js +3 -3
  21. package/dist/cli/commands/storageCommands.js +2 -3
  22. package/dist/cli/commands/transferCommands.js +3 -5
  23. package/dist/collections/attributes.d.ts +1 -1
  24. package/dist/collections/attributes.js +2 -35
  25. package/dist/collections/indexes.js +1 -3
  26. package/dist/collections/methods.d.ts +1 -1
  27. package/dist/collections/methods.js +111 -192
  28. package/dist/collections/tableOperations.d.ts +1 -0
  29. package/dist/collections/tableOperations.js +55 -23
  30. package/dist/collections/transferOperations.d.ts +1 -1
  31. package/dist/collections/transferOperations.js +3 -4
  32. package/dist/collections/wipeOperations.d.ts +4 -3
  33. package/dist/collections/wipeOperations.js +112 -39
  34. package/dist/databases/methods.js +2 -2
  35. package/dist/databases/setup.js +2 -2
  36. package/dist/examples/yamlTerminologyExample.js +2 -2
  37. package/dist/functions/deployments.d.ts +1 -1
  38. package/dist/functions/deployments.js +5 -5
  39. package/dist/functions/fnConfigDiscovery.js +2 -2
  40. package/dist/functions/methods.js +16 -4
  41. package/dist/init.js +1 -1
  42. package/dist/interactiveCLI.d.ts +6 -1
  43. package/dist/interactiveCLI.js +63 -9
  44. package/dist/main.js +130 -177
  45. package/dist/migrations/afterImportActions.js +2 -3
  46. package/dist/migrations/appwriteToX.d.ts +1 -1
  47. package/dist/migrations/appwriteToX.js +9 -7
  48. package/dist/migrations/comprehensiveTransfer.js +3 -5
  49. package/dist/migrations/dataLoader.js +2 -5
  50. package/dist/migrations/importController.js +3 -4
  51. package/dist/migrations/importDataActions.js +3 -3
  52. package/dist/migrations/relationships.js +1 -2
  53. package/dist/migrations/services/DataTransformationService.js +2 -2
  54. package/dist/migrations/services/FileHandlerService.js +1 -1
  55. package/dist/migrations/services/ImportOrchestrator.js +4 -4
  56. package/dist/migrations/services/RateLimitManager.js +1 -1
  57. package/dist/migrations/services/RelationshipResolver.js +1 -1
  58. package/dist/migrations/services/UserMappingService.js +1 -1
  59. package/dist/migrations/services/ValidationService.js +1 -1
  60. package/dist/migrations/transfer.d.ts +8 -4
  61. package/dist/migrations/transfer.js +106 -55
  62. package/dist/migrations/yaml/YamlImportConfigLoader.js +1 -1
  63. package/dist/migrations/yaml/YamlImportIntegration.js +2 -2
  64. package/dist/migrations/yaml/generateImportSchemas.js +1 -1
  65. package/dist/setupCommands.d.ts +1 -1
  66. package/dist/setupCommands.js +5 -6
  67. package/dist/setupController.js +1 -1
  68. package/dist/shared/backupTracking.d.ts +1 -1
  69. package/dist/shared/backupTracking.js +2 -2
  70. package/dist/shared/confirmationDialogs.js +1 -1
  71. package/dist/shared/migrationHelpers.d.ts +1 -1
  72. package/dist/shared/migrationHelpers.js +3 -3
  73. package/dist/shared/operationQueue.d.ts +1 -1
  74. package/dist/shared/operationQueue.js +2 -3
  75. package/dist/shared/operationsTable.d.ts +1 -1
  76. package/dist/shared/operationsTable.js +2 -2
  77. package/dist/shared/progressManager.js +1 -1
  78. package/dist/shared/selectionDialogs.js +9 -8
  79. package/dist/storage/methods.js +4 -4
  80. package/dist/storage/schemas.d.ts +2 -2
  81. package/dist/tables/indexManager.d.ts +65 -0
  82. package/dist/tables/indexManager.js +294 -0
  83. package/dist/types.d.ts +2 -2
  84. package/dist/types.js +1 -1
  85. package/dist/users/methods.js +2 -3
  86. package/dist/utils/configMigration.js +1 -1
  87. package/dist/utils/index.d.ts +1 -1
  88. package/dist/utils/index.js +1 -1
  89. package/dist/utils/loadConfigs.d.ts +2 -2
  90. package/dist/utils/loadConfigs.js +6 -7
  91. package/dist/utils/setupFiles.js +5 -7
  92. package/dist/utilsController.d.ts +15 -8
  93. package/dist/utilsController.js +57 -28
  94. package/package.json +7 -3
  95. package/src/adapters/index.ts +8 -34
  96. package/src/backups/operations/bucketBackup.ts +2 -2
  97. package/src/backups/operations/collectionBackup.ts +4 -4
  98. package/src/backups/operations/comprehensiveBackup.ts +3 -3
  99. package/src/backups/tracking/centralizedTracking.ts +3 -3
  100. package/src/cli/commands/configCommands.ts +72 -8
  101. package/src/cli/commands/databaseCommands.ts +161 -9
  102. package/src/cli/commands/functionCommands.ts +4 -3
  103. package/src/cli/commands/importFileCommands.ts +815 -0
  104. package/src/cli/commands/schemaCommands.ts +3 -3
  105. package/src/cli/commands/storageCommands.ts +2 -3
  106. package/src/cli/commands/transferCommands.ts +3 -6
  107. package/src/collections/attributes.ts +3 -39
  108. package/src/collections/indexes.ts +2 -4
  109. package/src/collections/methods.ts +115 -150
  110. package/src/collections/tableOperations.ts +57 -21
  111. package/src/collections/transferOperations.ts +4 -5
  112. package/src/collections/wipeOperations.ts +154 -51
  113. package/src/databases/methods.ts +2 -2
  114. package/src/databases/setup.ts +2 -2
  115. package/src/examples/yamlTerminologyExample.ts +2 -2
  116. package/src/functions/deployments.ts +6 -5
  117. package/src/functions/fnConfigDiscovery.ts +2 -2
  118. package/src/functions/methods.ts +17 -4
  119. package/src/init.ts +1 -1
  120. package/src/interactiveCLI.ts +75 -10
  121. package/src/main.ts +143 -287
  122. package/src/migrations/afterImportActions.ts +2 -3
  123. package/src/migrations/appwriteToX.ts +12 -8
  124. package/src/migrations/comprehensiveTransfer.ts +6 -6
  125. package/src/migrations/dataLoader.ts +2 -5
  126. package/src/migrations/importController.ts +3 -4
  127. package/src/migrations/importDataActions.ts +3 -3
  128. package/src/migrations/relationships.ts +1 -2
  129. package/src/migrations/services/DataTransformationService.ts +2 -2
  130. package/src/migrations/services/FileHandlerService.ts +1 -1
  131. package/src/migrations/services/ImportOrchestrator.ts +4 -4
  132. package/src/migrations/services/RateLimitManager.ts +1 -1
  133. package/src/migrations/services/RelationshipResolver.ts +1 -1
  134. package/src/migrations/services/UserMappingService.ts +1 -1
  135. package/src/migrations/services/ValidationService.ts +1 -1
  136. package/src/migrations/transfer.ts +126 -83
  137. package/src/migrations/yaml/YamlImportConfigLoader.ts +1 -1
  138. package/src/migrations/yaml/YamlImportIntegration.ts +2 -2
  139. package/src/migrations/yaml/generateImportSchemas.ts +1 -1
  140. package/src/setupCommands.ts +5 -6
  141. package/src/setupController.ts +1 -1
  142. package/src/shared/backupTracking.ts +3 -3
  143. package/src/shared/confirmationDialogs.ts +1 -1
  144. package/src/shared/migrationHelpers.ts +4 -4
  145. package/src/shared/operationQueue.ts +3 -4
  146. package/src/shared/operationsTable.ts +3 -3
  147. package/src/shared/progressManager.ts +1 -1
  148. package/src/shared/selectionDialogs.ts +9 -8
  149. package/src/storage/methods.ts +4 -4
  150. package/src/tables/indexManager.ts +409 -0
  151. package/src/types.ts +2 -2
  152. package/src/users/methods.ts +2 -3
  153. package/src/utils/configMigration.ts +1 -1
  154. package/src/utils/index.ts +1 -1
  155. package/src/utils/loadConfigs.ts +15 -7
  156. package/src/utils/setupFiles.ts +5 -7
  157. package/src/utilsController.ts +86 -32
  158. package/dist/adapters/AdapterFactory.d.ts +0 -94
  159. package/dist/adapters/AdapterFactory.js +0 -405
  160. package/dist/adapters/DatabaseAdapter.d.ts +0 -233
  161. package/dist/adapters/DatabaseAdapter.js +0 -50
  162. package/dist/adapters/LegacyAdapter.d.ts +0 -50
  163. package/dist/adapters/LegacyAdapter.js +0 -612
  164. package/dist/adapters/TablesDBAdapter.d.ts +0 -45
  165. package/dist/adapters/TablesDBAdapter.js +0 -571
  166. package/dist/config/ConfigManager.d.ts +0 -445
  167. package/dist/config/ConfigManager.js +0 -625
  168. package/dist/config/configMigration.d.ts +0 -87
  169. package/dist/config/configMigration.js +0 -390
  170. package/dist/config/configValidation.d.ts +0 -66
  171. package/dist/config/configValidation.js +0 -358
  172. package/dist/config/index.d.ts +0 -8
  173. package/dist/config/index.js +0 -7
  174. package/dist/config/services/ConfigDiscoveryService.d.ts +0 -126
  175. package/dist/config/services/ConfigDiscoveryService.js +0 -374
  176. package/dist/config/services/ConfigLoaderService.d.ts +0 -129
  177. package/dist/config/services/ConfigLoaderService.js +0 -540
  178. package/dist/config/services/ConfigMergeService.d.ts +0 -208
  179. package/dist/config/services/ConfigMergeService.js +0 -308
  180. package/dist/config/services/ConfigValidationService.d.ts +0 -214
  181. package/dist/config/services/ConfigValidationService.js +0 -310
  182. package/dist/config/services/SessionAuthService.d.ts +0 -225
  183. package/dist/config/services/SessionAuthService.js +0 -456
  184. package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +0 -1
  185. package/dist/config/services/__tests__/ConfigMergeService.test.js +0 -271
  186. package/dist/config/services/index.d.ts +0 -13
  187. package/dist/config/services/index.js +0 -10
  188. package/dist/config/yamlConfig.d.ts +0 -722
  189. package/dist/config/yamlConfig.js +0 -702
  190. package/dist/functions/pathResolution.d.ts +0 -37
  191. package/dist/functions/pathResolution.js +0 -185
  192. package/dist/shared/attributeMapper.d.ts +0 -20
  193. package/dist/shared/attributeMapper.js +0 -203
  194. package/dist/shared/errorUtils.d.ts +0 -54
  195. package/dist/shared/errorUtils.js +0 -95
  196. package/dist/shared/functionManager.d.ts +0 -48
  197. package/dist/shared/functionManager.js +0 -336
  198. package/dist/shared/indexManager.d.ts +0 -24
  199. package/dist/shared/indexManager.js +0 -151
  200. package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
  201. package/dist/shared/jsonSchemaGenerator.js +0 -290
  202. package/dist/shared/logging.d.ts +0 -61
  203. package/dist/shared/logging.js +0 -116
  204. package/dist/shared/messageFormatter.d.ts +0 -39
  205. package/dist/shared/messageFormatter.js +0 -162
  206. package/dist/shared/pydanticModelGenerator.d.ts +0 -17
  207. package/dist/shared/pydanticModelGenerator.js +0 -615
  208. package/dist/shared/schemaGenerator.d.ts +0 -40
  209. package/dist/shared/schemaGenerator.js +0 -556
  210. package/dist/utils/ClientFactory.d.ts +0 -87
  211. package/dist/utils/ClientFactory.js +0 -212
  212. package/dist/utils/configDiscovery.d.ts +0 -78
  213. package/dist/utils/configDiscovery.js +0 -472
  214. package/dist/utils/constantsGenerator.d.ts +0 -31
  215. package/dist/utils/constantsGenerator.js +0 -321
  216. package/dist/utils/dataConverters.d.ts +0 -46
  217. package/dist/utils/dataConverters.js +0 -139
  218. package/dist/utils/directoryUtils.d.ts +0 -22
  219. package/dist/utils/directoryUtils.js +0 -59
  220. package/dist/utils/getClientFromConfig.d.ts +0 -39
  221. package/dist/utils/getClientFromConfig.js +0 -199
  222. package/dist/utils/helperFunctions.d.ts +0 -63
  223. package/dist/utils/helperFunctions.js +0 -156
  224. package/dist/utils/pathResolvers.d.ts +0 -53
  225. package/dist/utils/pathResolvers.js +0 -72
  226. package/dist/utils/projectConfig.d.ts +0 -119
  227. package/dist/utils/projectConfig.js +0 -171
  228. package/dist/utils/retryFailedPromises.d.ts +0 -2
  229. package/dist/utils/retryFailedPromises.js +0 -23
  230. package/dist/utils/sessionAuth.d.ts +0 -48
  231. package/dist/utils/sessionAuth.js +0 -164
  232. package/dist/utils/typeGuards.d.ts +0 -35
  233. package/dist/utils/typeGuards.js +0 -57
  234. package/dist/utils/validationRules.d.ts +0 -43
  235. package/dist/utils/validationRules.js +0 -42
  236. package/dist/utils/versionDetection.d.ts +0 -58
  237. package/dist/utils/versionDetection.js +0 -251
  238. package/dist/utils/yamlConverter.d.ts +0 -100
  239. package/dist/utils/yamlConverter.js +0 -428
  240. package/dist/utils/yamlLoader.d.ts +0 -70
  241. package/dist/utils/yamlLoader.js +0 -267
  242. package/src/adapters/AdapterFactory.ts +0 -510
  243. package/src/adapters/DatabaseAdapter.ts +0 -306
  244. package/src/adapters/LegacyAdapter.ts +0 -841
  245. package/src/adapters/TablesDBAdapter.ts +0 -773
  246. package/src/config/ConfigManager.ts +0 -808
  247. package/src/config/README.md +0 -274
  248. package/src/config/configMigration.ts +0 -575
  249. package/src/config/configValidation.ts +0 -445
  250. package/src/config/index.ts +0 -10
  251. package/src/config/services/ConfigDiscoveryService.ts +0 -463
  252. package/src/config/services/ConfigLoaderService.ts +0 -740
  253. package/src/config/services/ConfigMergeService.ts +0 -388
  254. package/src/config/services/ConfigValidationService.ts +0 -394
  255. package/src/config/services/SessionAuthService.ts +0 -565
  256. package/src/config/services/__tests__/ConfigMergeService.test.ts +0 -351
  257. package/src/config/services/index.ts +0 -29
  258. package/src/config/yamlConfig.ts +0 -761
  259. package/src/functions/pathResolution.ts +0 -227
  260. package/src/shared/attributeMapper.ts +0 -229
  261. package/src/shared/errorUtils.ts +0 -110
  262. package/src/shared/functionManager.ts +0 -525
  263. package/src/shared/indexManager.ts +0 -254
  264. package/src/shared/jsonSchemaGenerator.ts +0 -383
  265. package/src/shared/logging.ts +0 -149
  266. package/src/shared/messageFormatter.ts +0 -208
  267. package/src/shared/pydanticModelGenerator.ts +0 -618
  268. package/src/shared/schemaGenerator.ts +0 -644
  269. package/src/utils/ClientFactory.ts +0 -240
  270. package/src/utils/configDiscovery.ts +0 -557
  271. package/src/utils/constantsGenerator.ts +0 -369
  272. package/src/utils/dataConverters.ts +0 -159
  273. package/src/utils/directoryUtils.ts +0 -61
  274. package/src/utils/getClientFromConfig.ts +0 -257
  275. package/src/utils/helperFunctions.ts +0 -228
  276. package/src/utils/pathResolvers.ts +0 -81
  277. package/src/utils/projectConfig.ts +0 -299
  278. package/src/utils/retryFailedPromises.ts +0 -29
  279. package/src/utils/sessionAuth.ts +0 -230
  280. package/src/utils/typeGuards.ts +0 -65
  281. package/src/utils/validationRules.ts +0 -88
  282. package/src/utils/versionDetection.ts +0 -292
  283. package/src/utils/yamlConverter.ts +0 -542
  284. package/src/utils/yamlLoader.ts +0 -371
@@ -14,18 +14,15 @@ import {
14
14
  } from "@njdamstra/appwrite-utils";
15
15
  import path from "path";
16
16
  import fs from "fs";
17
- import { convertObjectByAttributeMappings } from "../utils/dataConverters.js";
17
+ import { convertObjectByAttributeMappings } from "@njdamstra/appwrite-utils-helpers";
18
18
  import { z } from "zod";
19
19
  import { checkForCollection } from "../collections/methods.js";
20
20
  import { ID, Users, type Databases } from "node-appwrite";
21
- import { logger } from "../shared/logging.js";
21
+ import { logger, LegacyAdapter, MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
22
22
  import { findOrCreateOperation, updateOperation } from "../shared/migrationHelpers.js";
23
23
  import { AuthUserCreateSchema } from "../schemas/authUser.js";
24
- import { LegacyAdapter } from "../adapters/LegacyAdapter.js";
25
24
  import { UsersController } from "../users/methods.js";
26
- import { finalizeByAttributeMap } from "../utils/helperFunctions.js";
27
25
  import { isEmpty } from "es-toolkit/compat";
28
- import { MessageFormatter } from "../shared/messageFormatter.js";
29
26
 
30
27
  // Define a schema for the structure of collection import data using Zod for validation
31
28
  export const CollectionImportDataSchema = z.object({
@@ -13,13 +13,12 @@ import type {
13
13
  AttributeMappings,
14
14
  } from "@njdamstra/appwrite-utils";
15
15
  import type { ImportDataActions } from "./importDataActions.js";
16
- import { areCollectionNamesSame, tryAwaitWithRetry } from "../utils/index.js";
16
+ import { areCollectionNamesSame, tryAwaitWithRetry } from "@njdamstra/appwrite-utils-helpers";
17
17
  import type { SetupOptions } from "../utilsController.js";
18
18
  import { resolveAndUpdateRelationships } from "./relationships.js";
19
19
  import { UsersController } from "../users/methods.js";
20
- import { logger } from "../shared/logging.js";
20
+ import { logger, LegacyAdapter } from "@njdamstra/appwrite-utils-helpers";
21
21
  import { updateOperation } from "../shared/migrationHelpers.js";
22
- import { LegacyAdapter } from "../adapters/LegacyAdapter.js";
23
22
  import {
24
23
  BatchSchema,
25
24
  OperationCreateSchema,
@@ -30,7 +29,7 @@ import {
30
29
  transferDatabaseLocalToLocal,
31
30
  transferStorageLocalToLocal,
32
31
  } from "./transfer.js";
33
- import { MessageFormatter } from "../shared/messageFormatter.js";
32
+ import { MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
34
33
  import { ProgressManager } from "../shared/progressManager.js";
35
34
 
36
35
  export class ImportController {
@@ -6,11 +6,11 @@ import {
6
6
  type AttributeMappings,
7
7
  } from "@njdamstra/appwrite-utils";
8
8
  import { converterFunctions, type ConverterFunctions } from "@njdamstra/appwrite-utils";
9
- import { convertObjectBySchema } from "../utils/dataConverters.js";
9
+ import { convertObjectBySchema } from "@njdamstra/appwrite-utils-helpers";
10
10
  import { type AfterImportActions } from "@njdamstra/appwrite-utils";
11
11
  import { afterImportActions } from "./afterImportActions.js";
12
- import { logger } from "../shared/logging.js";
13
- import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
12
+ import { logger } from "@njdamstra/appwrite-utils-helpers";
13
+ import { tryAwaitWithRetry } from "@njdamstra/appwrite-utils-helpers";
14
14
 
15
15
  export class ImportDataActions {
16
16
  private db: Databases;
@@ -5,8 +5,7 @@ import type {
5
5
  Attribute,
6
6
  RelationshipAttribute,
7
7
  } from "@njdamstra/appwrite-utils";
8
- import { logger } from "../shared/logging.js";
9
- import { MessageFormatter } from "../shared/messageFormatter.js";
8
+ import { logger, MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
10
9
 
11
10
  /**
12
11
  * Finds collections that have defined relationship attributes.
@@ -5,8 +5,8 @@ import type {
5
5
  CollectionCreate,
6
6
  } from "@njdamstra/appwrite-utils";
7
7
  import type { ImportDataActions } from "../importDataActions.js";
8
- import { convertObjectByAttributeMappings } from "../../utils/dataConverters.js";
9
- import { logger } from "../../shared/logging.js";
8
+ import { convertObjectByAttributeMappings } from "@njdamstra/appwrite-utils-helpers";
9
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
10
10
 
11
11
  /**
12
12
  * Service responsible for data transformation during import.
@@ -2,7 +2,7 @@ import path from "path";
2
2
  import fs from "fs";
3
3
  import type { AttributeMappings, AppwriteConfig } from "@njdamstra/appwrite-utils";
4
4
  import type { ImportDataActions } from "../importDataActions.js";
5
- import { logger } from "../../shared/logging.js";
5
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
6
6
  import { RateLimitManager } from "./RateLimitManager.js";
7
7
 
8
8
  /**
@@ -23,12 +23,12 @@ import { RelationshipResolver, type CollectionImportData } from "./RelationshipR
23
23
  import type { ImportDataActions } from "../importDataActions.js";
24
24
  import type { SetupOptions } from "../../utilsController.js";
25
25
  import { UsersController } from "../../users/methods.js";
26
- import { logger } from "../../shared/logging.js";
27
- import { MessageFormatter } from "../../shared/messageFormatter.js";
26
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
27
+ import { MessageFormatter } from '@njdamstra/appwrite-utils-helpers';
28
28
  import { ProgressManager } from "../../shared/progressManager.js";
29
- import { tryAwaitWithRetry } from "../../utils/index.js";
29
+ import { tryAwaitWithRetry } from "@njdamstra/appwrite-utils-helpers";
30
30
  import { updateOperation, findOrCreateOperation } from "../../shared/migrationHelpers.js";
31
- import { LegacyAdapter } from "../../adapters/LegacyAdapter.js";
31
+ import { LegacyAdapter } from '@njdamstra/appwrite-utils-helpers';
32
32
  import { resolveAndUpdateRelationships } from "../relationships.js";
33
33
 
34
34
  // Enhanced rate limiting configuration - now managed by RateLimitManager
@@ -1,5 +1,5 @@
1
1
  import pLimit from "p-limit";
2
- import { logger } from "../../shared/logging.js";
2
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
3
3
 
4
4
  export interface RateLimitConfig {
5
5
  // Data operations
@@ -4,7 +4,7 @@ import type {
4
4
  AppwriteConfig,
5
5
  CollectionCreate,
6
6
  } from "@njdamstra/appwrite-utils";
7
- import { logger } from "../../shared/logging.js";
7
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
8
8
  import { isEmpty } from "es-toolkit/compat";
9
9
  import type { UserMappingService } from "./UserMappingService.js";
10
10
 
@@ -5,7 +5,7 @@ import type {
5
5
  AppwriteConfig,
6
6
  } from "@njdamstra/appwrite-utils";
7
7
  import { AuthUserCreateSchema } from "../../schemas/authUser.js";
8
- import { logger } from "../../shared/logging.js";
8
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
9
9
  import type { DataTransformationService } from "./DataTransformationService.js";
10
10
 
11
11
  /**
@@ -4,7 +4,7 @@ import type {
4
4
  CollectionCreate,
5
5
  } from "@njdamstra/appwrite-utils";
6
6
  import type { ImportDataActions } from "../importDataActions.js";
7
- import { logger } from "../../shared/logging.js";
7
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
8
8
  import fs from "fs";
9
9
  import path from "path";
10
10
 
@@ -9,18 +9,16 @@ import {
9
9
  type Models,
10
10
  } from "node-appwrite";
11
11
  import { InputFile } from "node-appwrite/file";
12
- import { getAppwriteClient } from "../utils/helperFunctions.js";
12
+ import { getAppwriteClient } from "@njdamstra/appwrite-utils-helpers";
13
13
  // Legacy attribute helpers retained only for local-to-local flows if needed
14
14
  import { parseAttribute } from "@njdamstra/appwrite-utils";
15
15
  import chalk from "chalk";
16
16
  import { fetchAllCollections } from "../collections/methods.js";
17
- import { MessageFormatter } from "../shared/messageFormatter.js";
18
- import { LegacyAdapter } from "../adapters/LegacyAdapter.js";
17
+ import { MessageFormatter, mapToCreateAttributeParams } from "@njdamstra/appwrite-utils-helpers";
19
18
  import { ProgressManager } from "../shared/progressManager.js";
20
- import { getClient, getAdapter } from "../utils/getClientFromConfig.js";
19
+ import { getClient, getAdapter } from "@njdamstra/appwrite-utils-helpers";
21
20
  import { diffTableColumns } from "../collections/tableOperations.js";
22
- import { mapToCreateAttributeParams } from "../shared/attributeMapper.js";
23
- import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js";
21
+ import { LegacyAdapter, type DatabaseAdapter } from "@njdamstra/appwrite-utils-helpers";
24
22
 
25
23
  export interface TransferOptions {
26
24
  fromDb: Models.Database | undefined;
@@ -241,99 +239,137 @@ export const transferStorageLocalToRemote = async (
241
239
  // Remote document transfer functions moved to collections/methods.ts with enhanced UX
242
240
 
243
241
  /**
244
- * Transfers all collections and documents from one local database to another local database.
242
+ * Transfers all tables/collections and documents from one local database to another local database.
243
+ * Uses the DatabaseAdapter for unified TablesDB / legacy support.
245
244
  *
246
- * @param {Databases} localDb - The local database instance.
245
+ * @param {Databases} localDb - The local database instance (kept for signature compat).
247
246
  * @param {string} fromDbId - The ID of the source database.
248
247
  * @param {string} targetDbId - The ID of the target database.
248
+ * @param {string[]} collectionIds - Optional filter: specific table/collection IDs to transfer. undefined = all, empty array = none.
249
+ * @param {DatabaseAdapter} adapter - The database adapter (TablesDB or Legacy).
249
250
  * @return {Promise<void>} A promise that resolves when the transfer is complete.
250
251
  */
251
252
  export const transferDatabaseLocalToLocal = async (
252
253
  localDb: Databases,
253
254
  fromDbId: string,
254
- targetDbId: string
255
+ targetDbId: string,
256
+ collectionIds?: string[],
257
+ adapter?: DatabaseAdapter
255
258
  ) => {
259
+ // If no adapter provided, fall back to creating a LegacyAdapter from the Databases client
260
+ const dbAdapter: DatabaseAdapter = adapter || new LegacyAdapter((localDb as any).client);
261
+
256
262
  MessageFormatter.info(
257
- `Starting database transfer from ${fromDbId} to ${targetDbId}`,
263
+ `Starting database transfer from ${fromDbId} to ${targetDbId} (mode: ${dbAdapter.getApiMode()})`,
258
264
  { prefix: "Transfer" }
259
265
  );
260
- // Get all collections from source database
261
- const sourceCollections = await fetchAllCollections(fromDbId, localDb);
266
+
267
+ // Get all tables/collections from source database via adapter
268
+ const sourceListRes = await dbAdapter.listTables({ databaseId: fromDbId, queries: [Query.limit(500)] });
269
+ let sourceTables: any[] = sourceListRes.tables || sourceListRes.collections || sourceListRes.data || [];
270
+
271
+ // Filter by collectionIds if provided (match by $id or by name)
272
+ if (collectionIds !== undefined) {
273
+ if (collectionIds.length === 0) {
274
+ MessageFormatter.info("No tables/collections selected for transfer, skipping.", { prefix: "Transfer" });
275
+ return;
276
+ }
277
+ const idSet = new Set(collectionIds);
278
+ sourceTables = sourceTables.filter((c: any) => idSet.has(c.$id) || idSet.has(c.name));
279
+ }
280
+
262
281
  MessageFormatter.info(
263
- `Found ${sourceCollections.length} collections in source database`,
282
+ `Found ${sourceTables.length} tables/collections in source database`,
264
283
  { prefix: "Transfer" }
265
284
  );
266
285
 
267
- // Process each collection
268
- for (const collection of sourceCollections) {
286
+ // Process each table/collection
287
+ for (const table of sourceTables) {
269
288
  MessageFormatter.processing(
270
- `Processing collection: ${collection.name} (${collection.$id})`,
289
+ `Processing table: ${table.name} (${table.$id})`,
271
290
  { prefix: "Transfer" }
272
291
  );
273
292
 
274
293
  try {
275
- // Create or update collection in target
276
- let targetCollection: Models.Collection;
277
- const existingCollection = await tryAwaitWithRetry(async () =>
278
- localDb.listCollections(targetDbId, [
279
- Query.equal("$id", collection.$id),
280
- ])
281
- );
294
+ // Check if table exists in target via adapter
295
+ let targetTableId = table.$id;
296
+ let targetTableData: any;
282
297
 
283
- if (existingCollection.collections.length > 0) {
284
- targetCollection = existingCollection.collections[0];
285
- MessageFormatter.info(
286
- `Collection ${collection.name} exists in target database`,
287
- { prefix: "Transfer" }
288
- );
298
+ try {
299
+ const existingRes = await dbAdapter.getTable({ databaseId: targetDbId, tableId: table.$id });
300
+ targetTableData = existingRes.data || (existingRes.tables && existingRes.tables[0]);
289
301
 
290
- // Update collection if needed
291
- if (
292
- targetCollection.name !== collection.name ||
293
- targetCollection.$permissions !== collection.$permissions ||
294
- targetCollection.documentSecurity !== collection.documentSecurity ||
295
- targetCollection.enabled !== collection.enabled
296
- ) {
297
- targetCollection = await tryAwaitWithRetry(async () =>
298
- localDb.updateCollection(
299
- targetDbId,
300
- collection.$id,
301
- collection.name,
302
- collection.$permissions,
303
- collection.documentSecurity,
304
- collection.enabled
305
- )
306
- );
307
- MessageFormatter.success(
308
- `Collection ${collection.name} updated`,
302
+ if (targetTableData) {
303
+ MessageFormatter.info(
304
+ `Table ${table.name} exists in target database`,
309
305
  { prefix: "Transfer" }
310
306
  );
307
+
308
+ // Update table if needed
309
+ const securityField = table.rowSecurity ?? table.documentSecurity ?? false;
310
+ const targetSecurity = targetTableData.rowSecurity ?? targetTableData.documentSecurity ?? false;
311
+ if (
312
+ targetTableData.name !== table.name ||
313
+ JSON.stringify(targetTableData.$permissions) !== JSON.stringify(table.$permissions) ||
314
+ targetSecurity !== securityField ||
315
+ targetTableData.enabled !== table.enabled
316
+ ) {
317
+ await tryAwaitWithRetry(async () =>
318
+ dbAdapter.updateTable({
319
+ databaseId: targetDbId,
320
+ id: table.$id,
321
+ name: table.name,
322
+ permissions: table.$permissions,
323
+ documentSecurity: table.documentSecurity,
324
+ rowSecurity: table.rowSecurity,
325
+ enabled: table.enabled,
326
+ })
327
+ );
328
+ MessageFormatter.success(
329
+ `Table ${table.name} updated`,
330
+ { prefix: "Transfer" }
331
+ );
332
+ }
311
333
  }
312
- } else {
334
+ } catch {
335
+ // Table does not exist in target, create it
336
+ targetTableData = null;
337
+ }
338
+
339
+ if (!targetTableData) {
313
340
  MessageFormatter.progress(
314
- `Creating collection ${collection.name} in target database...`,
341
+ `Creating table ${table.name} in target database...`,
315
342
  { prefix: "Transfer" }
316
343
  );
317
- targetCollection = await tryAwaitWithRetry(async () =>
318
- localDb.createCollection(
319
- targetDbId,
320
- collection.$id,
321
- collection.name,
322
- collection.$permissions,
323
- collection.documentSecurity,
324
- collection.enabled
325
- )
344
+ const createRes = await tryAwaitWithRetry(async () =>
345
+ dbAdapter.createTable({
346
+ databaseId: targetDbId,
347
+ id: table.$id,
348
+ name: table.name,
349
+ permissions: table.$permissions,
350
+ documentSecurity: table.documentSecurity,
351
+ rowSecurity: table.rowSecurity,
352
+ enabled: table.enabled,
353
+ })
326
354
  );
355
+ targetTableData = createRes.data || (createRes.tables && createRes.tables[0]);
327
356
  }
328
357
 
329
- // Create attributes via local adapter (wrap the existing client)
330
- const localAdapter: DatabaseAdapter = new LegacyAdapter((localDb as any).client);
331
- MessageFormatter.info(`Creating attributes for ${collection.name} via adapter...`, { prefix: 'Transfer' });
332
- const uniformAttrs = collection.attributes.map((attr) => parseAttribute(attr as any));
358
+ // Create attributes via adapter
359
+ MessageFormatter.info(`Creating attributes for ${table.name} via adapter...`, { prefix: 'Transfer' });
360
+
361
+ // Fetch existing attributes in target to skip already-created ones
362
+ const targetTableRes = await dbAdapter.getTable({ databaseId: targetDbId, tableId: targetTableId });
363
+ const targetInfo = targetTableRes.data || (targetTableRes.tables && targetTableRes.tables[0]);
364
+ const existingAttrs = targetInfo?.attributes || targetInfo?.columns || [];
365
+ const existingKeys = new Set(existingAttrs.map((a: any) => a.key || a.$id));
366
+
367
+ const uniformAttrs = (table.attributes || []).map((attr: any) => parseAttribute(attr as any));
333
368
  const nonRel = uniformAttrs.filter((a: any) => a.type !== 'relationship');
334
369
  for (const attr of nonRel) {
335
- const params = mapToCreateAttributeParams(attr as any, { databaseId: targetDbId, tableId: targetCollection.$id });
336
- await localAdapter.createAttribute(params);
370
+ if (existingKeys.has(attr.key)) continue;
371
+ const params = mapToCreateAttributeParams(attr as any, { databaseId: targetDbId, tableId: targetTableId });
372
+ await dbAdapter.createAttribute(params);
337
373
  await new Promise((r) => setTimeout(r, 150));
338
374
  }
339
375
 
@@ -343,8 +379,9 @@ export const transferDatabaseLocalToLocal = async (
343
379
  let lastStatus = '';
344
380
  while (Date.now() - start < maxWait) {
345
381
  try {
346
- const tableRes = await localAdapter.getTable({ databaseId: targetDbId, tableId: targetCollection.$id });
347
- const attrs = (tableRes as any).attributes || (tableRes as any).columns || [];
382
+ const tableRes = await dbAdapter.getTable({ databaseId: targetDbId, tableId: targetTableId });
383
+ const tInfo = tableRes.data || (tableRes.tables && tableRes.tables[0]);
384
+ const attrs = tInfo?.attributes || tInfo?.columns || [];
348
385
  const found = attrs.find((a: any) => a.key === attr.key);
349
386
  if (found) {
350
387
  if (found.status === 'available') break;
@@ -366,17 +403,18 @@ export const transferDatabaseLocalToLocal = async (
366
403
  // Relationship attributes
367
404
  const rels = uniformAttrs.filter((a: any) => a.type === 'relationship');
368
405
  for (const attr of rels) {
369
- const params = mapToCreateAttributeParams(attr as any, { databaseId: targetDbId, tableId: targetCollection.$id });
370
- await localAdapter.createAttribute(params);
406
+ if (existingKeys.has(attr.key)) continue;
407
+ const params = mapToCreateAttributeParams(attr as any, { databaseId: targetDbId, tableId: targetTableId });
408
+ await dbAdapter.createAttribute(params);
371
409
  await new Promise((r) => setTimeout(r, 150));
372
410
  }
373
411
 
374
412
  // Handle indexes via adapter (create or update)
375
- for (const idx of collection.indexes) {
413
+ for (const idx of (table.indexes || [])) {
376
414
  try {
377
- await localAdapter.createIndex({
415
+ await dbAdapter.createIndex({
378
416
  databaseId: targetDbId,
379
- tableId: targetCollection.$id,
417
+ tableId: targetTableId,
380
418
  key: (idx as any).key,
381
419
  type: (idx as any).type,
382
420
  attributes: (idx as any).attributes,
@@ -387,10 +425,10 @@ export const transferDatabaseLocalToLocal = async (
387
425
  } catch (e) {
388
426
  // Try update path by deleting and recreating if necessary
389
427
  try {
390
- await localAdapter.deleteIndex({ databaseId: targetDbId, tableId: targetCollection.$id, key: (idx as any).key });
391
- await localAdapter.createIndex({
428
+ await dbAdapter.deleteIndex({ databaseId: targetDbId, tableId: targetTableId, key: (idx as any).key });
429
+ await dbAdapter.createIndex({
392
430
  databaseId: targetDbId,
393
- tableId: targetCollection.$id,
431
+ tableId: targetTableId,
394
432
  key: (idx as any).key,
395
433
  type: (idx as any).type,
396
434
  attributes: (idx as any).attributes,
@@ -404,20 +442,20 @@ export const transferDatabaseLocalToLocal = async (
404
442
  }
405
443
  }
406
444
 
407
- // Transfer documents
445
+ // Transfer documents/rows via adapter
408
446
  const { transferDocumentsBetweenDbsLocalToLocal } = await import(
409
- "../collections/methods.js"
447
+ "../collections/transferOperations.js"
410
448
  );
411
449
  await transferDocumentsBetweenDbsLocalToLocal(
412
- localDb,
450
+ dbAdapter,
413
451
  fromDbId,
414
452
  targetDbId,
415
- collection.$id,
416
- targetCollection.$id
453
+ table.$id,
454
+ targetTableId
417
455
  );
418
456
  } catch (error) {
419
457
  MessageFormatter.error(
420
- `Error processing collection ${collection.name}`,
458
+ `Error processing table ${table.name}`,
421
459
  error instanceof Error ? error : new Error(String(error)),
422
460
  { prefix: "Transfer" }
423
461
  );
@@ -431,13 +469,18 @@ export const transferDatabaseLocalToRemote = async (
431
469
  projectId: string,
432
470
  apiKey: string,
433
471
  fromDbId: string,
434
- toDbId: string
472
+ toDbId: string,
473
+ collectionIds?: string[]
435
474
  ) => {
436
475
  const client = getAppwriteClient(endpoint, projectId, apiKey);
437
476
  const remoteDb = new Databases(client);
438
477
 
439
478
  // Get all collections from source database
440
- const sourceCollections = await fetchAllCollections(fromDbId, localDb);
479
+ let sourceCollections = await fetchAllCollections(fromDbId, localDb);
480
+ if (collectionIds && collectionIds.length > 0) {
481
+ const idSet = new Set(collectionIds);
482
+ sourceCollections = sourceCollections.filter((c) => idSet.has(c.$id));
483
+ }
441
484
  MessageFormatter.info(
442
485
  `Found ${sourceCollections.length} collections in source database`,
443
486
  { prefix: "Transfer" }
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import path from "path";
3
3
  import fs from "fs";
4
4
  import yaml from "js-yaml";
5
- import { logger } from "../../shared/logging.js";
5
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
6
6
  import type { ImportDef, AttributeMappings } from "@njdamstra/appwrite-utils";
7
7
 
8
8
  // YAML Import Configuration Schema
@@ -1,8 +1,8 @@
1
1
  import type { CollectionCreate, ImportDef } from "@njdamstra/appwrite-utils";
2
2
  import { YamlImportConfigLoader, type YamlImportConfig } from "./YamlImportConfigLoader.js";
3
3
  import { createImportSchemas, createImportExamples } from "./generateImportSchemas.js";
4
- import { logger } from "../../shared/logging.js";
5
- import { normalizeYamlData, usesTableTerminology, convertTerminology, type YamlCollectionData } from "../../utils/yamlConverter.js";
4
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
5
+ import { normalizeYamlData, usesTableTerminology, convertTerminology, type YamlCollectionData } from "@njdamstra/appwrite-utils-helpers";
6
6
  import path from "path";
7
7
  import fs from "fs";
8
8
  import yaml from "js-yaml";
@@ -1,6 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { logger } from "../../shared/logging.js";
3
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
4
4
 
5
5
  /**
6
6
  * Generates JSON Schema for YAML import configurations.
@@ -1,21 +1,20 @@
1
1
  import { mkdirSync, writeFileSync, existsSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { ulid } from "ulidx";
4
- import { MessageFormatter } from "./shared/messageFormatter.js";
4
+ import { MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
5
5
  import {
6
6
  detectAppwriteVersionCached,
7
7
  fetchServerVersion,
8
8
  isVersionAtLeast,
9
9
  type ApiMode
10
- } from "./utils/versionDetection.js";
10
+ } from "@njdamstra/appwrite-utils-helpers";
11
11
  import {
12
12
  loadAppwriteProjectConfig,
13
13
  findAppwriteProjectConfig,
14
14
  isTablesDBProject
15
- } from "./utils/projectConfig.js";
16
- import { findYamlConfig, generateYamlConfigTemplate } from "./config/yamlConfig.js";
17
- import { loadYamlConfig } from "./config/yamlConfig.js";
18
- import { hasSessionAuth } from "./utils/sessionAuth.js";
15
+ } from "@njdamstra/appwrite-utils-helpers";
16
+ import { findYamlConfig, generateYamlConfigTemplate, loadYamlConfig } from "@njdamstra/appwrite-utils-helpers";
17
+ import { hasSessionAuth } from "@njdamstra/appwrite-utils-helpers";
19
18
 
20
19
  /**
21
20
  * Terminology configuration for API mode-specific naming
@@ -3,7 +3,7 @@ import { loadConfig } from "./utils/loadConfigs.js";
3
3
  import path from "path";
4
4
  import fs from "fs";
5
5
  import type { AppwriteConfig } from "@njdamstra/appwrite-utils";
6
- import { MessageFormatter } from "./shared/messageFormatter.js";
6
+ import { MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
7
7
 
8
8
  export class SetupController {
9
9
  private currentDir: string;
@@ -1,6 +1,6 @@
1
- import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js";
2
- import { logger } from "./logging.js";
3
- import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
1
+ import type { DatabaseAdapter } from "@njdamstra/appwrite-utils-helpers";
2
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
3
+ import { tryAwaitWithRetry } from "@njdamstra/appwrite-utils-helpers";
4
4
  import { Query, ID } from "node-appwrite";
5
5
  import {
6
6
  BACKUP_TABLE_ID,
@@ -1,6 +1,6 @@
1
1
  import inquirer from "inquirer";
2
2
  import chalk from "chalk";
3
- import { MessageFormatter } from "./messageFormatter.js";
3
+ import { MessageFormatter } from '@njdamstra/appwrite-utils-helpers';
4
4
 
5
5
  export interface DestructiveOperationOptions {
6
6
  operation: string;
@@ -2,15 +2,15 @@ import { ID, Query, type Databases } from "node-appwrite";
2
2
  import { BatchSchema, OperationSchema, type Operation } from "../storage/schemas.js";
3
3
  import { AttributeMappingsSchema } from "@njdamstra/appwrite-utils";
4
4
  import { z } from "zod";
5
- import { logger } from "./logging.js";
6
- import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
5
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
6
+ import { tryAwaitWithRetry } from "@njdamstra/appwrite-utils-helpers";
7
7
  import {
8
8
  findOrCreateOperation as findOrCreateOp,
9
9
  updateOperation as updateOp,
10
10
  getOperation as getOp
11
11
  } from "./operationsTable.js";
12
- import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js";
13
- import { MessageFormatter } from "./messageFormatter.js";
12
+ import type { DatabaseAdapter } from "@njdamstra/appwrite-utils-helpers";
13
+ import { MessageFormatter } from '@njdamstra/appwrite-utils-helpers';
14
14
 
15
15
  /**
16
16
  * Object that contains the context for an action that needs to be executed after import
@@ -2,10 +2,9 @@ import { Query, type Databases, type Models } from "node-appwrite";
2
2
  import type { Attribute } from "@njdamstra/appwrite-utils";
3
3
  import { createOrUpdateAttributeWithStatusCheck } from "../collections/attributes.js";
4
4
  import { fetchAndCacheCollectionByName } from "../collections/methods.js";
5
- import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
6
- import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js";
7
- import { logger } from "../shared/logging.js";
8
- import { MessageFormatter } from "../shared/messageFormatter.js";
5
+ import { tryAwaitWithRetry } from "@njdamstra/appwrite-utils-helpers";
6
+ import type { DatabaseAdapter } from "@njdamstra/appwrite-utils-helpers";
7
+ import { logger, MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
9
8
 
10
9
  export interface QueuedOperation {
11
10
  type: "attribute";
@@ -1,6 +1,6 @@
1
- import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js";
2
- import { logger } from "./logging.js";
3
- import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
1
+ import type { DatabaseAdapter } from "@njdamstra/appwrite-utils-helpers";
2
+ import { logger } from '@njdamstra/appwrite-utils-helpers';
3
+ import { tryAwaitWithRetry } from "@njdamstra/appwrite-utils-helpers";
4
4
  import { Query, ID } from "node-appwrite";
5
5
  import {
6
6
  OPERATIONS_TABLE_ID,
@@ -1,6 +1,6 @@
1
1
  import cliProgress from "cli-progress";
2
2
  import chalk from "chalk";
3
- import { MessageFormatter } from "./messageFormatter.js";
3
+ import { MessageFormatter } from '@njdamstra/appwrite-utils-helpers';
4
4
 
5
5
  export interface ProgressOptions {
6
6
  title?: string;