@njdamstra/appwrite-utils-cli 1.8.9
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.
- package/CHANGELOG.md +19 -0
- package/README.md +1133 -0
- package/dist/adapters/AdapterFactory.d.ts +94 -0
- package/dist/adapters/AdapterFactory.js +405 -0
- package/dist/adapters/DatabaseAdapter.d.ts +233 -0
- package/dist/adapters/DatabaseAdapter.js +50 -0
- package/dist/adapters/LegacyAdapter.d.ts +50 -0
- package/dist/adapters/LegacyAdapter.js +612 -0
- package/dist/adapters/TablesDBAdapter.d.ts +45 -0
- package/dist/adapters/TablesDBAdapter.js +571 -0
- package/dist/adapters/index.d.ts +11 -0
- package/dist/adapters/index.js +12 -0
- package/dist/backups/operations/bucketBackup.d.ts +19 -0
- package/dist/backups/operations/bucketBackup.js +197 -0
- package/dist/backups/operations/collectionBackup.d.ts +30 -0
- package/dist/backups/operations/collectionBackup.js +201 -0
- package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
- package/dist/backups/operations/comprehensiveBackup.js +238 -0
- package/dist/backups/schemas/bucketManifest.d.ts +93 -0
- package/dist/backups/schemas/bucketManifest.js +33 -0
- package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
- package/dist/backups/schemas/comprehensiveManifest.js +32 -0
- package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
- package/dist/backups/tracking/centralizedTracking.js +274 -0
- package/dist/cli/commands/configCommands.d.ts +8 -0
- package/dist/cli/commands/configCommands.js +166 -0
- package/dist/cli/commands/databaseCommands.d.ts +13 -0
- package/dist/cli/commands/databaseCommands.js +554 -0
- package/dist/cli/commands/functionCommands.d.ts +7 -0
- package/dist/cli/commands/functionCommands.js +330 -0
- package/dist/cli/commands/schemaCommands.d.ts +7 -0
- package/dist/cli/commands/schemaCommands.js +169 -0
- package/dist/cli/commands/storageCommands.d.ts +5 -0
- package/dist/cli/commands/storageCommands.js +143 -0
- package/dist/cli/commands/transferCommands.d.ts +5 -0
- package/dist/cli/commands/transferCommands.js +384 -0
- package/dist/collections/attributes.d.ts +13 -0
- package/dist/collections/attributes.js +1364 -0
- package/dist/collections/indexes.d.ts +12 -0
- package/dist/collections/indexes.js +217 -0
- package/dist/collections/methods.d.ts +19 -0
- package/dist/collections/methods.js +682 -0
- package/dist/collections/tableOperations.d.ts +86 -0
- package/dist/collections/tableOperations.js +434 -0
- package/dist/collections/transferOperations.d.ts +8 -0
- package/dist/collections/transferOperations.js +412 -0
- package/dist/collections/wipeOperations.d.ts +16 -0
- package/dist/collections/wipeOperations.js +233 -0
- package/dist/config/ConfigManager.d.ts +445 -0
- package/dist/config/ConfigManager.js +625 -0
- package/dist/config/configMigration.d.ts +87 -0
- package/dist/config/configMigration.js +390 -0
- package/dist/config/configValidation.d.ts +66 -0
- package/dist/config/configValidation.js +358 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.js +7 -0
- package/dist/config/services/ConfigDiscoveryService.d.ts +126 -0
- package/dist/config/services/ConfigDiscoveryService.js +374 -0
- package/dist/config/services/ConfigLoaderService.d.ts +129 -0
- package/dist/config/services/ConfigLoaderService.js +540 -0
- package/dist/config/services/ConfigMergeService.d.ts +208 -0
- package/dist/config/services/ConfigMergeService.js +308 -0
- package/dist/config/services/ConfigValidationService.d.ts +214 -0
- package/dist/config/services/ConfigValidationService.js +310 -0
- package/dist/config/services/SessionAuthService.d.ts +225 -0
- package/dist/config/services/SessionAuthService.js +456 -0
- package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +1 -0
- package/dist/config/services/__tests__/ConfigMergeService.test.js +271 -0
- package/dist/config/services/index.d.ts +13 -0
- package/dist/config/services/index.js +10 -0
- package/dist/config/yamlConfig.d.ts +722 -0
- package/dist/config/yamlConfig.js +702 -0
- package/dist/databases/methods.d.ts +6 -0
- package/dist/databases/methods.js +35 -0
- package/dist/databases/setup.d.ts +5 -0
- package/dist/databases/setup.js +45 -0
- package/dist/examples/yamlTerminologyExample.d.ts +42 -0
- package/dist/examples/yamlTerminologyExample.js +272 -0
- package/dist/functions/deployments.d.ts +4 -0
- package/dist/functions/deployments.js +146 -0
- package/dist/functions/fnConfigDiscovery.d.ts +3 -0
- package/dist/functions/fnConfigDiscovery.js +108 -0
- package/dist/functions/methods.d.ts +16 -0
- package/dist/functions/methods.js +162 -0
- package/dist/functions/pathResolution.d.ts +37 -0
- package/dist/functions/pathResolution.js +185 -0
- package/dist/functions/templates/count-docs-in-collection/README.md +54 -0
- package/dist/functions/templates/count-docs-in-collection/src/main.ts +159 -0
- package/dist/functions/templates/count-docs-in-collection/src/request.ts +9 -0
- package/dist/functions/templates/hono-typescript/README.md +286 -0
- package/dist/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
- package/dist/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
- package/dist/functions/templates/hono-typescript/src/app.ts +180 -0
- package/dist/functions/templates/hono-typescript/src/context.ts +103 -0
- package/dist/functions/templates/hono-typescript/src/index.ts +54 -0
- package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
- package/dist/functions/templates/typescript-node/README.md +32 -0
- package/dist/functions/templates/typescript-node/src/context.ts +103 -0
- package/dist/functions/templates/typescript-node/src/index.ts +29 -0
- package/dist/functions/templates/uv/README.md +31 -0
- package/dist/functions/templates/uv/pyproject.toml +30 -0
- package/dist/functions/templates/uv/src/__init__.py +0 -0
- package/dist/functions/templates/uv/src/context.py +125 -0
- package/dist/functions/templates/uv/src/index.py +46 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +57 -0
- package/dist/interactiveCLI.d.ts +31 -0
- package/dist/interactiveCLI.js +898 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +1172 -0
- package/dist/migrations/afterImportActions.d.ts +17 -0
- package/dist/migrations/afterImportActions.js +306 -0
- package/dist/migrations/appwriteToX.d.ts +211 -0
- package/dist/migrations/appwriteToX.js +491 -0
- package/dist/migrations/comprehensiveTransfer.d.ts +147 -0
- package/dist/migrations/comprehensiveTransfer.js +1317 -0
- package/dist/migrations/dataLoader.d.ts +753 -0
- package/dist/migrations/dataLoader.js +1250 -0
- package/dist/migrations/importController.d.ts +23 -0
- package/dist/migrations/importController.js +268 -0
- package/dist/migrations/importDataActions.d.ts +50 -0
- package/dist/migrations/importDataActions.js +230 -0
- package/dist/migrations/relationships.d.ts +29 -0
- package/dist/migrations/relationships.js +204 -0
- package/dist/migrations/services/DataTransformationService.d.ts +55 -0
- package/dist/migrations/services/DataTransformationService.js +158 -0
- package/dist/migrations/services/FileHandlerService.d.ts +75 -0
- package/dist/migrations/services/FileHandlerService.js +236 -0
- package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
- package/dist/migrations/services/ImportOrchestrator.js +485 -0
- package/dist/migrations/services/RateLimitManager.d.ts +138 -0
- package/dist/migrations/services/RateLimitManager.js +279 -0
- package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
- package/dist/migrations/services/RelationshipResolver.js +332 -0
- package/dist/migrations/services/UserMappingService.d.ts +109 -0
- package/dist/migrations/services/UserMappingService.js +277 -0
- package/dist/migrations/services/ValidationService.d.ts +74 -0
- package/dist/migrations/services/ValidationService.js +260 -0
- package/dist/migrations/transfer.d.ts +26 -0
- package/dist/migrations/transfer.js +608 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +131 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.js +383 -0
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +93 -0
- package/dist/migrations/yaml/YamlImportIntegration.js +341 -0
- package/dist/migrations/yaml/generateImportSchemas.d.ts +30 -0
- package/dist/migrations/yaml/generateImportSchemas.js +1327 -0
- package/dist/schemas/authUser.d.ts +24 -0
- package/dist/schemas/authUser.js +17 -0
- package/dist/setup.d.ts +2 -0
- package/dist/setup.js +5 -0
- package/dist/setupCommands.d.ts +58 -0
- package/dist/setupCommands.js +490 -0
- package/dist/setupController.d.ts +9 -0
- package/dist/setupController.js +34 -0
- package/dist/shared/attributeMapper.d.ts +20 -0
- package/dist/shared/attributeMapper.js +203 -0
- package/dist/shared/backupMetadataSchema.d.ts +94 -0
- package/dist/shared/backupMetadataSchema.js +38 -0
- package/dist/shared/backupTracking.d.ts +18 -0
- package/dist/shared/backupTracking.js +176 -0
- package/dist/shared/confirmationDialogs.d.ts +75 -0
- package/dist/shared/confirmationDialogs.js +236 -0
- package/dist/shared/errorUtils.d.ts +54 -0
- package/dist/shared/errorUtils.js +95 -0
- package/dist/shared/functionManager.d.ts +48 -0
- package/dist/shared/functionManager.js +336 -0
- package/dist/shared/indexManager.d.ts +24 -0
- package/dist/shared/indexManager.js +151 -0
- package/dist/shared/jsonSchemaGenerator.d.ts +50 -0
- package/dist/shared/jsonSchemaGenerator.js +290 -0
- package/dist/shared/logging.d.ts +61 -0
- package/dist/shared/logging.js +116 -0
- package/dist/shared/messageFormatter.d.ts +39 -0
- package/dist/shared/messageFormatter.js +162 -0
- package/dist/shared/migrationHelpers.d.ts +61 -0
- package/dist/shared/migrationHelpers.js +145 -0
- package/dist/shared/operationLogger.d.ts +10 -0
- package/dist/shared/operationLogger.js +12 -0
- package/dist/shared/operationQueue.d.ts +40 -0
- package/dist/shared/operationQueue.js +311 -0
- package/dist/shared/operationsTable.d.ts +26 -0
- package/dist/shared/operationsTable.js +286 -0
- package/dist/shared/operationsTableSchema.d.ts +48 -0
- package/dist/shared/operationsTableSchema.js +35 -0
- package/dist/shared/progressManager.d.ts +62 -0
- package/dist/shared/progressManager.js +215 -0
- package/dist/shared/pydanticModelGenerator.d.ts +17 -0
- package/dist/shared/pydanticModelGenerator.js +615 -0
- package/dist/shared/relationshipExtractor.d.ts +56 -0
- package/dist/shared/relationshipExtractor.js +138 -0
- package/dist/shared/schemaGenerator.d.ts +40 -0
- package/dist/shared/schemaGenerator.js +556 -0
- package/dist/shared/selectionDialogs.d.ts +214 -0
- package/dist/shared/selectionDialogs.js +544 -0
- package/dist/storage/backupCompression.d.ts +20 -0
- package/dist/storage/backupCompression.js +67 -0
- package/dist/storage/methods.d.ts +32 -0
- package/dist/storage/methods.js +472 -0
- package/dist/storage/schemas.d.ts +842 -0
- package/dist/storage/schemas.js +175 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +3 -0
- package/dist/users/methods.d.ts +16 -0
- package/dist/users/methods.js +277 -0
- package/dist/utils/ClientFactory.d.ts +87 -0
- package/dist/utils/ClientFactory.js +212 -0
- package/dist/utils/configDiscovery.d.ts +78 -0
- package/dist/utils/configDiscovery.js +472 -0
- package/dist/utils/configMigration.d.ts +1 -0
- package/dist/utils/configMigration.js +261 -0
- package/dist/utils/constantsGenerator.d.ts +31 -0
- package/dist/utils/constantsGenerator.js +321 -0
- package/dist/utils/dataConverters.d.ts +46 -0
- package/dist/utils/dataConverters.js +139 -0
- package/dist/utils/directoryUtils.d.ts +22 -0
- package/dist/utils/directoryUtils.js +59 -0
- package/dist/utils/getClientFromConfig.d.ts +39 -0
- package/dist/utils/getClientFromConfig.js +199 -0
- package/dist/utils/helperFunctions.d.ts +63 -0
- package/dist/utils/helperFunctions.js +156 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/loadConfigs.d.ts +50 -0
- package/dist/utils/loadConfigs.js +358 -0
- package/dist/utils/pathResolvers.d.ts +53 -0
- package/dist/utils/pathResolvers.js +72 -0
- package/dist/utils/projectConfig.d.ts +119 -0
- package/dist/utils/projectConfig.js +171 -0
- package/dist/utils/retryFailedPromises.d.ts +2 -0
- package/dist/utils/retryFailedPromises.js +23 -0
- package/dist/utils/sessionAuth.d.ts +48 -0
- package/dist/utils/sessionAuth.js +164 -0
- package/dist/utils/setupFiles.d.ts +4 -0
- package/dist/utils/setupFiles.js +1192 -0
- package/dist/utils/typeGuards.d.ts +35 -0
- package/dist/utils/typeGuards.js +57 -0
- package/dist/utils/validationRules.d.ts +43 -0
- package/dist/utils/validationRules.js +42 -0
- package/dist/utils/versionDetection.d.ts +58 -0
- package/dist/utils/versionDetection.js +251 -0
- package/dist/utils/yamlConverter.d.ts +100 -0
- package/dist/utils/yamlConverter.js +428 -0
- package/dist/utils/yamlLoader.d.ts +70 -0
- package/dist/utils/yamlLoader.js +267 -0
- package/dist/utilsController.d.ts +106 -0
- package/dist/utilsController.js +863 -0
- package/package.json +75 -0
- package/scripts/copy-templates.ts +23 -0
- package/src/adapters/AdapterFactory.ts +510 -0
- package/src/adapters/DatabaseAdapter.ts +306 -0
- package/src/adapters/LegacyAdapter.ts +841 -0
- package/src/adapters/TablesDBAdapter.ts +773 -0
- package/src/adapters/index.ts +37 -0
- package/src/backups/operations/bucketBackup.ts +277 -0
- package/src/backups/operations/collectionBackup.ts +310 -0
- package/src/backups/operations/comprehensiveBackup.ts +342 -0
- package/src/backups/schemas/bucketManifest.ts +78 -0
- package/src/backups/schemas/comprehensiveManifest.ts +76 -0
- package/src/backups/tracking/centralizedTracking.ts +352 -0
- package/src/cli/commands/configCommands.ts +201 -0
- package/src/cli/commands/databaseCommands.ts +749 -0
- package/src/cli/commands/functionCommands.ts +418 -0
- package/src/cli/commands/schemaCommands.ts +200 -0
- package/src/cli/commands/storageCommands.ts +152 -0
- package/src/cli/commands/transferCommands.ts +457 -0
- package/src/collections/attributes.ts +2054 -0
- package/src/collections/attributes.ts.backup +1555 -0
- package/src/collections/indexes.ts +352 -0
- package/src/collections/methods.ts +745 -0
- package/src/collections/tableOperations.ts +506 -0
- package/src/collections/transferOperations.ts +590 -0
- package/src/collections/wipeOperations.ts +346 -0
- package/src/config/ConfigManager.ts +808 -0
- package/src/config/README.md +274 -0
- package/src/config/configMigration.ts +575 -0
- package/src/config/configValidation.ts +445 -0
- package/src/config/index.ts +10 -0
- package/src/config/services/ConfigDiscoveryService.ts +463 -0
- package/src/config/services/ConfigLoaderService.ts +740 -0
- package/src/config/services/ConfigMergeService.ts +388 -0
- package/src/config/services/ConfigValidationService.ts +394 -0
- package/src/config/services/SessionAuthService.ts +565 -0
- package/src/config/services/__tests__/ConfigMergeService.test.ts +351 -0
- package/src/config/services/index.ts +29 -0
- package/src/config/yamlConfig.ts +761 -0
- package/src/databases/methods.ts +49 -0
- package/src/databases/setup.ts +77 -0
- package/src/examples/yamlTerminologyExample.ts +346 -0
- package/src/functions/deployments.ts +220 -0
- package/src/functions/fnConfigDiscovery.ts +103 -0
- package/src/functions/methods.ts +271 -0
- package/src/functions/pathResolution.ts +227 -0
- package/src/functions/templates/count-docs-in-collection/README.md +54 -0
- package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -0
- package/src/functions/templates/count-docs-in-collection/src/request.ts +9 -0
- package/src/functions/templates/hono-typescript/README.md +286 -0
- package/src/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
- package/src/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
- package/src/functions/templates/hono-typescript/src/app.ts +180 -0
- package/src/functions/templates/hono-typescript/src/context.ts +103 -0
- package/src/functions/templates/hono-typescript/src/index.ts +54 -0
- package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
- package/src/functions/templates/typescript-node/README.md +32 -0
- package/src/functions/templates/typescript-node/src/context.ts +103 -0
- package/src/functions/templates/typescript-node/src/index.ts +29 -0
- package/src/functions/templates/uv/README.md +31 -0
- package/src/functions/templates/uv/pyproject.toml +30 -0
- package/src/functions/templates/uv/src/__init__.py +0 -0
- package/src/functions/templates/uv/src/context.py +125 -0
- package/src/functions/templates/uv/src/index.py +46 -0
- package/src/init.ts +62 -0
- package/src/interactiveCLI.ts +1136 -0
- package/src/main.ts +1661 -0
- package/src/migrations/afterImportActions.ts +580 -0
- package/src/migrations/appwriteToX.ts +664 -0
- package/src/migrations/comprehensiveTransfer.ts +2285 -0
- package/src/migrations/dataLoader.ts +1702 -0
- package/src/migrations/importController.ts +428 -0
- package/src/migrations/importDataActions.ts +315 -0
- package/src/migrations/relationships.ts +334 -0
- package/src/migrations/services/DataTransformationService.ts +196 -0
- package/src/migrations/services/FileHandlerService.ts +311 -0
- package/src/migrations/services/ImportOrchestrator.ts +666 -0
- package/src/migrations/services/RateLimitManager.ts +363 -0
- package/src/migrations/services/RelationshipResolver.ts +461 -0
- package/src/migrations/services/UserMappingService.ts +345 -0
- package/src/migrations/services/ValidationService.ts +349 -0
- package/src/migrations/transfer.ts +1068 -0
- package/src/migrations/yaml/YamlImportConfigLoader.ts +439 -0
- package/src/migrations/yaml/YamlImportIntegration.ts +446 -0
- package/src/migrations/yaml/generateImportSchemas.ts +1354 -0
- package/src/schemas/authUser.ts +23 -0
- package/src/setup.ts +8 -0
- package/src/setupCommands.ts +603 -0
- package/src/setupController.ts +43 -0
- package/src/shared/attributeMapper.ts +229 -0
- package/src/shared/backupMetadataSchema.ts +93 -0
- package/src/shared/backupTracking.ts +211 -0
- package/src/shared/confirmationDialogs.ts +327 -0
- package/src/shared/errorUtils.ts +110 -0
- package/src/shared/functionManager.ts +525 -0
- package/src/shared/indexManager.ts +254 -0
- package/src/shared/jsonSchemaGenerator.ts +383 -0
- package/src/shared/logging.ts +149 -0
- package/src/shared/messageFormatter.ts +208 -0
- package/src/shared/migrationHelpers.ts +232 -0
- package/src/shared/operationLogger.ts +20 -0
- package/src/shared/operationQueue.ts +377 -0
- package/src/shared/operationsTable.ts +338 -0
- package/src/shared/operationsTableSchema.ts +60 -0
- package/src/shared/progressManager.ts +278 -0
- package/src/shared/pydanticModelGenerator.ts +618 -0
- package/src/shared/relationshipExtractor.ts +214 -0
- package/src/shared/schemaGenerator.ts +644 -0
- package/src/shared/selectionDialogs.ts +749 -0
- package/src/storage/backupCompression.ts +88 -0
- package/src/storage/methods.ts +698 -0
- package/src/storage/schemas.ts +205 -0
- package/src/types/node-appwrite-tablesdb.d.ts +44 -0
- package/src/types.ts +9 -0
- package/src/users/methods.ts +359 -0
- package/src/utils/ClientFactory.ts +240 -0
- package/src/utils/configDiscovery.ts +557 -0
- package/src/utils/configMigration.ts +348 -0
- package/src/utils/constantsGenerator.ts +369 -0
- package/src/utils/dataConverters.ts +159 -0
- package/src/utils/directoryUtils.ts +61 -0
- package/src/utils/getClientFromConfig.ts +257 -0
- package/src/utils/helperFunctions.ts +228 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/loadConfigs.ts +449 -0
- package/src/utils/pathResolvers.ts +81 -0
- package/src/utils/projectConfig.ts +299 -0
- package/src/utils/retryFailedPromises.ts +29 -0
- package/src/utils/sessionAuth.ts +230 -0
- package/src/utils/setupFiles.ts +1238 -0
- package/src/utils/typeGuards.ts +65 -0
- package/src/utils/validationRules.ts +88 -0
- package/src/utils/versionDetection.ts +292 -0
- package/src/utils/yamlConverter.ts +542 -0
- package/src/utils/yamlLoader.ts +371 -0
- package/src/utilsController.ts +1203 -0
- package/tests/README.md +497 -0
- package/tests/adapters/AdapterFactory.test.ts +277 -0
- package/tests/integration/syncOperations.test.ts +463 -0
- package/tests/jest.config.js +25 -0
- package/tests/migration/configMigration.test.ts +546 -0
- package/tests/setup.ts +62 -0
- package/tests/testUtils.ts +340 -0
- package/tests/utils/loadConfigs.test.ts +350 -0
- package/tests/validation/configValidation.test.ts +412 -0
- package/tsconfig.json +44 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { Databases, Query } from "node-appwrite";
|
|
2
|
+
import { fetchAllCollections } from "../collections/methods.js";
|
|
3
|
+
import { logger } from "../shared/logging.js";
|
|
4
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
|
5
|
+
/**
|
|
6
|
+
* Finds collections that have defined relationship attributes.
|
|
7
|
+
*/
|
|
8
|
+
export const findCollectionsWithRelationships = (config) => {
|
|
9
|
+
const toReturn = new Map();
|
|
10
|
+
if (!config.collections) {
|
|
11
|
+
return toReturn;
|
|
12
|
+
}
|
|
13
|
+
for (const collection of config.collections) {
|
|
14
|
+
if (collection.attributes) {
|
|
15
|
+
for (const attribute of collection.attributes) {
|
|
16
|
+
if (attribute.type === "relationship" &&
|
|
17
|
+
attribute.twoWay &&
|
|
18
|
+
attribute.side === "parent") {
|
|
19
|
+
toReturn.set(collection.name, toReturn.get(collection.name) || []);
|
|
20
|
+
toReturn
|
|
21
|
+
.get(collection.name)
|
|
22
|
+
?.push(attribute);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return toReturn;
|
|
28
|
+
};
|
|
29
|
+
export async function resolveAndUpdateRelationships(dbId, database, config) {
|
|
30
|
+
const collections = await fetchAllCollections(dbId, database);
|
|
31
|
+
const collectionsWithRelationships = findCollectionsWithRelationships(config);
|
|
32
|
+
// Process each collection sequentially
|
|
33
|
+
for (const collection of collections) {
|
|
34
|
+
MessageFormatter.processing(`Processing collection: ${collection.name} (${collection.$id})`, { prefix: "Migration" });
|
|
35
|
+
const relAttributeMap = collectionsWithRelationships.get(collection.name); // Get the relationship attributes for the collections
|
|
36
|
+
if (!relAttributeMap) {
|
|
37
|
+
MessageFormatter.info(`No mapping found for collection: ${collection.name}, skipping...`, { prefix: "Migration" });
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
await processCollection(dbId, database, collection, relAttributeMap);
|
|
41
|
+
}
|
|
42
|
+
MessageFormatter.success(`Completed relationship resolution and update for database ID: ${dbId}`, { prefix: "Migration" });
|
|
43
|
+
}
|
|
44
|
+
async function processCollection(dbId, database, collection, relAttributeMap) {
|
|
45
|
+
let after; // For pagination
|
|
46
|
+
let hasMore = true;
|
|
47
|
+
while (hasMore) {
|
|
48
|
+
const response = await database.listDocuments(dbId, collection.$id, [
|
|
49
|
+
Query.limit(100), // Fetch documents in batches of 100
|
|
50
|
+
...(after ? [Query.cursorAfter(after)] : []),
|
|
51
|
+
]);
|
|
52
|
+
const documents = response.documents;
|
|
53
|
+
MessageFormatter.info(`Fetched ${documents.length} documents from collection: ${collection.name}`, { prefix: "Migration" });
|
|
54
|
+
if (documents.length > 0) {
|
|
55
|
+
const updates = await prepareDocumentUpdates(database, dbId, collection.name, documents, relAttributeMap);
|
|
56
|
+
// Execute updates for the current batch
|
|
57
|
+
await executeUpdatesInBatches(dbId, database, updates);
|
|
58
|
+
}
|
|
59
|
+
if (documents.length === 100) {
|
|
60
|
+
after = documents[documents.length - 1].$id; // Prepare for the next page
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
hasMore = false; // No more documents to fetch
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function findDocumentsByOriginalId(database, dbId, targetCollection, targetKey, originalId) {
|
|
68
|
+
const relatedCollectionId = targetCollection.$id;
|
|
69
|
+
const collection = await database.listCollections(dbId, [
|
|
70
|
+
Query.equal("$id", relatedCollectionId),
|
|
71
|
+
]);
|
|
72
|
+
if (collection.total === 0) {
|
|
73
|
+
MessageFormatter.warning(`Collection ${relatedCollectionId} doesn't exist, skipping...`, { prefix: "Migration" });
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const targetAttr = collection.collections[0].attributes.find(
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
(attr) => attr.key === targetKey);
|
|
79
|
+
if (!targetAttr) {
|
|
80
|
+
MessageFormatter.warning(`Attribute ${targetKey} not found in collection ${relatedCollectionId}, skipping...`, { prefix: "Migration" });
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
let queries = [];
|
|
84
|
+
if (targetAttr.array) {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
queries.push(Query.contains(targetKey, originalId));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
queries.push(Query.equal(targetKey, originalId));
|
|
90
|
+
}
|
|
91
|
+
const response = await database.listDocuments(dbId, relatedCollectionId, [
|
|
92
|
+
...queries,
|
|
93
|
+
Query.limit(500), // Adjust the limit based on your needs or implement pagination
|
|
94
|
+
]);
|
|
95
|
+
if (response.documents.length < 0) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
else if (response.documents.length > 0) {
|
|
99
|
+
return response.documents;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function prepareDocumentUpdates(database, dbId, collectionName, documents, relationships) {
|
|
106
|
+
MessageFormatter.processing(`Preparing updates for collection: ${collectionName}`, { prefix: "Migration" });
|
|
107
|
+
const updates = [];
|
|
108
|
+
const thisCollection = (await database.listCollections(dbId, [Query.equal("name", collectionName)])).collections[0];
|
|
109
|
+
const thisCollectionId = thisCollection?.$id;
|
|
110
|
+
if (!thisCollectionId) {
|
|
111
|
+
MessageFormatter.warning(`No collection found with name: ${collectionName}`, { prefix: "Migration" });
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
for (const doc of documents) {
|
|
115
|
+
let updatePayload = {};
|
|
116
|
+
for (const rel of relationships) {
|
|
117
|
+
// Skip if not dealing with the parent side of a two-way relationship
|
|
118
|
+
if (rel.twoWay && rel.side !== "parent") {
|
|
119
|
+
MessageFormatter.info("Skipping non-parent side of two-way relationship...", { prefix: "Migration" });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const isSingleReference = rel.relationType === "oneToOne" || rel.relationType === "manyToOne";
|
|
123
|
+
const originalIdField = rel.importMapping?.originalIdField;
|
|
124
|
+
const targetField = rel.importMapping?.targetField || originalIdField; // Use originalIdField if targetField is not specified
|
|
125
|
+
if (!originalIdField) {
|
|
126
|
+
MessageFormatter.warning("Missing originalIdField in importMapping, skipping...", { prefix: "Migration" });
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const originalId = doc[originalIdField];
|
|
130
|
+
if (!originalId) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const relatedCollection = (await database.listCollections(dbId, [
|
|
134
|
+
Query.equal("name", rel.relatedCollection),
|
|
135
|
+
])).collections[0];
|
|
136
|
+
if (!relatedCollection) {
|
|
137
|
+
MessageFormatter.warning(`Related collection ${rel.relatedCollection} not found, skipping...`, { prefix: "Migration" });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const foundDocuments = await findDocumentsByOriginalId(database, dbId, relatedCollection, targetField, String(originalId));
|
|
141
|
+
if (foundDocuments && foundDocuments.length > 0) {
|
|
142
|
+
const relationshipKey = rel.key;
|
|
143
|
+
const existingRefs = doc[relationshipKey] || [];
|
|
144
|
+
let existingRefIds = [];
|
|
145
|
+
if (Array.isArray(existingRefs)) {
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
existingRefIds = existingRefs.map((ref) => ref.$id);
|
|
148
|
+
}
|
|
149
|
+
else if (existingRefs) {
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
existingRefIds = [existingRefs.$id];
|
|
152
|
+
}
|
|
153
|
+
const newRefs = foundDocuments.map((fd) => fd.$id);
|
|
154
|
+
const allRefs = [...new Set([...existingRefIds, ...newRefs])]; // Combine and remove duplicates
|
|
155
|
+
// Update logic based on the relationship cardinality
|
|
156
|
+
updatePayload[relationshipKey] = isSingleReference
|
|
157
|
+
? newRefs[0] || existingRefIds[0]
|
|
158
|
+
: allRefs;
|
|
159
|
+
MessageFormatter.info(`Updating ${relationshipKey} with ${allRefs.length} refs`, { prefix: "Migration" });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (Object.keys(updatePayload).length > 0) {
|
|
163
|
+
updates.push({
|
|
164
|
+
collectionId: thisCollectionId,
|
|
165
|
+
documentId: doc.$id,
|
|
166
|
+
updatePayload: updatePayload,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return updates;
|
|
171
|
+
}
|
|
172
|
+
async function processInBatches(items, batchSize, processFunction) {
|
|
173
|
+
const maxParallelBatches = 25; // Adjust this value to control the number of parallel batches
|
|
174
|
+
let currentIndex = 0;
|
|
175
|
+
let activeBatchPromises = [];
|
|
176
|
+
while (currentIndex < items.length) {
|
|
177
|
+
// While there's still data to process and we haven't reached our parallel limit
|
|
178
|
+
while (currentIndex < items.length &&
|
|
179
|
+
activeBatchPromises.length < maxParallelBatches) {
|
|
180
|
+
const batch = items.slice(currentIndex, currentIndex + batchSize);
|
|
181
|
+
currentIndex += batchSize;
|
|
182
|
+
// Add new batch processing promise to the array
|
|
183
|
+
activeBatchPromises.push(processFunction(batch));
|
|
184
|
+
}
|
|
185
|
+
// Wait for one of the batch processes to complete
|
|
186
|
+
await Promise.race(activeBatchPromises).then(() => {
|
|
187
|
+
// Remove the resolved promise from the activeBatchPromises array
|
|
188
|
+
activeBatchPromises = activeBatchPromises.filter((p) => p !== Promise.race(activeBatchPromises));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// After processing all batches, ensure all active promises are resolved
|
|
192
|
+
await Promise.all(activeBatchPromises);
|
|
193
|
+
}
|
|
194
|
+
async function executeUpdatesInBatches(dbId, database, updates) {
|
|
195
|
+
const batchSize = 25; // Adjust based on your rate limit and performance testing
|
|
196
|
+
for (let i = 0; i < updates.length; i += batchSize) {
|
|
197
|
+
const batch = updates.slice(i, i + batchSize);
|
|
198
|
+
await Promise.all(batch.map((update) => database
|
|
199
|
+
.updateDocument(dbId, update.collectionId, update.documentId, update.updatePayload)
|
|
200
|
+
.catch((error) => {
|
|
201
|
+
logger.error(`Error updating doc ${update.documentId} in ${dbId}, update payload: ${JSON.stringify(update.updatePayload, undefined, 4)}, error: ${error}`);
|
|
202
|
+
})));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { AttributeMappings, ConfigDatabase, CollectionCreate } from "@njdamstra/appwrite-utils";
|
|
2
|
+
import type { ImportDataActions } from "../importDataActions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service responsible for data transformation during import.
|
|
5
|
+
* Extracted from DataLoader to provide focused, testable transformation logic.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DataTransformationService {
|
|
8
|
+
private importDataActions;
|
|
9
|
+
constructor(importDataActions: ImportDataActions);
|
|
10
|
+
/**
|
|
11
|
+
* Transforms the given item based on the provided attribute mappings.
|
|
12
|
+
* This method applies conversion rules to the item's attributes as defined in the attribute mappings.
|
|
13
|
+
*
|
|
14
|
+
* Preserves existing transformation logic from DataLoader.
|
|
15
|
+
*
|
|
16
|
+
* @param item - The item to be transformed.
|
|
17
|
+
* @param attributeMappings - The mappings that define how each attribute should be transformed.
|
|
18
|
+
* @returns The transformed item.
|
|
19
|
+
*/
|
|
20
|
+
transformData(item: any, attributeMappings: AttributeMappings): any;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a context object for data transformation.
|
|
23
|
+
* Preserves existing context creation logic from DataLoader.
|
|
24
|
+
*
|
|
25
|
+
* @param db - The database configuration
|
|
26
|
+
* @param collection - The collection configuration
|
|
27
|
+
* @param item - The raw item data
|
|
28
|
+
* @param docId - The document ID
|
|
29
|
+
* @returns Context object for transformation
|
|
30
|
+
*/
|
|
31
|
+
createContext(db: ConfigDatabase, collection: CollectionCreate, item: any, docId: string): any;
|
|
32
|
+
/**
|
|
33
|
+
* Merges two objects by updating the source object with the target object's values.
|
|
34
|
+
* Preserves existing merge logic from DataLoader.
|
|
35
|
+
*
|
|
36
|
+
* It iterates through the target object's keys and updates the source object if:
|
|
37
|
+
* - The source object has the key.
|
|
38
|
+
* - The target object's value for that key is not null, undefined, or an empty string.
|
|
39
|
+
* - If the target object has an array value, it concatenates the values and removes duplicates.
|
|
40
|
+
*
|
|
41
|
+
* @param source - The source object to be updated.
|
|
42
|
+
* @param update - The target object with values to update the source object.
|
|
43
|
+
* @returns The updated source object.
|
|
44
|
+
*/
|
|
45
|
+
mergeObjects(source: any, update: any): any;
|
|
46
|
+
/**
|
|
47
|
+
* Validates the transformed data item using existing validation logic.
|
|
48
|
+
*
|
|
49
|
+
* @param transformedData - The transformed data to validate
|
|
50
|
+
* @param attributeMappings - The attribute mappings containing validation rules
|
|
51
|
+
* @param context - The context for validation
|
|
52
|
+
* @returns True if valid, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
validateTransformedData(transformedData: any, attributeMappings: AttributeMappings, context: any): boolean;
|
|
55
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { convertObjectByAttributeMappings } from "../../utils/dataConverters.js";
|
|
2
|
+
import { logger } from "../../shared/logging.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service responsible for data transformation during import.
|
|
5
|
+
* Extracted from DataLoader to provide focused, testable transformation logic.
|
|
6
|
+
*/
|
|
7
|
+
export class DataTransformationService {
|
|
8
|
+
importDataActions;
|
|
9
|
+
constructor(importDataActions) {
|
|
10
|
+
this.importDataActions = importDataActions;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Transforms the given item based on the provided attribute mappings.
|
|
14
|
+
* This method applies conversion rules to the item's attributes as defined in the attribute mappings.
|
|
15
|
+
*
|
|
16
|
+
* Preserves existing transformation logic from DataLoader.
|
|
17
|
+
*
|
|
18
|
+
* @param item - The item to be transformed.
|
|
19
|
+
* @param attributeMappings - The mappings that define how each attribute should be transformed.
|
|
20
|
+
* @returns The transformed item.
|
|
21
|
+
*/
|
|
22
|
+
transformData(item, attributeMappings) {
|
|
23
|
+
try {
|
|
24
|
+
// Convert the item using the attribute mappings provided
|
|
25
|
+
const convertedItem = convertObjectByAttributeMappings(item, attributeMappings);
|
|
26
|
+
// Run additional converter functions on the converted item, if any
|
|
27
|
+
return this.importDataActions.runConverterFunctions(convertedItem, attributeMappings);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
logger.error(`Error transforming data for item: ${JSON.stringify(item, null, 2)}`, error);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a context object for data transformation.
|
|
36
|
+
* Preserves existing context creation logic from DataLoader.
|
|
37
|
+
*
|
|
38
|
+
* @param db - The database configuration
|
|
39
|
+
* @param collection - The collection configuration
|
|
40
|
+
* @param item - The raw item data
|
|
41
|
+
* @param docId - The document ID
|
|
42
|
+
* @returns Context object for transformation
|
|
43
|
+
*/
|
|
44
|
+
createContext(db, collection, item, docId) {
|
|
45
|
+
return {
|
|
46
|
+
...item, // Spread the item data for easy access to its properties
|
|
47
|
+
dbId: db.$id,
|
|
48
|
+
dbName: db.name,
|
|
49
|
+
collId: collection.$id,
|
|
50
|
+
collName: collection.name,
|
|
51
|
+
docId: docId,
|
|
52
|
+
createdDoc: {}, // Initially empty, to be updated when the document is created
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Merges two objects by updating the source object with the target object's values.
|
|
57
|
+
* Preserves existing merge logic from DataLoader.
|
|
58
|
+
*
|
|
59
|
+
* It iterates through the target object's keys and updates the source object if:
|
|
60
|
+
* - The source object has the key.
|
|
61
|
+
* - The target object's value for that key is not null, undefined, or an empty string.
|
|
62
|
+
* - If the target object has an array value, it concatenates the values and removes duplicates.
|
|
63
|
+
*
|
|
64
|
+
* @param source - The source object to be updated.
|
|
65
|
+
* @param update - The target object with values to update the source object.
|
|
66
|
+
* @returns The updated source object.
|
|
67
|
+
*/
|
|
68
|
+
mergeObjects(source, update) {
|
|
69
|
+
// Create a new object to hold the merged result
|
|
70
|
+
const result = { ...source };
|
|
71
|
+
// Loop through the keys of the object we care about
|
|
72
|
+
for (const [key, value] of Object.entries(source)) {
|
|
73
|
+
// Check if the key exists in the target object
|
|
74
|
+
if (!Object.hasOwn(update, key)) {
|
|
75
|
+
// If the key doesn't exist, we can just skip it
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (update[key] === value) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
// If the value ain't here, we can just do whatever man
|
|
82
|
+
if (value === undefined || value === null || value === "") {
|
|
83
|
+
// If the update key is defined
|
|
84
|
+
if (update[key] !== undefined &&
|
|
85
|
+
update[key] !== null &&
|
|
86
|
+
update[key] !== "") {
|
|
87
|
+
// might as well use it eh?
|
|
88
|
+
result[key] = update[key];
|
|
89
|
+
}
|
|
90
|
+
// ELSE if the value is an array, because it would then not be === to those things above
|
|
91
|
+
}
|
|
92
|
+
else if (Array.isArray(value)) {
|
|
93
|
+
// Get the update value
|
|
94
|
+
const updateValue = update[key];
|
|
95
|
+
// If the update value is an array, concatenate and remove duplicates
|
|
96
|
+
// and poopy data
|
|
97
|
+
if (Array.isArray(updateValue)) {
|
|
98
|
+
result[key] = [...new Set([...value, ...updateValue])].filter((item) => item !== null && item !== undefined && item !== "");
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// If the update value is not an array, just use it
|
|
102
|
+
result[key] = [...value, updateValue].filter((item) => item !== null && item !== undefined && item !== "");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (typeof value === "object" && !Array.isArray(value)) {
|
|
106
|
+
// If the value is an object, we need to merge it
|
|
107
|
+
if (typeof update[key] === "object" && !Array.isArray(update[key])) {
|
|
108
|
+
result[key] = this.mergeObjects(value, update[key]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Finally, the source value is defined, and not an array, so we don't care about the update value
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Because the objects should technically always be validated FIRST, we can assume the update keys are also defined on the source object
|
|
117
|
+
for (const [key, value] of Object.entries(update)) {
|
|
118
|
+
if (value === undefined || value === null || value === "") {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
else if (!Object.hasOwn(source, key)) {
|
|
122
|
+
result[key] = value;
|
|
123
|
+
}
|
|
124
|
+
else if (typeof source[key] === "object" &&
|
|
125
|
+
typeof value === "object" &&
|
|
126
|
+
!Array.isArray(source[key]) &&
|
|
127
|
+
!Array.isArray(value)) {
|
|
128
|
+
result[key] = this.mergeObjects(source[key], value);
|
|
129
|
+
}
|
|
130
|
+
else if (Array.isArray(source[key]) && Array.isArray(value)) {
|
|
131
|
+
result[key] = [...new Set([...source[key], ...value])].filter((item) => item !== null && item !== undefined && item !== "");
|
|
132
|
+
}
|
|
133
|
+
else if (source[key] === undefined ||
|
|
134
|
+
source[key] === null ||
|
|
135
|
+
source[key] === "") {
|
|
136
|
+
result[key] = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Validates the transformed data item using existing validation logic.
|
|
143
|
+
*
|
|
144
|
+
* @param transformedData - The transformed data to validate
|
|
145
|
+
* @param attributeMappings - The attribute mappings containing validation rules
|
|
146
|
+
* @param context - The context for validation
|
|
147
|
+
* @returns True if valid, false otherwise
|
|
148
|
+
*/
|
|
149
|
+
validateTransformedData(transformedData, attributeMappings, context) {
|
|
150
|
+
try {
|
|
151
|
+
return this.importDataActions.validateItem(transformedData, attributeMappings, context);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
logger.error(`Validation error for transformed data: ${JSON.stringify(transformedData, null, 2)}`, error);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { AttributeMappings, AppwriteConfig } from "@njdamstra/appwrite-utils";
|
|
2
|
+
import type { ImportDataActions } from "../importDataActions.js";
|
|
3
|
+
import { RateLimitManager } from "./RateLimitManager.js";
|
|
4
|
+
/**
|
|
5
|
+
* Service responsible for file handling during import.
|
|
6
|
+
* Preserves all existing file handling capabilities including URL support.
|
|
7
|
+
* Extracted from DataLoader to provide focused, testable file operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FileHandlerService {
|
|
10
|
+
private appwriteFolderPath;
|
|
11
|
+
private config;
|
|
12
|
+
private importDataActions;
|
|
13
|
+
private rateLimitManager;
|
|
14
|
+
constructor(appwriteFolderPath: string, config: AppwriteConfig, importDataActions: ImportDataActions, rateLimitManager?: RateLimitManager);
|
|
15
|
+
/**
|
|
16
|
+
* Generates attribute mappings with post-import actions based on the provided attribute mappings.
|
|
17
|
+
* This method checks each mapping for a fileData attribute and adds a post-import action to create a file
|
|
18
|
+
* and update the field with the file's ID if necessary.
|
|
19
|
+
*
|
|
20
|
+
* Preserves existing file handling logic from DataLoader.
|
|
21
|
+
*
|
|
22
|
+
* @param attributeMappings - The attribute mappings from the import definition.
|
|
23
|
+
* @param context - The context object containing information about the database, collection, and document.
|
|
24
|
+
* @param item - The item being imported, used for resolving template paths in fileData mappings.
|
|
25
|
+
* @returns The attribute mappings updated with any necessary post-import actions.
|
|
26
|
+
*/
|
|
27
|
+
getAttributeMappingsWithFileActions(attributeMappings: AttributeMappings, context: any, item: any): AttributeMappings;
|
|
28
|
+
/**
|
|
29
|
+
* Resolves local file path, searching in subdirectories if needed.
|
|
30
|
+
* Preserves existing file search logic from DataLoader.
|
|
31
|
+
*
|
|
32
|
+
* @param mappingFilePath - The relative file path from the mapping
|
|
33
|
+
* @returns Resolved absolute file path
|
|
34
|
+
*/
|
|
35
|
+
private resolveLocalFilePath;
|
|
36
|
+
/**
|
|
37
|
+
* Executes file-related post-import actions with rate limiting.
|
|
38
|
+
* Wraps the existing createFileAndUpdateField action with proper error handling and rate limiting.
|
|
39
|
+
*
|
|
40
|
+
* @param context - The context containing document and collection information
|
|
41
|
+
* @param postImportActions - The post-import actions to execute
|
|
42
|
+
*/
|
|
43
|
+
executeFileActions(context: any, postImportActions: any[]): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Executes a single file action with proper error handling.
|
|
46
|
+
*
|
|
47
|
+
* @param action - The file action to execute
|
|
48
|
+
* @param context - The context for template resolution
|
|
49
|
+
*/
|
|
50
|
+
private executeFileAction;
|
|
51
|
+
/**
|
|
52
|
+
* Validates that file paths exist before import begins.
|
|
53
|
+
* Provides early validation to catch file issues before processing starts.
|
|
54
|
+
*
|
|
55
|
+
* @param attributeMappings - The attribute mappings to validate
|
|
56
|
+
* @param context - The context for template resolution
|
|
57
|
+
* @param item - The item for template resolution
|
|
58
|
+
* @returns Array of validation errors (empty if all valid)
|
|
59
|
+
*/
|
|
60
|
+
validateFilePaths(attributeMappings: AttributeMappings, context: any, item: any): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Gets file statistics for import planning.
|
|
63
|
+
* Helps estimate import time and resource requirements.
|
|
64
|
+
*
|
|
65
|
+
* @param attributeMappings - The attribute mappings to analyze
|
|
66
|
+
* @param items - The items that will be imported
|
|
67
|
+
* @returns File statistics object
|
|
68
|
+
*/
|
|
69
|
+
getFileStatistics(attributeMappings: AttributeMappings, items: any[]): {
|
|
70
|
+
totalFiles: number;
|
|
71
|
+
urlFiles: number;
|
|
72
|
+
localFiles: number;
|
|
73
|
+
estimatedSize: number;
|
|
74
|
+
};
|
|
75
|
+
}
|