appwrite-utils-cli 1.9.7 → 1.11.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.
- package/CONFIG_TODO.md +1189 -1189
- package/README.md +1004 -1004
- package/SELECTION_DIALOGS.md +145 -145
- package/SERVICE_IMPLEMENTATION_REPORT.md +462 -462
- package/package.json +6 -3
- package/scripts/copy-templates.ts +23 -23
- package/src/adapters/index.ts +11 -37
- package/src/backups/operations/bucketBackup.ts +277 -277
- package/src/backups/operations/collectionBackup.ts +310 -310
- package/src/backups/operations/comprehensiveBackup.ts +342 -342
- package/src/backups/schemas/bucketManifest.ts +78 -78
- package/src/backups/schemas/comprehensiveManifest.ts +76 -76
- package/src/backups/tracking/centralizedTracking.ts +352 -352
- package/src/cli/commands/configCommands.ts +265 -201
- package/src/cli/commands/databaseCommands.ts +931 -879
- package/src/cli/commands/functionCommands.ts +333 -332
- package/src/cli/commands/importFileCommands.ts +815 -0
- package/src/cli/commands/schemaCommands.ts +141 -141
- package/src/cli/commands/storageCommands.ts +2 -3
- package/src/cli/commands/transferCommands.ts +454 -457
- package/src/collections/attributes.ts.backup +1555 -1555
- package/src/collections/{attributes.ts → columns.ts} +15 -10
- package/src/collections/indexes.ts +350 -352
- package/src/collections/methods.ts +714 -700
- package/src/collections/tableOperations.ts +29 -8
- package/src/collections/transferOperations.ts +376 -377
- package/src/collections/wipeOperations.ts +449 -346
- package/src/databases/methods.ts +49 -49
- package/src/databases/setup.ts +77 -77
- package/src/examples/yamlTerminologyExample.ts +346 -346
- package/src/functions/deployments.ts +221 -220
- package/src/functions/fnConfigDiscovery.ts +2 -2
- package/src/functions/methods.ts +284 -284
- package/src/functions/templates/count-docs-in-collection/README.md +53 -53
- package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -159
- package/src/functions/templates/count-docs-in-collection/src/request.ts +8 -8
- package/src/functions/templates/hono-typescript/README.md +285 -285
- package/src/functions/templates/hono-typescript/src/adapters/request.ts +73 -73
- package/src/functions/templates/hono-typescript/src/adapters/response.ts +105 -105
- package/src/functions/templates/hono-typescript/src/app.ts +179 -179
- package/src/functions/templates/hono-typescript/src/context.ts +102 -102
- package/src/functions/templates/hono-typescript/src/{index.ts → main.ts} +53 -53
- package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +118 -118
- package/src/functions/templates/typescript-node/README.md +31 -31
- package/src/functions/templates/typescript-node/src/context.ts +102 -102
- package/src/functions/templates/typescript-node/src/{index.ts → main.ts} +29 -29
- package/src/functions/templates/uv/README.md +30 -30
- package/src/functions/templates/uv/pyproject.toml +29 -29
- package/src/functions/templates/uv/src/context.py +124 -124
- package/src/functions/templates/uv/src/{index.py → main.py} +45 -45
- package/src/init.ts +62 -62
- package/src/interactiveCLI.ts +1095 -1030
- package/src/main.ts +1517 -1670
- package/src/migrations/afterImportActions.ts +579 -580
- package/src/migrations/appwriteToX.ts +634 -630
- package/src/migrations/comprehensiveTransfer.ts +2149 -2149
- package/src/migrations/dataLoader.ts +1729 -1702
- package/src/migrations/importController.ts +440 -428
- package/src/migrations/importDataActions.ts +315 -315
- package/src/migrations/relationships.ts +333 -334
- package/src/migrations/services/DataTransformationService.ts +195 -195
- package/src/migrations/services/FileHandlerService.ts +310 -310
- package/src/migrations/services/ImportOrchestrator.ts +674 -665
- package/src/migrations/services/RateLimitManager.ts +362 -362
- package/src/migrations/services/RelationshipResolver.ts +460 -460
- package/src/migrations/services/UserMappingService.ts +344 -344
- package/src/migrations/services/ValidationService.ts +333 -333
- package/src/migrations/transfer.ts +987 -942
- package/src/migrations/yaml/YamlImportConfigLoader.ts +438 -438
- package/src/migrations/yaml/YamlImportIntegration.ts +438 -438
- package/src/migrations/yaml/generateImportSchemas.ts +1347 -1347
- package/src/schemas/authUser.ts +23 -23
- package/src/setup.ts +8 -8
- package/src/setupCommands.ts +5 -6
- package/src/setupController.ts +42 -42
- package/src/shared/backupMetadataSchema.ts +93 -93
- package/src/shared/backupTracking.ts +211 -211
- package/src/shared/confirmationDialogs.ts +326 -326
- package/src/shared/migrationHelpers.ts +232 -232
- package/src/shared/operationLogger.ts +20 -20
- package/src/shared/operationQueue.ts +326 -327
- package/src/shared/operationsTable.ts +338 -338
- package/src/shared/operationsTableSchema.ts +60 -60
- package/src/shared/progressManager.ts +277 -277
- package/src/shared/relationshipExtractor.ts +214 -214
- package/src/shared/selectionDialogs.ts +775 -722
- package/src/storage/backupCompression.ts +88 -88
- package/src/storage/methods.ts +695 -682
- package/src/storage/schemas.ts +205 -205
- package/src/tables/indexManager.ts +408 -408
- package/src/types/node-appwrite-tablesdb.d.ts +43 -43
- package/src/types.ts +9 -9
- package/src/users/methods.ts +358 -359
- package/src/utils/configMigration.ts +347 -347
- package/src/utils/index.ts +2 -2
- package/src/utils/loadConfigs.ts +457 -449
- package/src/utils/setupFiles.ts +1236 -1238
- package/src/utilsController.ts +1263 -1213
- package/tests/README.md +496 -496
- package/tests/adapters/AdapterFactory.test.ts +276 -276
- package/tests/integration/syncOperations.test.ts +462 -462
- package/tests/jest.config.js +24 -24
- package/tests/migration/configMigration.test.ts +545 -545
- package/tests/setup.ts +61 -61
- package/tests/testUtils.ts +339 -339
- package/tests/utils/loadConfigs.test.ts +349 -349
- package/tests/validation/configValidation.test.ts +411 -411
- package/tsconfig.json +44 -44
- package/.appwrite/.yaml_schemas/appwrite-config.schema.json +0 -380
- package/.appwrite/.yaml_schemas/collection.schema.json +0 -255
- package/.appwrite/collections/Categories.yaml +0 -182
- package/.appwrite/collections/ExampleCollection.yaml +0 -36
- package/.appwrite/collections/Posts.yaml +0 -227
- package/.appwrite/collections/Users.yaml +0 -149
- package/.appwrite/config.yaml +0 -109
- package/.appwrite/import/README.md +0 -148
- package/.appwrite/import/categories-import.yaml +0 -129
- package/.appwrite/import/posts-import.yaml +0 -208
- package/.appwrite/import/users-import.yaml +0 -130
- package/.appwrite/importData/categories.json +0 -194
- package/.appwrite/importData/posts.json +0 -270
- package/.appwrite/importData/users.json +0 -220
- package/.appwrite/schemas/categories.json +0 -128
- package/.appwrite/schemas/exampleCollection.json +0 -52
- package/.appwrite/schemas/posts.json +0 -173
- package/.appwrite/schemas/users.json +0 -125
- package/dist/adapters/AdapterFactory.d.ts +0 -94
- package/dist/adapters/AdapterFactory.js +0 -420
- package/dist/adapters/DatabaseAdapter.d.ts +0 -243
- package/dist/adapters/DatabaseAdapter.js +0 -50
- package/dist/adapters/LegacyAdapter.d.ts +0 -50
- package/dist/adapters/LegacyAdapter.js +0 -615
- package/dist/adapters/TablesDBAdapter.d.ts +0 -45
- package/dist/adapters/TablesDBAdapter.js +0 -611
- package/dist/adapters/index.d.ts +0 -11
- package/dist/adapters/index.js +0 -12
- package/dist/backups/operations/bucketBackup.d.ts +0 -19
- package/dist/backups/operations/bucketBackup.js +0 -197
- package/dist/backups/operations/collectionBackup.d.ts +0 -30
- package/dist/backups/operations/collectionBackup.js +0 -201
- package/dist/backups/operations/comprehensiveBackup.d.ts +0 -25
- package/dist/backups/operations/comprehensiveBackup.js +0 -238
- package/dist/backups/schemas/bucketManifest.d.ts +0 -93
- package/dist/backups/schemas/bucketManifest.js +0 -33
- package/dist/backups/schemas/comprehensiveManifest.d.ts +0 -108
- package/dist/backups/schemas/comprehensiveManifest.js +0 -32
- package/dist/backups/tracking/centralizedTracking.d.ts +0 -34
- package/dist/backups/tracking/centralizedTracking.js +0 -274
- package/dist/cli/commands/configCommands.d.ts +0 -8
- package/dist/cli/commands/configCommands.js +0 -166
- package/dist/cli/commands/databaseCommands.d.ts +0 -14
- package/dist/cli/commands/databaseCommands.js +0 -644
- package/dist/cli/commands/functionCommands.d.ts +0 -7
- package/dist/cli/commands/functionCommands.js +0 -330
- package/dist/cli/commands/schemaCommands.d.ts +0 -7
- package/dist/cli/commands/schemaCommands.js +0 -169
- package/dist/cli/commands/storageCommands.d.ts +0 -5
- package/dist/cli/commands/storageCommands.js +0 -143
- package/dist/cli/commands/transferCommands.d.ts +0 -5
- package/dist/cli/commands/transferCommands.js +0 -384
- package/dist/collections/attributes.d.ts +0 -13
- package/dist/collections/attributes.js +0 -1333
- package/dist/collections/indexes.d.ts +0 -12
- package/dist/collections/indexes.js +0 -217
- package/dist/collections/methods.d.ts +0 -19
- package/dist/collections/methods.js +0 -587
- package/dist/collections/tableOperations.d.ts +0 -86
- package/dist/collections/tableOperations.js +0 -447
- package/dist/collections/transferOperations.d.ts +0 -8
- package/dist/collections/transferOperations.js +0 -412
- package/dist/collections/wipeOperations.d.ts +0 -16
- package/dist/collections/wipeOperations.js +0 -233
- package/dist/config/ConfigManager.d.ts +0 -450
- package/dist/config/ConfigManager.js +0 -650
- package/dist/config/configMigration.d.ts +0 -87
- package/dist/config/configMigration.js +0 -390
- package/dist/config/configValidation.d.ts +0 -66
- package/dist/config/configValidation.js +0 -358
- package/dist/config/index.d.ts +0 -8
- package/dist/config/index.js +0 -7
- package/dist/config/services/ConfigDiscoveryService.d.ts +0 -122
- package/dist/config/services/ConfigDiscoveryService.js +0 -322
- package/dist/config/services/ConfigLoaderService.d.ts +0 -129
- package/dist/config/services/ConfigLoaderService.js +0 -535
- package/dist/config/services/ConfigMergeService.d.ts +0 -208
- package/dist/config/services/ConfigMergeService.js +0 -308
- package/dist/config/services/ConfigValidationService.d.ts +0 -214
- package/dist/config/services/ConfigValidationService.js +0 -310
- package/dist/config/services/SessionAuthService.d.ts +0 -225
- package/dist/config/services/SessionAuthService.js +0 -456
- package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +0 -1
- package/dist/config/services/__tests__/ConfigMergeService.test.js +0 -271
- package/dist/config/services/index.d.ts +0 -13
- package/dist/config/services/index.js +0 -10
- package/dist/config/yamlConfig.d.ts +0 -722
- package/dist/config/yamlConfig.js +0 -702
- package/dist/databases/methods.d.ts +0 -6
- package/dist/databases/methods.js +0 -35
- package/dist/databases/setup.d.ts +0 -5
- package/dist/databases/setup.js +0 -45
- package/dist/examples/yamlTerminologyExample.d.ts +0 -42
- package/dist/examples/yamlTerminologyExample.js +0 -272
- package/dist/functions/deployments.d.ts +0 -4
- package/dist/functions/deployments.js +0 -146
- package/dist/functions/fnConfigDiscovery.d.ts +0 -3
- package/dist/functions/fnConfigDiscovery.js +0 -108
- package/dist/functions/methods.d.ts +0 -16
- package/dist/functions/methods.js +0 -174
- package/dist/functions/pathResolution.d.ts +0 -37
- package/dist/functions/pathResolution.js +0 -185
- package/dist/functions/templates/count-docs-in-collection/README.md +0 -54
- package/dist/functions/templates/count-docs-in-collection/package.json +0 -25
- package/dist/functions/templates/count-docs-in-collection/src/main.ts +0 -159
- package/dist/functions/templates/count-docs-in-collection/src/request.ts +0 -9
- package/dist/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
- package/dist/functions/templates/hono-typescript/README.md +0 -286
- package/dist/functions/templates/hono-typescript/package.json +0 -26
- package/dist/functions/templates/hono-typescript/src/adapters/request.ts +0 -74
- package/dist/functions/templates/hono-typescript/src/adapters/response.ts +0 -106
- package/dist/functions/templates/hono-typescript/src/app.ts +0 -180
- package/dist/functions/templates/hono-typescript/src/context.ts +0 -103
- package/dist/functions/templates/hono-typescript/src/index.ts +0 -54
- package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -119
- package/dist/functions/templates/hono-typescript/tsconfig.json +0 -20
- package/dist/functions/templates/typescript-node/README.md +0 -32
- package/dist/functions/templates/typescript-node/package.json +0 -25
- package/dist/functions/templates/typescript-node/src/context.ts +0 -103
- package/dist/functions/templates/typescript-node/src/index.ts +0 -29
- package/dist/functions/templates/typescript-node/tsconfig.json +0 -28
- package/dist/functions/templates/uv/README.md +0 -31
- package/dist/functions/templates/uv/pyproject.toml +0 -30
- package/dist/functions/templates/uv/src/__init__.py +0 -0
- package/dist/functions/templates/uv/src/context.py +0 -125
- package/dist/functions/templates/uv/src/index.py +0 -46
- package/dist/init.d.ts +0 -2
- package/dist/init.js +0 -57
- package/dist/interactiveCLI.d.ts +0 -31
- package/dist/interactiveCLI.js +0 -898
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -1180
- package/dist/migrations/afterImportActions.d.ts +0 -17
- package/dist/migrations/afterImportActions.js +0 -306
- package/dist/migrations/appwriteToX.d.ts +0 -211
- package/dist/migrations/appwriteToX.js +0 -491
- package/dist/migrations/comprehensiveTransfer.d.ts +0 -147
- package/dist/migrations/comprehensiveTransfer.js +0 -1317
- package/dist/migrations/dataLoader.d.ts +0 -753
- package/dist/migrations/dataLoader.js +0 -1250
- package/dist/migrations/importController.d.ts +0 -23
- package/dist/migrations/importController.js +0 -268
- package/dist/migrations/importDataActions.d.ts +0 -50
- package/dist/migrations/importDataActions.js +0 -230
- package/dist/migrations/relationships.d.ts +0 -29
- package/dist/migrations/relationships.js +0 -204
- package/dist/migrations/services/DataTransformationService.d.ts +0 -55
- package/dist/migrations/services/DataTransformationService.js +0 -158
- package/dist/migrations/services/FileHandlerService.d.ts +0 -75
- package/dist/migrations/services/FileHandlerService.js +0 -236
- package/dist/migrations/services/ImportOrchestrator.d.ts +0 -97
- package/dist/migrations/services/ImportOrchestrator.js +0 -485
- package/dist/migrations/services/RateLimitManager.d.ts +0 -138
- package/dist/migrations/services/RateLimitManager.js +0 -279
- package/dist/migrations/services/RelationshipResolver.d.ts +0 -120
- package/dist/migrations/services/RelationshipResolver.js +0 -332
- package/dist/migrations/services/UserMappingService.d.ts +0 -109
- package/dist/migrations/services/UserMappingService.js +0 -277
- package/dist/migrations/services/ValidationService.d.ts +0 -74
- package/dist/migrations/services/ValidationService.js +0 -260
- package/dist/migrations/transfer.d.ts +0 -26
- package/dist/migrations/transfer.js +0 -608
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +0 -131
- package/dist/migrations/yaml/YamlImportConfigLoader.js +0 -383
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +0 -93
- package/dist/migrations/yaml/YamlImportIntegration.js +0 -341
- package/dist/migrations/yaml/generateImportSchemas.d.ts +0 -30
- package/dist/migrations/yaml/generateImportSchemas.js +0 -1327
- package/dist/schemas/authUser.d.ts +0 -24
- package/dist/schemas/authUser.js +0 -17
- package/dist/setup.d.ts +0 -2
- package/dist/setup.js +0 -5
- package/dist/setupCommands.d.ts +0 -58
- package/dist/setupCommands.js +0 -490
- package/dist/setupController.d.ts +0 -9
- package/dist/setupController.js +0 -34
- package/dist/shared/attributeMapper.d.ts +0 -20
- package/dist/shared/attributeMapper.js +0 -203
- package/dist/shared/backupMetadataSchema.d.ts +0 -94
- package/dist/shared/backupMetadataSchema.js +0 -38
- package/dist/shared/backupTracking.d.ts +0 -18
- package/dist/shared/backupTracking.js +0 -176
- package/dist/shared/confirmationDialogs.d.ts +0 -75
- package/dist/shared/confirmationDialogs.js +0 -236
- package/dist/shared/errorUtils.d.ts +0 -54
- package/dist/shared/errorUtils.js +0 -95
- package/dist/shared/functionManager.d.ts +0 -48
- package/dist/shared/functionManager.js +0 -348
- package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
- package/dist/shared/jsonSchemaGenerator.js +0 -290
- package/dist/shared/logging.d.ts +0 -61
- package/dist/shared/logging.js +0 -116
- package/dist/shared/messageFormatter.d.ts +0 -39
- package/dist/shared/messageFormatter.js +0 -162
- package/dist/shared/migrationHelpers.d.ts +0 -61
- package/dist/shared/migrationHelpers.js +0 -145
- package/dist/shared/operationLogger.d.ts +0 -10
- package/dist/shared/operationLogger.js +0 -12
- package/dist/shared/operationQueue.d.ts +0 -40
- package/dist/shared/operationQueue.js +0 -311
- package/dist/shared/operationsTable.d.ts +0 -26
- package/dist/shared/operationsTable.js +0 -286
- package/dist/shared/operationsTableSchema.d.ts +0 -48
- package/dist/shared/operationsTableSchema.js +0 -35
- package/dist/shared/progressManager.d.ts +0 -62
- package/dist/shared/progressManager.js +0 -215
- package/dist/shared/pydanticModelGenerator.d.ts +0 -17
- package/dist/shared/pydanticModelGenerator.js +0 -615
- package/dist/shared/relationshipExtractor.d.ts +0 -56
- package/dist/shared/relationshipExtractor.js +0 -138
- package/dist/shared/schemaGenerator.d.ts +0 -40
- package/dist/shared/schemaGenerator.js +0 -556
- package/dist/shared/selectionDialogs.d.ts +0 -214
- package/dist/shared/selectionDialogs.js +0 -544
- package/dist/storage/backupCompression.d.ts +0 -20
- package/dist/storage/backupCompression.js +0 -67
- package/dist/storage/methods.d.ts +0 -32
- package/dist/storage/methods.js +0 -472
- package/dist/storage/schemas.d.ts +0 -842
- package/dist/storage/schemas.js +0 -175
- package/dist/tables/indexManager.d.ts +0 -65
- package/dist/tables/indexManager.js +0 -294
- package/dist/types.d.ts +0 -4
- package/dist/types.js +0 -3
- package/dist/users/methods.d.ts +0 -16
- package/dist/users/methods.js +0 -277
- package/dist/utils/ClientFactory.d.ts +0 -87
- package/dist/utils/ClientFactory.js +0 -212
- package/dist/utils/configDiscovery.d.ts +0 -78
- package/dist/utils/configDiscovery.js +0 -472
- package/dist/utils/configMigration.d.ts +0 -1
- package/dist/utils/configMigration.js +0 -261
- package/dist/utils/constantsGenerator.d.ts +0 -31
- package/dist/utils/constantsGenerator.js +0 -321
- package/dist/utils/dataConverters.d.ts +0 -46
- package/dist/utils/dataConverters.js +0 -139
- package/dist/utils/directoryUtils.d.ts +0 -22
- package/dist/utils/directoryUtils.js +0 -59
- package/dist/utils/getClientFromConfig.d.ts +0 -39
- package/dist/utils/getClientFromConfig.js +0 -199
- package/dist/utils/helperFunctions.d.ts +0 -63
- package/dist/utils/helperFunctions.js +0 -156
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/utils/loadConfigs.d.ts +0 -50
- package/dist/utils/loadConfigs.js +0 -358
- package/dist/utils/pathResolvers.d.ts +0 -53
- package/dist/utils/pathResolvers.js +0 -72
- package/dist/utils/projectConfig.d.ts +0 -122
- package/dist/utils/projectConfig.js +0 -206
- package/dist/utils/retryFailedPromises.d.ts +0 -2
- package/dist/utils/retryFailedPromises.js +0 -23
- package/dist/utils/sessionAuth.d.ts +0 -48
- package/dist/utils/sessionAuth.js +0 -164
- package/dist/utils/setupFiles.d.ts +0 -4
- package/dist/utils/setupFiles.js +0 -1192
- package/dist/utils/typeGuards.d.ts +0 -35
- package/dist/utils/typeGuards.js +0 -57
- package/dist/utils/validationRules.d.ts +0 -43
- package/dist/utils/validationRules.js +0 -42
- package/dist/utils/versionDetection.d.ts +0 -58
- package/dist/utils/versionDetection.js +0 -251
- package/dist/utils/yamlConverter.d.ts +0 -100
- package/dist/utils/yamlConverter.js +0 -428
- package/dist/utils/yamlLoader.d.ts +0 -70
- package/dist/utils/yamlLoader.js +0 -267
- package/dist/utilsController.d.ts +0 -107
- package/dist/utilsController.js +0 -873
- package/src/adapters/AdapterFactory.ts +0 -529
- package/src/adapters/DatabaseAdapter.ts +0 -319
- package/src/adapters/LegacyAdapter.ts +0 -844
- package/src/adapters/TablesDBAdapter.ts +0 -823
- package/src/config/ConfigManager.ts +0 -849
- package/src/config/README.md +0 -274
- package/src/config/configMigration.ts +0 -575
- package/src/config/configValidation.ts +0 -445
- package/src/config/index.ts +0 -10
- package/src/config/services/ConfigDiscoveryService.ts +0 -410
- package/src/config/services/ConfigLoaderService.ts +0 -732
- package/src/config/services/ConfigMergeService.ts +0 -388
- package/src/config/services/ConfigValidationService.ts +0 -394
- package/src/config/services/SessionAuthService.ts +0 -565
- package/src/config/services/__tests__/ConfigMergeService.test.ts +0 -351
- package/src/config/services/index.ts +0 -29
- package/src/config/yamlConfig.ts +0 -761
- package/src/functions/pathResolution.ts +0 -227
- package/src/functions/templates/count-docs-in-collection/package.json +0 -25
- package/src/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
- package/src/functions/templates/hono-typescript/package.json +0 -26
- package/src/functions/templates/hono-typescript/tsconfig.json +0 -20
- package/src/functions/templates/typescript-node/package.json +0 -25
- package/src/functions/templates/typescript-node/tsconfig.json +0 -28
- package/src/shared/attributeMapper.ts +0 -229
- package/src/shared/errorUtils.ts +0 -110
- package/src/shared/functionManager.ts +0 -537
- package/src/shared/jsonSchemaGenerator.ts +0 -383
- package/src/shared/logging.ts +0 -149
- package/src/shared/messageFormatter.ts +0 -208
- package/src/shared/pydanticModelGenerator.ts +0 -618
- package/src/shared/schemaGenerator.ts +0 -644
- package/src/utils/ClientFactory.ts +0 -240
- package/src/utils/configDiscovery.ts +0 -557
- package/src/utils/constantsGenerator.ts +0 -369
- package/src/utils/dataConverters.ts +0 -159
- package/src/utils/directoryUtils.ts +0 -61
- package/src/utils/getClientFromConfig.ts +0 -257
- package/src/utils/helperFunctions.ts +0 -228
- package/src/utils/pathResolvers.ts +0 -81
- package/src/utils/projectConfig.ts +0 -340
- package/src/utils/retryFailedPromises.ts +0 -29
- package/src/utils/sessionAuth.ts +0 -230
- package/src/utils/typeGuards.ts +0 -65
- package/src/utils/validationRules.ts +0 -88
- package/src/utils/versionDetection.ts +0 -292
- package/src/utils/yamlConverter.ts +0 -542
- package/src/utils/yamlLoader.ts +0 -371
- package/tmp-sync-test/.appwrite/collections/TestCollection.yaml +0 -7
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import { Query } from "node-appwrite";
|
|
2
|
-
import { createOrUpdateAttributeWithStatusCheck } from "../collections/attributes.js";
|
|
3
|
-
import { fetchAndCacheCollectionByName } from "../collections/methods.js";
|
|
4
|
-
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
|
5
|
-
import { logger } from "../shared/logging.js";
|
|
6
|
-
import { MessageFormatter } from "../shared/messageFormatter.js";
|
|
7
|
-
// Global state management
|
|
8
|
-
export const queuedOperations = [];
|
|
9
|
-
export const nameToIdMapping = new Map();
|
|
10
|
-
// Keys are scoped per database to avoid cross-database collisions
|
|
11
|
-
// Collections key format: `${databaseId}::${collectionId}`
|
|
12
|
-
// Attributes key format: `${databaseId}::${collectionId}::${attributeKey}`
|
|
13
|
-
export const processedCollections = new Set();
|
|
14
|
-
export const processedAttributes = new Set();
|
|
15
|
-
// Helpers to build scoped keys
|
|
16
|
-
const collectionKey = (databaseId, collectionId) => `${databaseId}::${collectionId}`;
|
|
17
|
-
const attributeKeyScoped = (databaseId, collectionId, key) => `${databaseId}::${collectionId}::${key}`;
|
|
18
|
-
export const enqueueOperation = (operation) => {
|
|
19
|
-
// Avoid duplicate queue entries for same attribute
|
|
20
|
-
const attributeKey = operation.attribute?.key;
|
|
21
|
-
const collectionId = operation.collectionId;
|
|
22
|
-
logger.info('Enqueueing operation', {
|
|
23
|
-
type: operation.type,
|
|
24
|
-
attributeKey,
|
|
25
|
-
collectionId,
|
|
26
|
-
dependencies: operation.dependencies,
|
|
27
|
-
queueSizeBefore: queuedOperations.length,
|
|
28
|
-
operation: 'enqueueOperation'
|
|
29
|
-
});
|
|
30
|
-
if (attributeKey && collectionId) {
|
|
31
|
-
const duplicateIndex = queuedOperations.findIndex((op) => op.collectionId === collectionId && op.attribute?.key === attributeKey);
|
|
32
|
-
if (duplicateIndex !== -1) {
|
|
33
|
-
MessageFormatter.info(`Replacing existing queue entry for attribute: ${attributeKey}`);
|
|
34
|
-
logger.info('Replacing duplicate queue entry', {
|
|
35
|
-
attributeKey,
|
|
36
|
-
collectionId,
|
|
37
|
-
duplicateIndex,
|
|
38
|
-
operation: 'enqueueOperation'
|
|
39
|
-
});
|
|
40
|
-
queuedOperations[duplicateIndex] = operation;
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
queuedOperations.push(operation);
|
|
45
|
-
logger.debug('Operation enqueued successfully', {
|
|
46
|
-
attributeKey,
|
|
47
|
-
collectionId,
|
|
48
|
-
queueSizeAfter: queuedOperations.length,
|
|
49
|
-
operation: 'enqueueOperation'
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Clear all caches and processing state - use between operations
|
|
54
|
-
*/
|
|
55
|
-
export const clearProcessingState = () => {
|
|
56
|
-
const sizeBefore = {
|
|
57
|
-
collections: processedCollections.size,
|
|
58
|
-
attributes: processedAttributes.size,
|
|
59
|
-
nameMapping: nameToIdMapping.size
|
|
60
|
-
};
|
|
61
|
-
processedCollections.clear();
|
|
62
|
-
processedAttributes.clear();
|
|
63
|
-
nameToIdMapping.clear();
|
|
64
|
-
logger.debug("Cleared processing state caches", { operation: "clearProcessingState", sizeBefore });
|
|
65
|
-
logger.info('Processing state cleared', {
|
|
66
|
-
sizeBefore,
|
|
67
|
-
operation: 'clearProcessingState'
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Check if a collection has already been fully processed
|
|
72
|
-
*/
|
|
73
|
-
export const isCollectionProcessed = (collectionId, databaseId) => {
|
|
74
|
-
return processedCollections.has(collectionKey(databaseId, collectionId));
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Mark a collection as fully processed
|
|
78
|
-
*/
|
|
79
|
-
export const markCollectionProcessed = (collectionId, collectionName, databaseId) => {
|
|
80
|
-
processedCollections.add(collectionKey(databaseId, collectionId));
|
|
81
|
-
const logData = {
|
|
82
|
-
databaseId,
|
|
83
|
-
collectionId,
|
|
84
|
-
collectionName,
|
|
85
|
-
totalProcessedCollections: processedCollections.size,
|
|
86
|
-
operation: 'markCollectionProcessed'
|
|
87
|
-
};
|
|
88
|
-
if (collectionName) {
|
|
89
|
-
MessageFormatter.success(`Marked collection '${collectionName}' (${collectionId}) as processed`, { prefix: 'Tables' });
|
|
90
|
-
}
|
|
91
|
-
logger.info('Collection marked as processed', logData);
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Check if a specific attribute has been processed
|
|
95
|
-
*/
|
|
96
|
-
export const isAttributeProcessed = (databaseId, collectionId, attributeKey) => {
|
|
97
|
-
return processedAttributes.has(attributeKeyScoped(databaseId, collectionId, attributeKey));
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Mark a specific attribute as processed
|
|
101
|
-
*/
|
|
102
|
-
export const markAttributeProcessed = (databaseId, collectionId, attributeKey) => {
|
|
103
|
-
const identifier = attributeKeyScoped(databaseId, collectionId, attributeKey);
|
|
104
|
-
processedAttributes.add(identifier);
|
|
105
|
-
logger.debug('Attribute marked as processed', {
|
|
106
|
-
databaseId,
|
|
107
|
-
collectionId,
|
|
108
|
-
attributeKey,
|
|
109
|
-
identifier,
|
|
110
|
-
totalProcessedAttributes: processedAttributes.size,
|
|
111
|
-
operation: 'markAttributeProcessed'
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Process only specific attributes in the queue, not entire collections
|
|
116
|
-
* This prevents triggering full collection re-processing cycles
|
|
117
|
-
*/
|
|
118
|
-
export const processQueue = async (db, dbId) => {
|
|
119
|
-
const startTime = Date.now();
|
|
120
|
-
if (queuedOperations.length === 0) {
|
|
121
|
-
MessageFormatter.info("No queued operations to process");
|
|
122
|
-
logger.info('Queue processing skipped - no operations', {
|
|
123
|
-
dbId,
|
|
124
|
-
operation: 'processQueue'
|
|
125
|
-
});
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
MessageFormatter.section(`Starting surgical queue processing of ${queuedOperations.length} operations for ${dbId}`);
|
|
129
|
-
logger.info('Starting queue processing', {
|
|
130
|
-
dbId,
|
|
131
|
-
queueSize: queuedOperations.length,
|
|
132
|
-
operations: queuedOperations.map(op => ({
|
|
133
|
-
type: op.type,
|
|
134
|
-
attributeKey: op.attribute?.key,
|
|
135
|
-
collectionId: op.collectionId,
|
|
136
|
-
dependencies: op.dependencies
|
|
137
|
-
})),
|
|
138
|
-
operation: 'processQueue'
|
|
139
|
-
});
|
|
140
|
-
let progress = true;
|
|
141
|
-
let attempts = 0;
|
|
142
|
-
const maxAttempts = 3; // Prevent infinite loops
|
|
143
|
-
while (progress && attempts < maxAttempts) {
|
|
144
|
-
progress = false;
|
|
145
|
-
attempts++;
|
|
146
|
-
MessageFormatter.info(`Queue processing attempt ${attempts}/${maxAttempts}`);
|
|
147
|
-
logger.info('Queue processing attempt started', {
|
|
148
|
-
attempt: attempts,
|
|
149
|
-
maxAttempts,
|
|
150
|
-
remainingOperations: queuedOperations.length,
|
|
151
|
-
dbId,
|
|
152
|
-
operation: 'processQueue'
|
|
153
|
-
});
|
|
154
|
-
for (let i = queuedOperations.length - 1; i >= 0; i--) {
|
|
155
|
-
const operation = queuedOperations[i];
|
|
156
|
-
if (!operation.attribute || !operation.collectionId) {
|
|
157
|
-
MessageFormatter.warning("Invalid operation, removing from queue");
|
|
158
|
-
queuedOperations.splice(i, 1);
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
const attributeKey = operation.attribute.key;
|
|
162
|
-
const collectionId = operation.collectionId;
|
|
163
|
-
// Skip if this specific attribute was already processed (per database)
|
|
164
|
-
if (isAttributeProcessed(dbId, collectionId, attributeKey)) {
|
|
165
|
-
MessageFormatter.debug(`Attribute '${attributeKey}' already processed, removing from queue`);
|
|
166
|
-
logger.debug('Removing already processed attribute from queue', {
|
|
167
|
-
attributeKey,
|
|
168
|
-
collectionId,
|
|
169
|
-
queueIndex: i,
|
|
170
|
-
operation: 'processQueue'
|
|
171
|
-
});
|
|
172
|
-
queuedOperations.splice(i, 1);
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
let targetCollection;
|
|
176
|
-
// Resolve the target collection (where the attribute will be created)
|
|
177
|
-
try {
|
|
178
|
-
targetCollection = await tryAwaitWithRetry(async () => {
|
|
179
|
-
if ('getMetadata' in db && typeof db.getMetadata === 'function') {
|
|
180
|
-
// DatabaseAdapter
|
|
181
|
-
return (await db.getTable({ databaseId: dbId, tableId: collectionId })).data;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
// Legacy Databases
|
|
185
|
-
return await db.getCollection(dbId, collectionId);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
catch (e) {
|
|
190
|
-
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
191
|
-
MessageFormatter.error(`Target collection ${collectionId} not found, removing from queue`);
|
|
192
|
-
logger.error('Target collection not found during queue processing', {
|
|
193
|
-
collectionId,
|
|
194
|
-
attributeKey,
|
|
195
|
-
error: errorMessage,
|
|
196
|
-
operation: 'processQueue'
|
|
197
|
-
});
|
|
198
|
-
queuedOperations.splice(i, 1);
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
// For relationship attributes, ensure the related collection exists
|
|
202
|
-
let canProcess = true;
|
|
203
|
-
if (operation.attribute.type === "relationship") {
|
|
204
|
-
const relatedCollection = operation.attribute.relatedCollection;
|
|
205
|
-
if (relatedCollection) {
|
|
206
|
-
// Try to resolve related collection by ID first, then by name
|
|
207
|
-
let relatedFound = false;
|
|
208
|
-
try {
|
|
209
|
-
await tryAwaitWithRetry(async () => {
|
|
210
|
-
if ('getMetadata' in db && typeof db.getMetadata === 'function') {
|
|
211
|
-
// DatabaseAdapter
|
|
212
|
-
return (await db.getTable({ databaseId: dbId, tableId: relatedCollection })).data;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
// Legacy Databases
|
|
216
|
-
return await db.getCollection(dbId, relatedCollection);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
relatedFound = true;
|
|
220
|
-
nameToIdMapping.set(relatedCollection, relatedCollection); // Cache the ID mapping
|
|
221
|
-
}
|
|
222
|
-
catch (_) {
|
|
223
|
-
// Try by name lookup
|
|
224
|
-
const cachedId = nameToIdMapping.get(relatedCollection);
|
|
225
|
-
if (cachedId) {
|
|
226
|
-
try {
|
|
227
|
-
await tryAwaitWithRetry(async () => {
|
|
228
|
-
if ('getMetadata' in db && typeof db.getMetadata === 'function') {
|
|
229
|
-
// DatabaseAdapter
|
|
230
|
-
return (await db.getTable({ databaseId: dbId, tableId: cachedId })).data;
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
// Legacy Databases
|
|
234
|
-
return await db.getCollection(dbId, cachedId);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
relatedFound = true;
|
|
238
|
-
}
|
|
239
|
-
catch (_) {
|
|
240
|
-
nameToIdMapping.delete(relatedCollection); // Remove stale cache
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (!relatedFound) {
|
|
244
|
-
// Final attempt: search by name
|
|
245
|
-
try {
|
|
246
|
-
const collections = 'getMetadata' in db && typeof db.getMetadata === 'function'
|
|
247
|
-
? await db.listTables({ databaseId: dbId, queries: [Query.equal("name", relatedCollection)] })
|
|
248
|
-
: await db.listCollections(dbId, [Query.equal("name", relatedCollection)]);
|
|
249
|
-
if (collections.total && collections.total > 0) {
|
|
250
|
-
const firstCollection = 'getMetadata' in db && typeof db.getMetadata === 'function'
|
|
251
|
-
? collections.tables?.[0]
|
|
252
|
-
: collections.collections?.[0];
|
|
253
|
-
nameToIdMapping.set(relatedCollection, firstCollection.$id);
|
|
254
|
-
relatedFound = true;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
catch (_) {
|
|
258
|
-
// Related collection truly doesn't exist yet
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (!relatedFound) {
|
|
263
|
-
MessageFormatter.warning(`Related collection '${relatedCollection}' not ready for attribute '${attributeKey}', keeping in queue`);
|
|
264
|
-
canProcess = false;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (canProcess && targetCollection) {
|
|
269
|
-
MessageFormatter.progress(`Processing queued ${operation.attribute.type} attribute: '${attributeKey}' for collection: '${targetCollection.name}'`);
|
|
270
|
-
const success = await createOrUpdateAttributeWithStatusCheck(db, dbId, targetCollection, operation.attribute);
|
|
271
|
-
if (success) {
|
|
272
|
-
MessageFormatter.success(`Successfully processed queued attribute: '${attributeKey}'`);
|
|
273
|
-
logger.info('Queued attribute processed successfully', {
|
|
274
|
-
attributeKey,
|
|
275
|
-
collectionId,
|
|
276
|
-
targetCollectionName: targetCollection.name,
|
|
277
|
-
operation: 'processQueue'
|
|
278
|
-
});
|
|
279
|
-
markAttributeProcessed(dbId, collectionId, attributeKey);
|
|
280
|
-
queuedOperations.splice(i, 1);
|
|
281
|
-
progress = true;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
MessageFormatter.error(`Failed to process queued attribute: '${attributeKey}', removing from queue`);
|
|
285
|
-
logger.error('Failed to process queued attribute', {
|
|
286
|
-
attributeKey,
|
|
287
|
-
collectionId,
|
|
288
|
-
targetCollectionName: targetCollection.name,
|
|
289
|
-
operation: 'processQueue'
|
|
290
|
-
});
|
|
291
|
-
queuedOperations.splice(i, 1);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (queuedOperations.length === 0) {
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
MessageFormatter.info(`Remaining operations after attempt ${attempts}: ${queuedOperations.length}`);
|
|
299
|
-
}
|
|
300
|
-
if (queuedOperations.length > 0) {
|
|
301
|
-
MessageFormatter.warning(`${queuedOperations.length} operations remain unresolved after ${maxAttempts} attempts:`);
|
|
302
|
-
queuedOperations.forEach((op, index) => {
|
|
303
|
-
MessageFormatter.warning(` ${index + 1}. ${op.attribute?.type} attribute '${op.attribute?.key}' for collection ${op.collectionId}`);
|
|
304
|
-
});
|
|
305
|
-
MessageFormatter.warning("These may have unmet dependencies or require manual intervention");
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
MessageFormatter.success("All queued operations processed successfully");
|
|
309
|
-
}
|
|
310
|
-
MessageFormatter.section(`Surgical queue processing complete for ${dbId}`);
|
|
311
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js";
|
|
2
|
-
import { type OperationRecord } from "./operationsTableSchema.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates the operations tracking table in the specified database
|
|
5
|
-
* Table is created with underscore prefix to indicate it's a system table
|
|
6
|
-
*/
|
|
7
|
-
export declare function createOperationsTable(db: DatabaseAdapter, databaseId: string): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* Finds an existing operation or creates a new one
|
|
10
|
-
* Useful for resuming interrupted operations
|
|
11
|
-
*/
|
|
12
|
-
export declare function findOrCreateOperation(db: DatabaseAdapter, databaseId: string, operationType: string, params?: Partial<OperationRecord>): Promise<OperationRecord>;
|
|
13
|
-
/**
|
|
14
|
-
* Updates an existing operation record
|
|
15
|
-
*/
|
|
16
|
-
export declare function updateOperation(db: DatabaseAdapter, databaseId: string, operationId: string, updates: Partial<OperationRecord>): Promise<OperationRecord>;
|
|
17
|
-
/**
|
|
18
|
-
* Gets a single operation by ID
|
|
19
|
-
*/
|
|
20
|
-
export declare function getOperation(db: DatabaseAdapter, databaseId: string, operationId: string): Promise<OperationRecord | null>;
|
|
21
|
-
/**
|
|
22
|
-
* Cleans up old completed operations
|
|
23
|
-
* @param olderThan - Optional date, defaults to operations older than 7 days
|
|
24
|
-
* @returns Number of operations deleted
|
|
25
|
-
*/
|
|
26
|
-
export declare function cleanupOperations(db: DatabaseAdapter, databaseId: string, olderThan?: Date): Promise<number>;
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { logger } from "./logging.js";
|
|
2
|
-
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
|
3
|
-
import { Query, ID } from "node-appwrite";
|
|
4
|
-
import { OPERATIONS_TABLE_ID, OPERATIONS_TABLE_NAME, OperationRecordSchema, } from "./operationsTableSchema.js";
|
|
5
|
-
/**
|
|
6
|
-
* Operations Table Manager
|
|
7
|
-
*
|
|
8
|
-
* Manages dynamic operations tracking tables in each database.
|
|
9
|
-
* Creates _appwrite_operations table on-demand for tracking imports, exports, transfers, etc.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Checks if operations table exists in database
|
|
13
|
-
*/
|
|
14
|
-
async function tableExists(db, databaseId) {
|
|
15
|
-
try {
|
|
16
|
-
await db.getTable({ databaseId, tableId: OPERATIONS_TABLE_ID });
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Creates the operations tracking table in the specified database
|
|
25
|
-
* Table is created with underscore prefix to indicate it's a system table
|
|
26
|
-
*/
|
|
27
|
-
export async function createOperationsTable(db, databaseId) {
|
|
28
|
-
// Check if table already exists
|
|
29
|
-
const exists = await tableExists(db, databaseId);
|
|
30
|
-
if (exists) {
|
|
31
|
-
logger.debug("Operations table already exists", {
|
|
32
|
-
databaseId,
|
|
33
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
34
|
-
});
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
logger.info("Creating operations tracking table", {
|
|
38
|
-
databaseId,
|
|
39
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
40
|
-
});
|
|
41
|
-
// Create table
|
|
42
|
-
await tryAwaitWithRetry(async () => {
|
|
43
|
-
await db.createTable({
|
|
44
|
-
databaseId,
|
|
45
|
-
id: OPERATIONS_TABLE_ID,
|
|
46
|
-
name: OPERATIONS_TABLE_NAME,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
// Create attributes with retry logic
|
|
50
|
-
const attributes = [
|
|
51
|
-
{
|
|
52
|
-
key: "operationType",
|
|
53
|
-
type: "string",
|
|
54
|
-
size: 50,
|
|
55
|
-
required: true,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
key: "targetCollection",
|
|
59
|
-
type: "string",
|
|
60
|
-
size: 50,
|
|
61
|
-
required: false,
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
key: "status",
|
|
65
|
-
type: "enum",
|
|
66
|
-
elements: ["pending", "in_progress", "completed", "failed", "cancelled"],
|
|
67
|
-
required: true,
|
|
68
|
-
default: "pending",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
key: "progress",
|
|
72
|
-
type: "integer",
|
|
73
|
-
required: true,
|
|
74
|
-
default: 0,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
key: "total",
|
|
78
|
-
type: "integer",
|
|
79
|
-
required: true,
|
|
80
|
-
default: 0,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
key: "data",
|
|
84
|
-
type: "string",
|
|
85
|
-
size: 1048576, // 1MB for serialized data
|
|
86
|
-
required: false,
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
key: "error",
|
|
90
|
-
type: "string",
|
|
91
|
-
size: 10000,
|
|
92
|
-
required: false,
|
|
93
|
-
},
|
|
94
|
-
];
|
|
95
|
-
for (const attr of attributes) {
|
|
96
|
-
await tryAwaitWithRetry(async () => {
|
|
97
|
-
await db.createAttribute({
|
|
98
|
-
databaseId,
|
|
99
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
100
|
-
...attr,
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
logger.info("Operations tracking table created successfully", {
|
|
105
|
-
databaseId,
|
|
106
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
107
|
-
attributes: attributes.length,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Finds an existing operation or creates a new one
|
|
112
|
-
* Useful for resuming interrupted operations
|
|
113
|
-
*/
|
|
114
|
-
export async function findOrCreateOperation(db, databaseId, operationType, params) {
|
|
115
|
-
// Ensure operations table exists
|
|
116
|
-
await createOperationsTable(db, databaseId);
|
|
117
|
-
// Try to find existing pending operation
|
|
118
|
-
try {
|
|
119
|
-
const queries = [
|
|
120
|
-
Query.equal("operationType", operationType),
|
|
121
|
-
Query.equal("status", "pending"),
|
|
122
|
-
];
|
|
123
|
-
if (params?.targetCollection) {
|
|
124
|
-
queries.push(Query.equal("targetCollection", params.targetCollection));
|
|
125
|
-
}
|
|
126
|
-
const response = await db.listRows({
|
|
127
|
-
databaseId,
|
|
128
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
129
|
-
queries,
|
|
130
|
-
});
|
|
131
|
-
if (response.rows && response.rows.length > 0) {
|
|
132
|
-
logger.debug("Found existing operation", {
|
|
133
|
-
operationId: response.rows[0].$id,
|
|
134
|
-
operationType,
|
|
135
|
-
});
|
|
136
|
-
return response.rows[0];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
logger.debug("No existing operation found, creating new one", {
|
|
141
|
-
operationType,
|
|
142
|
-
error: error instanceof Error ? error.message : String(error),
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
// Create new operation
|
|
146
|
-
const newOperation = {
|
|
147
|
-
operationType,
|
|
148
|
-
targetCollection: params?.targetCollection,
|
|
149
|
-
status: "pending",
|
|
150
|
-
progress: params?.progress ?? 0,
|
|
151
|
-
total: params?.total ?? 0,
|
|
152
|
-
data: params?.data ? JSON.stringify(params.data) : undefined,
|
|
153
|
-
error: params?.error,
|
|
154
|
-
};
|
|
155
|
-
const result = await db.createRow({
|
|
156
|
-
databaseId,
|
|
157
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
158
|
-
id: ID.unique(),
|
|
159
|
-
data: newOperation,
|
|
160
|
-
});
|
|
161
|
-
logger.info("Created new operation", {
|
|
162
|
-
operationId: result.data?.$id,
|
|
163
|
-
operationType,
|
|
164
|
-
});
|
|
165
|
-
return result.data;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Updates an existing operation record
|
|
169
|
-
*/
|
|
170
|
-
export async function updateOperation(db, databaseId, operationId, updates) {
|
|
171
|
-
// Prepare update data (exclude system fields like $id, $createdAt, $updatedAt)
|
|
172
|
-
const updateData = {};
|
|
173
|
-
if (updates.operationType !== undefined)
|
|
174
|
-
updateData.operationType = updates.operationType;
|
|
175
|
-
if (updates.targetCollection !== undefined)
|
|
176
|
-
updateData.targetCollection = updates.targetCollection;
|
|
177
|
-
if (updates.status !== undefined)
|
|
178
|
-
updateData.status = updates.status;
|
|
179
|
-
if (updates.progress !== undefined)
|
|
180
|
-
updateData.progress = updates.progress;
|
|
181
|
-
if (updates.total !== undefined)
|
|
182
|
-
updateData.total = updates.total;
|
|
183
|
-
if (updates.error !== undefined)
|
|
184
|
-
updateData.error = updates.error;
|
|
185
|
-
if (updates.data !== undefined) {
|
|
186
|
-
updateData.data =
|
|
187
|
-
typeof updates.data === "string"
|
|
188
|
-
? updates.data
|
|
189
|
-
: JSON.stringify(updates.data);
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const result = await db.updateRow({
|
|
193
|
-
databaseId,
|
|
194
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
195
|
-
id: operationId,
|
|
196
|
-
data: updateData,
|
|
197
|
-
});
|
|
198
|
-
logger.debug("Updated operation", {
|
|
199
|
-
operationId,
|
|
200
|
-
updates: Object.keys(updateData),
|
|
201
|
-
});
|
|
202
|
-
return result.data;
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
logger.error("Failed to update operation", {
|
|
206
|
-
operationId,
|
|
207
|
-
error: error instanceof Error ? error.message : String(error),
|
|
208
|
-
});
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Gets a single operation by ID
|
|
214
|
-
*/
|
|
215
|
-
export async function getOperation(db, databaseId, operationId) {
|
|
216
|
-
try {
|
|
217
|
-
const result = await db.getRow({
|
|
218
|
-
databaseId,
|
|
219
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
220
|
-
id: operationId,
|
|
221
|
-
});
|
|
222
|
-
return result.data;
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
logger.debug("Operation not found", {
|
|
226
|
-
operationId,
|
|
227
|
-
error: error instanceof Error ? error.message : String(error),
|
|
228
|
-
});
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Cleans up old completed operations
|
|
234
|
-
* @param olderThan - Optional date, defaults to operations older than 7 days
|
|
235
|
-
* @returns Number of operations deleted
|
|
236
|
-
*/
|
|
237
|
-
export async function cleanupOperations(db, databaseId, olderThan) {
|
|
238
|
-
const cutoffDate = olderThan || new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); // 7 days ago
|
|
239
|
-
const cutoffIso = cutoffDate.toISOString();
|
|
240
|
-
try {
|
|
241
|
-
// Query for completed operations older than cutoff
|
|
242
|
-
const response = await db.listRows({
|
|
243
|
-
databaseId,
|
|
244
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
245
|
-
queries: [
|
|
246
|
-
Query.equal("status", ["completed", "failed", "cancelled"]),
|
|
247
|
-
Query.lessThan("$createdAt", cutoffIso),
|
|
248
|
-
],
|
|
249
|
-
});
|
|
250
|
-
if (!response.rows || response.rows.length === 0) {
|
|
251
|
-
logger.debug("No old operations to clean up", { databaseId });
|
|
252
|
-
return 0;
|
|
253
|
-
}
|
|
254
|
-
// Delete in batches
|
|
255
|
-
let deletedCount = 0;
|
|
256
|
-
for (const operation of response.rows) {
|
|
257
|
-
try {
|
|
258
|
-
await db.deleteRow({
|
|
259
|
-
databaseId,
|
|
260
|
-
tableId: OPERATIONS_TABLE_ID,
|
|
261
|
-
id: operation.$id,
|
|
262
|
-
});
|
|
263
|
-
deletedCount++;
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
logger.warn("Failed to delete operation", {
|
|
267
|
-
operationId: operation.$id,
|
|
268
|
-
error: error instanceof Error ? error.message : String(error),
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
logger.info("Cleaned up old operations", {
|
|
273
|
-
databaseId,
|
|
274
|
-
deletedCount,
|
|
275
|
-
cutoffDate: cutoffIso,
|
|
276
|
-
});
|
|
277
|
-
return deletedCount;
|
|
278
|
-
}
|
|
279
|
-
catch (error) {
|
|
280
|
-
logger.error("Failed to cleanup operations", {
|
|
281
|
-
databaseId,
|
|
282
|
-
error: error instanceof Error ? error.message : String(error),
|
|
283
|
-
});
|
|
284
|
-
return 0;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema for operation tracking table (_appwrite_operations)
|
|
3
|
-
*
|
|
4
|
-
* This table is created dynamically in each database to track long-running operations
|
|
5
|
-
* like imports, exports, transfers, and backups.
|
|
6
|
-
*/
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
export interface OperationRecord {
|
|
9
|
-
$id: string;
|
|
10
|
-
$createdAt: string;
|
|
11
|
-
$updatedAt: string;
|
|
12
|
-
operationType: string;
|
|
13
|
-
targetCollection?: string;
|
|
14
|
-
status: OperationStatus;
|
|
15
|
-
progress: number;
|
|
16
|
-
total: number;
|
|
17
|
-
data?: any;
|
|
18
|
-
error?: string;
|
|
19
|
-
}
|
|
20
|
-
export type OperationStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'cancelled';
|
|
21
|
-
export declare const OPERATION_STATUSES: readonly ["pending", "in_progress", "completed", "failed", "cancelled"];
|
|
22
|
-
export declare const OperationStatusSchema: z.ZodEnum<{
|
|
23
|
-
pending: "pending";
|
|
24
|
-
in_progress: "in_progress";
|
|
25
|
-
completed: "completed";
|
|
26
|
-
cancelled: "cancelled";
|
|
27
|
-
failed: "failed";
|
|
28
|
-
}>;
|
|
29
|
-
export declare const OperationRecordSchema: z.ZodObject<{
|
|
30
|
-
$id: z.ZodString;
|
|
31
|
-
$createdAt: z.ZodString;
|
|
32
|
-
$updatedAt: z.ZodString;
|
|
33
|
-
operationType: z.ZodString;
|
|
34
|
-
targetCollection: z.ZodOptional<z.ZodString>;
|
|
35
|
-
status: z.ZodEnum<{
|
|
36
|
-
pending: "pending";
|
|
37
|
-
in_progress: "in_progress";
|
|
38
|
-
completed: "completed";
|
|
39
|
-
cancelled: "cancelled";
|
|
40
|
-
failed: "failed";
|
|
41
|
-
}>;
|
|
42
|
-
progress: z.ZodNumber;
|
|
43
|
-
total: z.ZodNumber;
|
|
44
|
-
data: z.ZodOptional<z.ZodAny>;
|
|
45
|
-
error: z.ZodOptional<z.ZodString>;
|
|
46
|
-
}, z.core.$strip>;
|
|
47
|
-
export declare const OPERATIONS_TABLE_ID = "_appwrite_operations";
|
|
48
|
-
export declare const OPERATIONS_TABLE_NAME = "Operations Tracking";
|