From 06e9d65b9f617837f141474f8f4911f38284f456 Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Thu, 26 May 2022 14:58:51 +0300 Subject: [PATCH] Tech | Refactoring | MW 0.9.0 with Protocol refactoring + Auth refactoring (#2242) --- .../features/auth/SetupSelectedAccountTest.kt | 7 +- .../anytypeio/anytype/di/feature/AuthDI.kt | 15 +- .../anytype/di/feature/DashboardDi.kt | 23 +- .../anytype/di/feature/MainEntryDI.kt | 11 +- .../anytype/di/feature/NavigationDI.kt | 5 +- .../anytypeio/anytype/di/feature/SplashDi.kt | 13 +- .../di/feature/auth/DeletedAccountDI.kt | 9 +- .../di/feature/settings/AccountAndDataDI.kt | 11 +- .../di/feature/settings/LogoutWarningDI.kt | 11 +- .../anytypeio/anytype/di/main/ConfigModule.kt | 20 +- .../anytypeio/anytype/di/main/DataModule.kt | 7 +- .../anytypeio/anytype/core_models}/Account.kt | 4 +- .../anytype/core_models/AccountSetup.kt | 8 + .../anytypeio/anytype/core_models/Response.kt | 1 + data/build.gradle | 1 + .../data/auth/mapper/MapperExtension.kt | 2 +- .../data/auth/repo/AuthCacheDataStore.kt | 3 +- .../data/auth/repo/AuthDataRepository.kt | 16 +- .../anytype/data/auth/repo/AuthDataStore.kt | 3 +- .../anytype/data/auth/repo/AuthRemote.kt | 4 +- .../auth/repo/block/BlockDataRepository.kt | 2 - .../data/auth/repo/block/BlockDataStore.kt | 1 - .../data/auth/repo/block/BlockRemote.kt | 1 - .../auth/repo/block/BlockRemoteDataStore.kt | 2 - .../data/auth/repo/config/Configuration.kt | 5 - .../data/auth/repo/config/Configurator.kt | 9 - .../data/auth/repo/config/GatewayProvider.kt | 7 +- .../anytype/data/AuthDataRepositoryTest.kt | 40 +- .../anytype/data/MapperExtensionTest.kt | 2 +- dependencies.gradle | 2 +- .../domain/auth/interactor/CreateAccount.kt | 2 +- .../domain/auth/interactor/GetAccount.kt | 2 +- .../auth/interactor/GetCurrentAccount.kt | 48 - .../domain/auth/interactor/GetProfile.kt | 12 +- .../domain/auth/interactor/LaunchAccount.kt | 18 +- .../anytype/domain/auth/interactor/Logout.kt | 5 +- .../domain/auth/interactor/ObserveAccounts.kt | 2 +- .../domain/auth/interactor/StartAccount.kt | 25 +- .../domain/auth/repo/AuthRepository.kt | 5 +- .../block/interactor/sets/CreateObjectSet.kt | 2 +- .../domain/block/repo/BlockRepository.kt | 2 - .../anytype/domain/config/ConfigStorage.kt | 23 + .../anytype/domain/config/Gateway.kt | 2 +- .../anytype/domain/config/GetConfig.kt | 5 +- .../dashboard/interactor/CloseDashboard.kt | 26 +- .../dashboard/interactor/OpenDashboard.kt | 8 +- .../anytype/domain/misc/UrlBuilder.kt | 10 +- .../auth/CheckAuthorizationStatusTest.kt | 10 +- .../anytype/domain/auth/CreateAccountTest.kt | 12 +- .../domain/auth/GetCurrentAccountTest.kt | 181 - .../domain/auth/ObserveAccountsTest.kt | 6 +- .../anytype/domain/auth/StartAccountTest.kt | 62 +- .../domain/dashboard/GetProfileTest.kt | 23 +- .../domain/dashboard/OpenDashboardTest.kt | 22 +- .../anytype/domain/misc/UrlBuilderTest.kt | 18 +- .../anytype/middleware/UnsplashMiddleware.kt | 8 +- .../anytype/middleware/auth/AuthMappers.kt | 40 + .../anytype/middleware/auth/AuthMiddleware.kt | 38 +- .../middleware/block/BlockMiddleware.kt | 162 +- .../middleware/config/DefaultConfigurator.kt | 50 - .../middleware/interactor/Middleware.kt | 2330 +++--- .../middleware/mappers/UnsplashMapper.kt | 2 +- .../middleware/service/MiddlewareService.kt | 232 +- .../MiddlewareServiceImplementation.kt | 1451 ++-- .../com/anytypeio/anytype/MiddlewareTest.kt | 122 +- .../auth/account/SelectAccountViewModel.kt | 9 +- presentation/src/test/java/FakeGateWay.kt | 2 +- .../auth/DeleteAccountViewModelTest.kt | 7 +- .../auth/SelectAccountViewModelTest.kt | 2 +- .../auth/SetupSelectedAccountViewModelTest.kt | 28 +- .../dashboard/DashboardTestSetup.kt | 2 +- protocol/src/main/proto/block.proto | 5 +- protocol/src/main/proto/commands.proto | 6453 ++++++++--------- protocol/src/main/proto/events.proto | 16 +- protocol/src/main/proto/localstore.proto | 3 +- protocol/src/main/proto/models.proto | 17 +- .../com/anytypeio/anytype/core_models/Auth.kt | 49 + 77 files changed, 5700 insertions(+), 6104 deletions(-) rename {domain/src/main/java/com/anytypeio/anytype/domain/auth/model => core-models/src/main/java/com/anytypeio/anytype/core_models}/Account.kt (75%) create mode 100644 core-models/src/main/java/com/anytypeio/anytype/core_models/AccountSetup.kt delete mode 100644 data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configuration.kt delete mode 100644 data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configurator.kt delete mode 100644 domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetCurrentAccount.kt create mode 100644 domain/src/main/java/com/anytypeio/anytype/domain/config/ConfigStorage.kt delete mode 100644 domain/src/test/java/com/anytypeio/anytype/domain/auth/GetCurrentAccountTest.kt create mode 100644 middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMappers.kt delete mode 100644 middleware/src/main/java/com/anytypeio/anytype/middleware/config/DefaultConfigurator.kt create mode 100644 test/core-models-stub/src/main/java/com/anytypeio/anytype/core_models/Auth.kt diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/auth/SetupSelectedAccountTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/auth/SetupSelectedAccountTest.kt index 58e28a9bd5..3ad830671f 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/auth/SetupSelectedAccountTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/auth/SetupSelectedAccountTest.kt @@ -13,6 +13,7 @@ import com.anytypeio.anytype.domain.auth.interactor.StartAccount import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.block.interactor.sets.StoreObjectTypes import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider import com.anytypeio.anytype.domain.device.PathProvider import com.anytypeio.anytype.features.auth.fragments.TestSetupSelectedAccountFragment @@ -65,6 +66,9 @@ class SetupSelectedAccountTest { @Mock lateinit var pathProvider: PathProvider + @Mock + lateinit var configStorage: ConfigStorage + lateinit var storeObjectTypes: StoreObjectTypes @Before @@ -72,7 +76,8 @@ class SetupSelectedAccountTest { MockitoAnnotations.openMocks(this) startAccount = StartAccount( repository = authRepository, - featuresConfigProvider = featuresConfigProvider + featuresConfigProvider = featuresConfigProvider, + configStorage = configStorage ) storeObjectTypes = StoreObjectTypes( repo = blockRepository, diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/AuthDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/AuthDI.kt index 1669df7f2c..097dd86ca0 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/AuthDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/AuthDI.kt @@ -5,10 +5,18 @@ import com.anytypeio.anytype.analytics.base.Analytics import com.anytypeio.anytype.core_utils.di.scope.PerFeature import com.anytypeio.anytype.core_utils.di.scope.PerScreen import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider -import com.anytypeio.anytype.domain.auth.interactor.* +import com.anytypeio.anytype.domain.auth.interactor.ConvertWallet +import com.anytypeio.anytype.domain.auth.interactor.CreateAccount +import com.anytypeio.anytype.domain.auth.interactor.ObserveAccounts +import com.anytypeio.anytype.domain.auth.interactor.RecoverWallet +import com.anytypeio.anytype.domain.auth.interactor.SaveMnemonic +import com.anytypeio.anytype.domain.auth.interactor.SetupWallet +import com.anytypeio.anytype.domain.auth.interactor.StartAccount +import com.anytypeio.anytype.domain.auth.interactor.StartLoadingAccounts import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.block.interactor.sets.StoreObjectTypes import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider import com.anytypeio.anytype.domain.device.PathProvider import com.anytypeio.anytype.presentation.auth.account.CreateAccountViewModelFactory @@ -41,6 +49,7 @@ interface AuthSubComponent { } fun inject(fragment: InvitationFragment) + @ExperimentalMaterialApi fun inject(fragment: AboutAnalyticsFragment) @@ -261,10 +270,12 @@ object SetupSelectedAccountModule { @PerScreen fun provideSelectAccountUseCase( repository: AuthRepository, + configStorage: ConfigStorage, featuresConfigProvider: FeaturesConfigProvider ): StartAccount { return StartAccount( repository = repository, + configStorage = configStorage, featuresConfigProvider = featuresConfigProvider ) } @@ -358,7 +369,7 @@ object KeychainLoginModule { @PerScreen fun provideConvertWallet( authRepository: AuthRepository - ) : ConvertWallet { + ): ConvertWallet { return ConvertWallet( authRepository = authRepository ) diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/DashboardDi.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/DashboardDi.kt index 73e992e04a..dbe04ed18b 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/DashboardDi.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/DashboardDi.kt @@ -8,6 +8,7 @@ import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers import com.anytypeio.anytype.domain.block.interactor.Move import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider import com.anytypeio.anytype.domain.config.GetConfig import com.anytypeio.anytype.domain.config.GetDebugSettings @@ -107,10 +108,12 @@ object HomeDashboardModule { @PerScreen fun provideGetProfileUseCase( repository: BlockRepository, - subscriptionEventChannel: SubscriptionEventChannel + subscriptionEventChannel: SubscriptionEventChannel, + provider: ConfigStorage ): GetProfile = GetProfile( repo = repository, - channel = subscriptionEventChannel + channel = subscriptionEventChannel, + provider = provider ) @JvmStatic @@ -118,19 +121,23 @@ object HomeDashboardModule { @PerScreen fun provideOpenDashboardUseCase( repo: BlockRepository, - auth: AuthRepository + auth: AuthRepository, + provider: ConfigStorage ): OpenDashboard = OpenDashboard( repo = repo, - auth = auth + auth = auth, + provider = provider ) @JvmStatic @Provides @PerScreen fun provideCloseDashboardUseCase( - repo: BlockRepository + repo: BlockRepository, + provider: ConfigStorage ): CloseDashboard = CloseDashboard( - repo = repo + repo = repo, + provider = provider ) @JvmStatic @@ -146,9 +153,9 @@ object HomeDashboardModule { @Provides @PerScreen fun getConfigUseCase( - repo: BlockRepository + provider: ConfigStorage ): GetConfig = GetConfig( - repo = repo + provider = provider ) @JvmStatic diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt index c1f5c0c6b9..4ee7635ad5 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt @@ -8,6 +8,7 @@ import com.anytypeio.anytype.domain.auth.interactor.LaunchAccount import com.anytypeio.anytype.domain.auth.interactor.Logout import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider import com.anytypeio.anytype.domain.config.UserSettingsRepository import com.anytypeio.anytype.domain.device.PathProvider @@ -64,10 +65,12 @@ object MainEntryModule { fun provideLaunchAccountUseCase( authRepository: AuthRepository, pathProvider: PathProvider, + configStorage: ConfigStorage, featuresConfigProvider: FeaturesConfigProvider ): LaunchAccount = LaunchAccount( repository = authRepository, pathProvider = pathProvider, + configStorage = configStorage, featuresConfigProvider = featuresConfigProvider ) @@ -112,7 +115,11 @@ object MainEntryModule { @JvmStatic @PerScreen @Provides - fun provideLogoutUseCase(repo: AuthRepository): Logout = Logout( - repo = repo + fun provideLogoutUseCase( + repo: AuthRepository, + provider: ConfigStorage + ): Logout = Logout( + repo = repo, + provider ) } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/NavigationDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/NavigationDI.kt index a33949294b..52cacf7b49 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/NavigationDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/NavigationDI.kt @@ -4,6 +4,7 @@ import com.anytypeio.anytype.analytics.base.Analytics import com.anytypeio.anytype.core_utils.di.scope.PerScreen import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.GetConfig import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.page.navigation.GetObjectInfoWithLinks @@ -59,8 +60,8 @@ object PageNavigationModule { @Provides @PerScreen fun getConfigUseCase( - repo: BlockRepository + provider: ConfigStorage ): GetConfig = GetConfig( - repo = repo + provider = provider ) } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/SplashDi.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/SplashDi.kt index 6a6e99258e..5baa866eee 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/SplashDi.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/SplashDi.kt @@ -10,6 +10,7 @@ import com.anytypeio.anytype.domain.auth.interactor.LaunchWallet import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.block.interactor.sets.StoreObjectTypes import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider import com.anytypeio.anytype.domain.config.UserSettingsRepository import com.anytypeio.anytype.domain.device.PathProvider @@ -23,12 +24,6 @@ import dagger.Module import dagger.Provides import dagger.Subcomponent -/** - * Created by Konstantin Ivanov - * email : ki@agileburo.com - * on 2019-10-21. - */ - @PerScreen @Subcomponent(modules = [SplashModule::class]) interface SplashSubComponent { @@ -87,11 +82,13 @@ object SplashModule { fun provideLaunchAccountUseCase( authRepository: AuthRepository, pathProvider: PathProvider, - featuresConfigProvider: FeaturesConfigProvider + featuresConfigProvider: FeaturesConfigProvider, + configStorage: ConfigStorage ): LaunchAccount = LaunchAccount( repository = authRepository, pathProvider = pathProvider, - featuresConfigProvider = featuresConfigProvider + featuresConfigProvider = featuresConfigProvider, + configStorage = configStorage ) @JvmStatic diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/auth/DeletedAccountDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/auth/DeletedAccountDI.kt index 263d08fa50..54f2d1c852 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/auth/DeletedAccountDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/auth/DeletedAccountDI.kt @@ -5,6 +5,7 @@ import com.anytypeio.anytype.domain.account.DateHelper import com.anytypeio.anytype.domain.account.RestoreAccount import com.anytypeio.anytype.domain.auth.interactor.Logout import com.anytypeio.anytype.domain.auth.repo.AuthRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.ext.DefaultDateHelper import com.anytypeio.anytype.presentation.auth.account.DeletedAccountViewModel import com.anytypeio.anytype.ui.auth.account.DeletedAccountFragment @@ -49,8 +50,12 @@ object DeletedAccountModule { @JvmStatic @Provides @PerScreen - fun provideLogout(repo: AuthRepository): Logout = Logout( - repo = repo + fun provideLogout( + repo: AuthRepository, + provider: ConfigStorage + ): Logout = Logout( + repo = repo, + provider = provider ) @JvmStatic diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/settings/AccountAndDataDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/settings/AccountAndDataDI.kt index 335a417275..f2a9c65cb6 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/settings/AccountAndDataDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/settings/AccountAndDataDI.kt @@ -6,6 +6,7 @@ import com.anytypeio.anytype.domain.account.DeleteAccount import com.anytypeio.anytype.domain.auth.interactor.Logout import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.device.ClearFileCache import com.anytypeio.anytype.ui.settings.AccountAndDataFragment import com.anytypeio.anytype.ui_settings.account.AccountAndDataViewModel @@ -47,9 +48,15 @@ object AccountAndDataModule { fun clearFileCache(repo: BlockRepository): ClearFileCache = ClearFileCache(repo) @JvmStatic - @Provides @PerScreen - fun logout(repo: AuthRepository): Logout = Logout(repo) + @Provides + fun provideLogoutUseCase( + repo: AuthRepository, + provider: ConfigStorage + ): Logout = Logout( + repo = repo, + provider + ) @JvmStatic @Provides diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/settings/LogoutWarningDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/settings/LogoutWarningDI.kt index b98a67b73b..638866d380 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/settings/LogoutWarningDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/settings/LogoutWarningDI.kt @@ -4,6 +4,7 @@ import com.anytypeio.anytype.analytics.base.Analytics import com.anytypeio.anytype.core_utils.di.scope.PerScreen import com.anytypeio.anytype.domain.auth.interactor.Logout import com.anytypeio.anytype.domain.auth.repo.AuthRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.ui.settings.LogoutWarningFragment import com.anytypeio.anytype.ui_settings.account.LogoutWarningViewModel import dagger.Module @@ -35,7 +36,13 @@ object LogoutWarningModule { ): LogoutWarningViewModel.Factory = LogoutWarningViewModel.Factory(logout, analytics) @JvmStatic - @Provides @PerScreen - fun logout(repo: AuthRepository): Logout = Logout(repo) + @Provides + fun provideLogoutUseCase( + repo: AuthRepository, + provider: ConfigStorage + ): Logout = Logout( + repo = repo, + provider + ) } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/di/main/ConfigModule.kt b/app/src/main/java/com/anytypeio/anytype/di/main/ConfigModule.kt index aaafdf687d..44752e9578 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/main/ConfigModule.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/main/ConfigModule.kt @@ -1,11 +1,8 @@ package com.anytypeio.anytype.di.main -import com.anytypeio.anytype.core_models.Config -import com.anytypeio.anytype.data.auth.repo.config.Configuration -import com.anytypeio.anytype.data.auth.repo.config.Configurator import com.anytypeio.anytype.data.auth.repo.config.GatewayProvider +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.Gateway -import com.anytypeio.anytype.middleware.config.DefaultConfigurator import dagger.Module import dagger.Provides import javax.inject.Singleton @@ -16,19 +13,12 @@ object ConfigModule { @JvmStatic @Provides @Singleton - fun provideApplicationConfig(configurator: Configurator): Config { - return Configuration(configurator).init() - } + fun provideGateway( + provider: ConfigStorage + ): Gateway = GatewayProvider(provider) @JvmStatic @Provides @Singleton - fun provideGateway(configurator: Configurator): Gateway = GatewayProvider(configurator) - - @JvmStatic - @Provides - @Singleton - fun provideConfigurator(): Configurator { - return DefaultConfigurator() - } + fun provideConfigProvider(): ConfigStorage = ConfigStorage.CacheStorage() } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/di/main/DataModule.kt b/app/src/main/java/com/anytypeio/anytype/di/main/DataModule.kt index fc8dd08712..f85dace3b1 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/main/DataModule.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/main/DataModule.kt @@ -20,7 +20,6 @@ import com.anytypeio.anytype.data.auth.repo.block.BlockDataRepository import com.anytypeio.anytype.data.auth.repo.block.BlockDataStoreFactory import com.anytypeio.anytype.data.auth.repo.block.BlockRemote import com.anytypeio.anytype.data.auth.repo.block.BlockRemoteDataStore -import com.anytypeio.anytype.data.auth.repo.config.Configurator import com.anytypeio.anytype.data.auth.repo.unsplash.UnsplashDataRepository import com.anytypeio.anytype.data.auth.repo.unsplash.UnsplashRemote import com.anytypeio.anytype.data.auth.types.DefaultObjectTypesProvider @@ -66,12 +65,10 @@ object DataModule { @Provides @Singleton fun provideAuthRepository( - factory: AuthDataStoreFactory, - configurator: Configurator + factory: AuthDataStoreFactory ): AuthRepository { return AuthDataRepository( - factory = factory, - configurator = configurator + factory = factory ) } diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/model/Account.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/Account.kt similarity index 75% rename from domain/src/main/java/com/anytypeio/anytype/domain/auth/model/Account.kt rename to core-models/src/main/java/com/anytypeio/anytype/core_models/Account.kt index 43ce59e098..6f2f17c297 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/model/Account.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/Account.kt @@ -1,6 +1,4 @@ -package com.anytypeio.anytype.domain.auth.model - -import com.anytypeio.anytype.core_models.Url +package com.anytypeio.anytype.core_models /** * User account. diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/AccountSetup.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/AccountSetup.kt new file mode 100644 index 0000000000..a21c1cfd9f --- /dev/null +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/AccountSetup.kt @@ -0,0 +1,8 @@ +package com.anytypeio.anytype.core_models + +data class AccountSetup( + val account: Account, + val config: Config, + val features: FeaturesConfig, + val status: AccountStatus +) \ No newline at end of file diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/Response.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/Response.kt index 597f788806..86feb8ddc3 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/Response.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/Response.kt @@ -37,6 +37,7 @@ sealed class Response { sealed class Set : Response() { data class Create( + @Deprecated("legacy param") val blockId: Id?, val targetId: Id, val payload: Payload diff --git a/data/build.gradle b/data/build.gradle index 3c7f1d5b9d..50c36cac6f 100644 --- a/data/build.gradle +++ b/data/build.gradle @@ -11,6 +11,7 @@ dependencies { implementation applicationDependencies.coroutines testImplementation project(":test:utils") + testImplementation project(":test:core-models-stub") testImplementation unitTestDependencies.junit testImplementation unitTestDependencies.kotlinTest testImplementation unitTestDependencies.mockitoKotlin diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/mapper/MapperExtension.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/mapper/MapperExtension.kt index 0601064fce..e1b3e9657b 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/mapper/MapperExtension.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/mapper/MapperExtension.kt @@ -1,9 +1,9 @@ package com.anytypeio.anytype.data.auth.mapper +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.data.auth.model.AccountEntity import com.anytypeio.anytype.data.auth.model.FeaturesConfigEntity import com.anytypeio.anytype.data.auth.model.WalletEntity -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.domain.auth.model.Wallet import com.anytypeio.anytype.core_models.FeaturesConfig diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthCacheDataStore.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthCacheDataStore.kt index 6837e2b9dd..eaeeacb365 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthCacheDataStore.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthCacheDataStore.kt @@ -1,5 +1,6 @@ package com.anytypeio.anytype.data.auth.repo +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.data.auth.model.AccountEntity @@ -12,7 +13,7 @@ class AuthCacheDataStore(private val cache: AuthCache) : AuthDataStore { override suspend fun startAccount( id: String, path: String - ): Triple { + ): AccountSetup { throw UnsupportedOperationException() } diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataRepository.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataRepository.kt index dd8e9aacec..71b4d21642 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataRepository.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataRepository.kt @@ -1,30 +1,23 @@ package com.anytypeio.anytype.data.auth.repo +import com.anytypeio.anytype.core_models.Account +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.core_models.FeaturesConfig import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.data.auth.mapper.toDomain import com.anytypeio.anytype.data.auth.mapper.toEntity -import com.anytypeio.anytype.data.auth.repo.config.Configurator -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.domain.auth.model.Wallet import com.anytypeio.anytype.domain.auth.repo.AuthRepository import kotlinx.coroutines.flow.map class AuthDataRepository( - private val factory: AuthDataStoreFactory, - private val configurator: Configurator + private val factory: AuthDataStoreFactory ) : AuthRepository { override suspend fun startAccount( id: String, path: String - ): Triple = factory.remote.startAccount(id, path).let { triple -> - Triple( - first = triple.first.toDomain(), - second = triple.second.toDomain(), - third = triple.third - ) - } + ): AccountSetup = factory.remote.startAccount(id, path) override suspend fun createAccount( name: String, @@ -71,7 +64,6 @@ class AuthDataRepository( override suspend fun getMnemonic() = factory.cache.getMnemonic() override suspend fun logout(clearLocalRepositoryData: Boolean) { - configurator.release() factory.remote.logout(clearLocalRepositoryData) factory.cache.logout(clearLocalRepositoryData) } diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataStore.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataStore.kt index cdc4d38f4a..0ef3a216d8 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataStore.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthDataStore.kt @@ -1,5 +1,6 @@ package com.anytypeio.anytype.data.auth.repo +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.data.auth.model.AccountEntity @@ -9,7 +10,7 @@ import kotlinx.coroutines.flow.Flow interface AuthDataStore { - suspend fun startAccount(id: String, path: String): Triple + suspend fun startAccount(id: String, path: String): AccountSetup suspend fun createAccount(name: String, avatarPath: String?, invitationCode: String): AccountEntity diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthRemote.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthRemote.kt index f13e6a4157..78c70f1c17 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthRemote.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/AuthRemote.kt @@ -1,13 +1,13 @@ package com.anytypeio.anytype.data.auth.repo +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.data.auth.model.AccountEntity -import com.anytypeio.anytype.data.auth.model.FeaturesConfigEntity import com.anytypeio.anytype.data.auth.model.WalletEntity import kotlinx.coroutines.flow.Flow interface AuthRemote { - suspend fun startAccount(id: String, path: String): Triple + suspend fun startAccount(id: String, path: String): AccountSetup suspend fun createAccount(name: String, avatarPath: String?, invitationCode: String): AccountEntity suspend fun deleteAccount() : AccountStatus suspend fun restoreAccount() : AccountStatus diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt index 7ae0445391..328590f7fa 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt @@ -31,8 +31,6 @@ class BlockDataRepository( private val factory: BlockDataStoreFactory ) : BlockRepository { - override suspend fun getConfig() = factory.remote.getConfig() - override suspend fun openDashboard( contextId: String, id: String diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataStore.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataStore.kt index 71481fea06..fe3103c35b 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataStore.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataStore.kt @@ -41,7 +41,6 @@ interface BlockDataStore { suspend fun uploadBlock(command: Command.UploadBlock): Payload suspend fun move(command: Command.Move): Payload suspend fun unlink(command: Command.Unlink): Payload - suspend fun getConfig(): Config suspend fun createPage( ctx: Id?, emoji: String?, diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt index a415c0707e..5e134cb1ea 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt @@ -38,7 +38,6 @@ interface BlockRemote { suspend fun updateCheckbox(command: Command.UpdateCheckbox): Payload suspend fun move(command: Command.Move): Payload - suspend fun getConfig(): Config suspend fun createPage( ctx: Id?, emoji: String?, diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemoteDataStore.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemoteDataStore.kt index 97f143c211..326859ca9c 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemoteDataStore.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemoteDataStore.kt @@ -19,8 +19,6 @@ import com.anytypeio.anytype.core_models.SearchResult class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore { - override suspend fun getConfig() = remote.getConfig() - override suspend fun openDashboard( contextId: String, id: String diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configuration.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configuration.kt deleted file mode 100644 index e1256234a4..0000000000 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configuration.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.anytypeio.anytype.data.auth.repo.config - -class Configuration(private val configurator: Configurator) { - fun init() = configurator.configure() -} \ No newline at end of file diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configurator.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configurator.kt deleted file mode 100644 index b91f0c9e95..0000000000 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/Configurator.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.anytypeio.anytype.data.auth.repo.config - -import com.anytypeio.anytype.core_models.Config - - -interface Configurator { - fun configure(): Config - fun release() -} \ No newline at end of file diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/GatewayProvider.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/GatewayProvider.kt index dfbb395dc0..0586022894 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/GatewayProvider.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/config/GatewayProvider.kt @@ -1,7 +1,10 @@ package com.anytypeio.anytype.data.auth.repo.config +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.Gateway -class GatewayProvider(private val configurator: Configurator) : Gateway { - override fun obtain(): String = configurator.configure().gateway +class GatewayProvider( + private val configStorage: ConfigStorage +) : Gateway { + override fun provide(): String = configStorage.get().gateway } \ No newline at end of file diff --git a/data/src/test/java/com/anytypeio/anytype/data/AuthDataRepositoryTest.kt b/data/src/test/java/com/anytypeio/anytype/data/AuthDataRepositoryTest.kt index dd8009dd96..64cf96ff0b 100644 --- a/data/src/test/java/com/anytypeio/anytype/data/AuthDataRepositoryTest.kt +++ b/data/src/test/java/com/anytypeio/anytype/data/AuthDataRepositoryTest.kt @@ -1,12 +1,16 @@ package com.anytypeio.anytype.data +import com.anytypeio.anytype.core_models.Account +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus +import com.anytypeio.anytype.core_models.FeaturesConfig +import com.anytypeio.anytype.core_models.StubAccount +import com.anytypeio.anytype.core_models.StubAccountSetup +import com.anytypeio.anytype.core_models.StubConfig +import com.anytypeio.anytype.core_models.StubFeatureConfig import com.anytypeio.anytype.data.auth.model.AccountEntity -import com.anytypeio.anytype.data.auth.model.FeaturesConfigEntity import com.anytypeio.anytype.data.auth.model.WalletEntity import com.anytypeio.anytype.data.auth.repo.* -import com.anytypeio.anytype.data.auth.repo.config.Configurator -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.test_utils.MockDataFactory import kotlinx.coroutines.runBlocking import org.junit.Before @@ -23,11 +27,10 @@ class AuthDataRepositoryTest { @Mock lateinit var authCache: AuthCache - @Mock - lateinit var configurator: Configurator - lateinit var repo: AuthDataRepository + val config = StubConfig() + @Before fun setup() { MockitoAnnotations.openMocks(this) @@ -39,8 +42,7 @@ class AuthDataRepositoryTest { remote = AuthRemoteDataStore( authRemote = authRemote ) - ), - configurator = configurator + ) ) } @@ -51,17 +53,14 @@ class AuthDataRepositoryTest { val path = MockDataFactory.randomString() - val account = AccountEntity( - id = id, - name = MockDataFactory.randomString(), - color = null - ) + val account = StubAccount() - val config = FeaturesConfigEntity() + val features = StubFeatureConfig() authRemote.stub { - onBlocking { startAccount(id = id, path = path) } doReturn Triple( - account, config, AccountStatus.Active + onBlocking { startAccount(id = id, path = path) } doReturn StubAccountSetup( + account = account, + features = features ) } @@ -131,12 +130,7 @@ class AuthDataRepositoryTest { @Test fun `should call only cache in order to save account`() = runBlocking { - val account = Account( - id = MockDataFactory.randomUuid(), - name = MockDataFactory.randomString(), - avatar = null, - color = null - ) + val account = StubAccount() authCache.stub { onBlocking { saveAccount(any()) } doReturn Unit @@ -234,8 +228,6 @@ class AuthDataRepositoryTest { verifyNoMoreInteractions(authCache) verify(authRemote, times(1)).logout(false) verifyNoMoreInteractions(authRemote) - verify(configurator, times(1)).release() - verifyZeroInteractions(configurator) } @Test diff --git a/data/src/test/java/com/anytypeio/anytype/data/MapperExtensionTest.kt b/data/src/test/java/com/anytypeio/anytype/data/MapperExtensionTest.kt index 10df634532..3388a34038 100644 --- a/data/src/test/java/com/anytypeio/anytype/data/MapperExtensionTest.kt +++ b/data/src/test/java/com/anytypeio/anytype/data/MapperExtensionTest.kt @@ -1,10 +1,10 @@ package com.anytypeio.anytype.data +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.data.auth.mapper.toDomain import com.anytypeio.anytype.data.auth.mapper.toEntity import com.anytypeio.anytype.data.auth.model.AccountEntity import com.anytypeio.anytype.data.auth.model.WalletEntity -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.test_utils.MockDataFactory import org.junit.Test import kotlin.test.assertTrue diff --git a/dependencies.gradle b/dependencies.gradle index 222827fa0f..9dcabe6087 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -86,7 +86,7 @@ ext { // Anytype - middleware_version = 'v0.18.3' + middleware_version = 'v0.19.0' mainApplication = [ kotlin: "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version", diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/CreateAccount.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/CreateAccount.kt index 2475ef171a..efeb844d6e 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/CreateAccount.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/CreateAccount.kt @@ -1,6 +1,6 @@ package com.anytypeio.anytype.domain.auth.interactor -import com.anytypeio.anytype.domain.auth.model.Account +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.BaseUseCase import com.anytypeio.anytype.domain.base.Either diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetAccount.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetAccount.kt index 9c89225ead..a8790bb461 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetAccount.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetAccount.kt @@ -1,6 +1,6 @@ package com.anytypeio.anytype.domain.auth.interactor -import com.anytypeio.anytype.domain.auth.model.Account +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.BaseUseCase diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetCurrentAccount.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetCurrentAccount.kt deleted file mode 100644 index 616dd0e80b..0000000000 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetCurrentAccount.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.anytypeio.anytype.domain.auth.interactor - -import com.anytypeio.anytype.core_models.Event -import com.anytypeio.anytype.domain.auth.model.Account -import com.anytypeio.anytype.domain.base.BaseUseCase -import com.anytypeio.anytype.domain.base.Either -import com.anytypeio.anytype.domain.block.repo.BlockRepository -import com.anytypeio.anytype.domain.misc.UrlBuilder - -/** Use case for getting currently selected user account. - */ -@Deprecated("Incorrect use-case. Will be deleted.") -class GetCurrentAccount( - private val repo: BlockRepository, - private val builder: UrlBuilder -) : BaseUseCase() { - - override suspend fun run(params: None) = try { - Either.Right(execute()) - } catch (t: Throwable) { - Either.Left(t) - } - - private suspend fun execute(): Account { - val config = repo.getConfig() - - val payload = repo.openProfile(config.profile) - - val event = payload.events.first { event -> event is Event.Command.ShowObject } - - val details = (event as Event.Command.ShowObject).details.details[config.profile] - - val name = details?.name.orEmpty() - - val image = details?.iconImage - - return Account( - id = config.profile, - name = name, - avatar = if (image.isNullOrEmpty()) null else builder.image(image), - color = null - ) - } - - companion object { - const val MISSING_NAME_ERROR = "Profile name is missing" - } -} \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetProfile.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetProfile.kt index ba558548ba..adc326e8a3 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetProfile.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/GetProfile.kt @@ -7,14 +7,20 @@ import com.anytypeio.anytype.domain.`object`.amend import com.anytypeio.anytype.domain.`object`.unset import com.anytypeio.anytype.domain.base.BaseUseCase import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.search.SubscriptionEventChannel import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.emitAll +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.scan /** Use case for getting currently selected user account. */ class GetProfile( + private val provider: ConfigStorage, private val repo: BlockRepository, private val channel: SubscriptionEventChannel ) : BaseUseCase() { @@ -58,7 +64,7 @@ class GetProfile( subscription: Id, keys: List ): ObjectWrapper.Basic { - val config = repo.getConfig() + val config = provider.get() val result = repo.searchObjectsByIdWithSubscription( subscription = subscription, ids = listOf(config.profile), @@ -72,7 +78,7 @@ class GetProfile( @Deprecated("Should not be used. Will be changed.") override suspend fun run(params: Params) = safe { - val config = repo.getConfig() + val config = provider.get() val result = repo.searchObjectsByIdWithSubscription( subscription = params.subscription, ids = listOf(config.profile), diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt index 7d10715cfe..96004cbcfe 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt @@ -4,6 +4,7 @@ import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.BaseUseCase import com.anytypeio.anytype.domain.base.Either import com.anytypeio.anytype.domain.config.FeaturesConfigProvider +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.device.PathProvider import kotlinx.coroutines.Dispatchers import kotlin.coroutines.CoroutineContext @@ -15,6 +16,7 @@ class LaunchAccount( private val repository: AuthRepository, private val pathProvider: PathProvider, private val context: CoroutineContext = Dispatchers.IO, + private val configStorage: ConfigStorage, private val featuresConfigProvider: FeaturesConfigProvider ) : BaseUseCase(context) { @@ -22,16 +24,16 @@ class LaunchAccount( repository.startAccount( id = repository.getCurrentAccountId(), path = pathProvider.providePath() - ).let { pair -> - val (account, config, status) = pair - repository.updateAccount(account) + ).let { setup -> + repository.updateAccount(setup.account) featuresConfigProvider.set( - enableDataView = config.enableDataView ?: false, - enableDebug = config.enableDebug ?: false, - enableChannelSwitch = config.enableChannelSwitch ?: false, - enableSpaces = config.enableSpaces ?: false + enableDataView = setup.features.enableDataView ?: false, + enableDebug = setup.features.enableDebug ?: false, + enableChannelSwitch = setup.features.enableChannelSwitch ?: false, + enableSpaces = setup.features.enableSpaces ?: false ) - Either.Right(account.id) + configStorage.set(config = setup.config) + Either.Right(setup.account.id) } } catch (e: Throwable) { Either.Left(e) diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/Logout.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/Logout.kt index f290431779..fa69c92a4e 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/Logout.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/Logout.kt @@ -2,16 +2,19 @@ package com.anytypeio.anytype.domain.auth.interactor import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.Interactor +import com.anytypeio.anytype.domain.config.ConfigStorage /** * Use case for logging out. */ class Logout( - private val repo: AuthRepository + private val repo: AuthRepository, + private val provider: ConfigStorage ) : Interactor() { override suspend fun run(params: Params) { repo.logout(params.clearLocalRepositoryData) + provider.clear() } class Params( diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/ObserveAccounts.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/ObserveAccounts.kt index b5f0137fee..2623ce1a9c 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/ObserveAccounts.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/ObserveAccounts.kt @@ -1,6 +1,6 @@ package com.anytypeio.anytype.domain.auth.interactor -import com.anytypeio.anytype.domain.auth.model.Account +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.FlowUseCase diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/StartAccount.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/StartAccount.kt index d978a42604..0031b525f7 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/StartAccount.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/StartAccount.kt @@ -4,6 +4,7 @@ import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.BaseUseCase +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider /** @@ -11,25 +12,27 @@ import com.anytypeio.anytype.domain.config.FeaturesConfigProvider */ class StartAccount( private val repository: AuthRepository, + private val configStorage: ConfigStorage, private val featuresConfigProvider: FeaturesConfigProvider -) : BaseUseCase, StartAccount.Params>() { +) : BaseUseCase() { override suspend fun run(params: Params) = safe { - val (account, config, status) = repository.startAccount( + val setup = repository.startAccount( id = params.id, path = params.path ) with(repository) { - saveAccount(account) - setCurrentAccount(account.id) + saveAccount(setup.account) + setCurrentAccount(setup.account.id) featuresConfigProvider.set( - enableDataView = config.enableDataView ?: false, - enableDebug = config.enableDebug ?: false, - enableChannelSwitch = config.enableChannelSwitch ?: false, - enableSpaces = config.enableSpaces ?: false + enableDataView = setup.features.enableDataView ?: false, + enableDebug = setup.features.enableDebug ?: false, + enableChannelSwitch = setup.features.enableChannelSwitch ?: false, + enableSpaces = setup.features.enableSpaces ?: false ) + configStorage.set(config = setup.config) } - Pair(account.id, status) + StartAccountResult(setup.account.id, setup.status) } /** @@ -40,4 +43,6 @@ class StartAccount( val id: String, val path: String ) -} \ No newline at end of file +} + +typealias StartAccountResult = Pair \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/repo/AuthRepository.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/repo/AuthRepository.kt index 61351a1c2f..6607dc870c 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/repo/AuthRepository.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/repo/AuthRepository.kt @@ -1,9 +1,10 @@ package com.anytypeio.anytype.domain.auth.repo +import com.anytypeio.anytype.core_models.Account +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.core_models.FeaturesConfig import com.anytypeio.anytype.core_models.Id -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.domain.auth.model.Wallet import kotlinx.coroutines.flow.Flow @@ -14,7 +15,7 @@ interface AuthRepository { * @param id user account id * @param path wallet repository path */ - suspend fun startAccount(id: String, path: String): Triple + suspend fun startAccount(id: String, path: String): AccountSetup suspend fun createAccount(name: String, avatarPath: String?, invitationCode: String): Account diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/block/interactor/sets/CreateObjectSet.kt b/domain/src/main/java/com/anytypeio/anytype/domain/block/interactor/sets/CreateObjectSet.kt index 96acdf9ca0..8359227987 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/block/interactor/sets/CreateObjectSet.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/block/interactor/sets/CreateObjectSet.kt @@ -3,7 +3,6 @@ package com.anytypeio.anytype.domain.block.interactor.sets import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.Position -import com.anytypeio.anytype.core_models.Url import com.anytypeio.anytype.domain.base.BaseUseCase import com.anytypeio.anytype.domain.block.repo.BlockRepository @@ -33,6 +32,7 @@ class CreateObjectSet( */ data class Response( val target: Id, + @Deprecated("legacy param") val block: Id?, val payload: Payload ) diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt b/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt index 3bc9e8f0fa..68a468f9f8 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt @@ -85,8 +85,6 @@ interface BlockRepository { suspend fun setRelationKey(command: Command.SetRelationKey): Payload - suspend fun getConfig(): Config - suspend fun createPage( ctx: Id?, emoji: String?, diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/config/ConfigStorage.kt b/domain/src/main/java/com/anytypeio/anytype/domain/config/ConfigStorage.kt new file mode 100644 index 0000000000..f10cdb84f6 --- /dev/null +++ b/domain/src/main/java/com/anytypeio/anytype/domain/config/ConfigStorage.kt @@ -0,0 +1,23 @@ +package com.anytypeio.anytype.domain.config + +import com.anytypeio.anytype.core_models.Config + +interface ConfigStorage { + fun get(): Config + fun set(config: Config) + fun clear() + class CacheStorage : ConfigStorage { + private var instance: Config? = null + override fun get(): Config { + return instance ?: throw IllegalStateException("Config is not initialized") + } + + override fun set(config: Config) { + instance = config + } + + override fun clear() { + instance = null + } + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/config/Gateway.kt b/domain/src/main/java/com/anytypeio/anytype/domain/config/Gateway.kt index 57c8cdd3e1..d1d08bec8e 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/config/Gateway.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/config/Gateway.kt @@ -1,5 +1,5 @@ package com.anytypeio.anytype.domain.config interface Gateway { - fun obtain(): String + fun provide(): String } \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/config/GetConfig.kt b/domain/src/main/java/com/anytypeio/anytype/domain/config/GetConfig.kt index 12c05cbab7..ea24f7d70c 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/config/GetConfig.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/config/GetConfig.kt @@ -3,14 +3,13 @@ package com.anytypeio.anytype.domain.config import com.anytypeio.anytype.core_models.Config import com.anytypeio.anytype.domain.base.BaseUseCase import com.anytypeio.anytype.domain.base.Either -import com.anytypeio.anytype.domain.block.repo.BlockRepository class GetConfig( - private val repo: BlockRepository + private val provider: ConfigStorage ) : BaseUseCase() { override suspend fun run(params: Unit) = try { - repo.getConfig().let { + provider.get().let { Either.Right(it) } } catch (t: Throwable) { diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/CloseDashboard.kt b/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/CloseDashboard.kt index 35d5c68182..7d53b3762d 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/CloseDashboard.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/CloseDashboard.kt @@ -1,8 +1,8 @@ package com.anytypeio.anytype.domain.dashboard.interactor import com.anytypeio.anytype.domain.base.BaseUseCase -import com.anytypeio.anytype.domain.base.Either import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.MainConfig /** @@ -11,23 +11,17 @@ import com.anytypeio.anytype.domain.config.MainConfig * @property repo */ class CloseDashboard( - private val repo: BlockRepository + private val repo: BlockRepository, + private val provider: ConfigStorage ) : BaseUseCase() { - override suspend fun run(params: Param) = try { - if (params.id == MainConfig.HOME_DASHBOARD_ID) - repo.getConfig().let { config -> - repo.closeDashboard(id = config.home) - }.let { - Either.Right(it) - } - else - repo.closeDashboard(id = params.id).let { - Either.Right(it) - } - - } catch (t: Throwable) { - Either.Left(t) + override suspend fun run(params: Param) = safe { + if (params.id == MainConfig.HOME_DASHBOARD_ID) { + val config = provider.get() + repo.closeDashboard(id = config.home) + } else { + repo.closeDashboard(id = params.id) + } } /** diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/OpenDashboard.kt b/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/OpenDashboard.kt index ef61064b0a..c59134727c 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/OpenDashboard.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/interactor/OpenDashboard.kt @@ -1,10 +1,11 @@ package com.anytypeio.anytype.domain.dashboard.interactor +import com.anytypeio.anytype.core_models.Payload +import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.BaseUseCase import com.anytypeio.anytype.domain.base.Either import com.anytypeio.anytype.domain.block.repo.BlockRepository -import com.anytypeio.anytype.core_models.Payload -import com.anytypeio.anytype.domain.auth.repo.AuthRepository +import com.anytypeio.anytype.domain.config.ConfigStorage /** * Use-case for opening a dashboard by sending a special request. @@ -14,6 +15,7 @@ import com.anytypeio.anytype.domain.auth.repo.AuthRepository class OpenDashboard( private val repo: BlockRepository, private val auth: AuthRepository, + private val provider: ConfigStorage ) : BaseUseCase() { override suspend fun run(params: Param?) = try { @@ -27,7 +29,7 @@ class OpenDashboard( } } else { - repo.getConfig().let { config -> + provider.get().let { config -> repo.openDashboard( contextId = config.home, id = config.home diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/misc/UrlBuilder.kt b/domain/src/main/java/com/anytypeio/anytype/domain/misc/UrlBuilder.kt index 0a3bfa3567..9dd9bf0eba 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/misc/UrlBuilder.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/misc/UrlBuilder.kt @@ -12,27 +12,27 @@ class UrlBuilder(val gateway: Gateway) { /** * Builds image url for given [hash] */ - fun image(hash: String?): Url = gateway.obtain() + IMAGE_PATH + hash + DEFAULT_WIDTH_PARAM + fun image(hash: String?): Url = gateway.provide() + IMAGE_PATH + hash + DEFAULT_WIDTH_PARAM /** * Builds original image url for given [hash] */ - fun original(hash: String?): Url = gateway.obtain() + IMAGE_PATH + hash + fun original(hash: String?): Url = gateway.provide() + IMAGE_PATH + hash /** * Builds small image url for given [hash] */ - fun thumbnail(hash: String): Url = gateway.obtain() + IMAGE_PATH + hash + THUMBNAIL_WIDTH_PARAM + fun thumbnail(hash: String): Url = gateway.provide() + IMAGE_PATH + hash + THUMBNAIL_WIDTH_PARAM /** * Builds file url for given [hash] */ - fun file(hash: String?): Url = gateway.obtain() + FILE_PATH + hash + fun file(hash: String?): Url = gateway.provide() + FILE_PATH + hash /** * Builds video url for given [hash] */ - fun video(hash: String?): Url = gateway.obtain() + FILE_PATH + hash + fun video(hash: String?): Url = gateway.provide() + FILE_PATH + hash companion object { const val IMAGE_PATH = "/image/" diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/auth/CheckAuthorizationStatusTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/auth/CheckAuthorizationStatusTest.kt index 0281abe982..b85ebfbccd 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/auth/CheckAuthorizationStatusTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/auth/CheckAuthorizationStatusTest.kt @@ -1,13 +1,17 @@ package com.anytypeio.anytype.domain.auth +import com.anytypeio.anytype.core_models.Account +import com.anytypeio.anytype.core_models.CoroutineTestRule import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.domain.auth.model.AuthStatus import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.Either -import com.anytypeio.anytype.core_models.CoroutineTestRule import com.anytypeio.anytype.test_utils.MockDataFactory -import com.nhaarman.mockitokotlin2.* +import com.nhaarman.mockitokotlin2.doReturn +import com.nhaarman.mockitokotlin2.stub +import com.nhaarman.mockitokotlin2.times +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import org.junit.Before diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/auth/CreateAccountTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/auth/CreateAccountTest.kt index 66827f1fff..fe178980c1 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/auth/CreateAccountTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/auth/CreateAccountTest.kt @@ -1,11 +1,15 @@ package com.anytypeio.anytype.domain.auth -import com.anytypeio.anytype.domain.auth.interactor.CreateAccount -import com.anytypeio.anytype.domain.auth.model.Account -import com.anytypeio.anytype.domain.auth.repo.AuthRepository +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.core_models.CoroutineTestRule +import com.anytypeio.anytype.domain.auth.interactor.CreateAccount +import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.test_utils.MockDataFactory -import com.nhaarman.mockitokotlin2.* +import com.nhaarman.mockitokotlin2.doReturn +import com.nhaarman.mockitokotlin2.stub +import com.nhaarman.mockitokotlin2.times +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import org.junit.Before diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/auth/GetCurrentAccountTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/auth/GetCurrentAccountTest.kt deleted file mode 100644 index 067a879b32..0000000000 --- a/domain/src/test/java/com/anytypeio/anytype/domain/auth/GetCurrentAccountTest.kt +++ /dev/null @@ -1,181 +0,0 @@ -package com.anytypeio.anytype.domain.auth - -import com.anytypeio.anytype.domain.auth.interactor.GetCurrentAccount -import com.anytypeio.anytype.domain.auth.model.Account -import com.anytypeio.anytype.domain.base.BaseUseCase -import com.anytypeio.anytype.domain.base.Either -import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.domain.block.repo.BlockRepository -import com.anytypeio.anytype.core_models.Config -import com.anytypeio.anytype.domain.config.Gateway -import com.anytypeio.anytype.core_models.Event -import com.anytypeio.anytype.core_models.Payload -import com.anytypeio.anytype.domain.misc.UrlBuilder -import com.anytypeio.anytype.test_utils.MockDataFactory -import com.nhaarman.mockitokotlin2.doReturn -import com.nhaarman.mockitokotlin2.stub -import kotlinx.coroutines.runBlocking -import org.junit.Before -import org.junit.Test -import org.mockito.Mock -import org.mockito.MockitoAnnotations -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class GetCurrentAccountTest { - - @Mock lateinit var repo: BlockRepository - - @Mock - lateinit var gateway: Gateway - - lateinit var getCurrentAccount: GetCurrentAccount - - private val config = Config( - home = MockDataFactory.randomUuid(), - profile = MockDataFactory.randomUuid(), - gateway = MockDataFactory.randomString() - ) - - private val builder: UrlBuilder get() = UrlBuilder(gateway) - - @Before - fun before() { - MockitoAnnotations.initMocks(this) - getCurrentAccount = GetCurrentAccount( - repo = repo, - builder = builder - ) - } - - @Test - fun `should return error if payload contains no event`() { - - val context = MockDataFactory.randomUuid() - - stubGetConfig() - - stubOpenProfile(context = context) - - val result = runBlocking { - getCurrentAccount.invoke(BaseUseCase.None) - } - - assertTrue { result is Either.Left } - } - - @Test - fun `should create account object without avatar from data contained in details`() { - - val context = MockDataFactory.randomUuid() - - val name = MockDataFactory.randomString() - - stubGetConfig() - - stubOpenProfile( - context = context, - events = listOf( - Event.Command.ShowObject( - context = context, - details = Block.Details( - details = mapOf( - config.profile to Block.Fields( - mapOf( - "name" to name - ) - ) - ) - ), - blocks = emptyList(), - root = config.profile - ) - - ) - ) - - val result = runBlocking { - getCurrentAccount.invoke(BaseUseCase.None) - } - - val expected = Account( - id = config.profile, - name = name, - avatar = null, - color = null - ) - - assertEquals( - expected = Either.Right(expected), - actual = result - ) - } - - @Test - fun `should create account object with avatar from data contained in details`() { - - val context = MockDataFactory.randomUuid() - - val name = MockDataFactory.randomString() - - val avatar = MockDataFactory.randomString() - - stubGetConfig() - - stubOpenProfile( - context = context, - events = listOf( - Event.Command.ShowObject( - context = context, - details = Block.Details( - details = mapOf( - config.profile to Block.Fields( - mapOf( - "name" to name, - "iconImage" to avatar - ) - ) - ) - ), - blocks = emptyList(), - root = config.profile - ) - - ) - ) - - val result = runBlocking { - getCurrentAccount.invoke(BaseUseCase.None) - } - - val expected = Account( - id = config.profile, - name = name, - avatar = builder.image(avatar), - color = null - ) - - assertEquals( - expected = Either.Right(expected), - actual = result - ) - } - - private fun stubOpenProfile( - context: String, - events: List = emptyList() - ) { - repo.stub { - onBlocking { openProfile(config.profile) } doReturn Payload( - context = context, - events = events - ) - } - } - - private fun stubGetConfig() { - repo.stub { - onBlocking { getConfig() } doReturn config - } - } -} \ No newline at end of file diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/auth/ObserveAccountsTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/auth/ObserveAccountsTest.kt index a45c7bb7ef..09109470db 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/auth/ObserveAccountsTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/auth/ObserveAccountsTest.kt @@ -1,9 +1,9 @@ package com.anytypeio.anytype.domain.auth -import com.anytypeio.anytype.domain.auth.interactor.ObserveAccounts -import com.anytypeio.anytype.domain.auth.model.Account -import com.anytypeio.anytype.domain.auth.repo.AuthRepository +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.core_models.CoroutineTestRule +import com.anytypeio.anytype.domain.auth.interactor.ObserveAccounts +import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.test_utils.MockDataFactory import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.stub diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/auth/StartAccountTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/auth/StartAccountTest.kt index 9dff039761..b7211c52b2 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/auth/StartAccountTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/auth/StartAccountTest.kt @@ -1,15 +1,22 @@ package com.anytypeio.anytype.domain.auth +import com.anytypeio.anytype.core_models.Account +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus +import com.anytypeio.anytype.core_models.Config import com.anytypeio.anytype.core_models.CoroutineTestRule import com.anytypeio.anytype.core_models.FeaturesConfig import com.anytypeio.anytype.domain.auth.interactor.StartAccount -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.base.Either +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider import com.anytypeio.anytype.test_utils.MockDataFactory -import com.nhaarman.mockitokotlin2.* +import com.nhaarman.mockitokotlin2.doReturn +import com.nhaarman.mockitokotlin2.stub +import com.nhaarman.mockitokotlin2.times +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import org.junit.Before @@ -31,12 +38,25 @@ class StartAccountTest { @Mock lateinit var featuresConfigProvider: FeaturesConfigProvider + @Mock + lateinit var configStorage: ConfigStorage + lateinit var startAccount: StartAccount + val config = Config( + home = MockDataFactory.randomUuid(), + gateway = MockDataFactory.randomUuid(), + profile = MockDataFactory.randomUuid() + ) + @Before fun setup() { MockitoAnnotations.initMocks(this) - startAccount = StartAccount(repo, featuresConfigProvider) + startAccount = StartAccount( + repository = repo, + configStorage = configStorage, + featuresConfigProvider = featuresConfigProvider + ) } @Test @@ -57,7 +77,7 @@ class StartAccountTest { color = null ) - val config = FeaturesConfig( + val featuresConfig = FeaturesConfig( enableDataView = false, enableDebug = false, enableChannelSwitch = false @@ -69,7 +89,12 @@ class StartAccountTest { id = id, path = path ) - } doReturn Triple(account, config, AccountStatus.Active) + } doReturn AccountSetup( + account = account, + features = featuresConfig, + status = AccountStatus.Active, + config = config + ) } startAccount.run(params) @@ -104,7 +129,7 @@ class StartAccountTest { color = null ) - val config = FeaturesConfig( + val featuresConfig = FeaturesConfig( enableDataView = false, enableDebug = false, enableChannelSwitch = false @@ -116,7 +141,12 @@ class StartAccountTest { id = id, path = path ) - } doReturn Triple(account, config, AccountStatus.Active) + } doReturn AccountSetup( + account = account, + features = featuresConfig, + status = AccountStatus.Active, + config = config + ) } val result = startAccount.run(params) @@ -142,7 +172,7 @@ class StartAccountTest { color = null ) - val config = FeaturesConfig( + val featuresConfig = FeaturesConfig( enableDataView = null, enableDebug = null, enableChannelSwitch = null @@ -154,7 +184,12 @@ class StartAccountTest { id = id, path = path ) - } doReturn Triple(account, config, AccountStatus.Active) + } doReturn AccountSetup( + account = account, + features = featuresConfig, + status = AccountStatus.Active, + config = config + ) } val result = startAccount.run(params) @@ -187,7 +222,7 @@ class StartAccountTest { color = null ) - val config = FeaturesConfig( + val featuresConfig = FeaturesConfig( enableDataView = true, enableDebug = false, enableChannelSwitch = true @@ -199,7 +234,12 @@ class StartAccountTest { id = id, path = path ) - } doReturn Triple(account, config, AccountStatus.Active) + } doReturn AccountSetup( + account = account, + features = featuresConfig, + status = AccountStatus.Active, + config = config + ) } val result = startAccount.run(params) diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/GetProfileTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/GetProfileTest.kt index 3a3f07dee8..84f844d4a6 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/GetProfileTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/GetProfileTest.kt @@ -4,6 +4,7 @@ import app.cash.turbine.test import com.anytypeio.anytype.core_models.* import com.anytypeio.anytype.domain.auth.interactor.GetProfile import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.search.SubscriptionEventChannel import com.anytypeio.anytype.test_utils.MockDataFactory import com.nhaarman.mockitokotlin2.doReturn @@ -31,6 +32,9 @@ class GetProfileTest { @Mock lateinit var channel: SubscriptionEventChannel + @Mock + lateinit var configStorage: ConfigStorage + private lateinit var usecase: GetProfile val config = Config( @@ -44,7 +48,8 @@ class GetProfileTest { MockitoAnnotations.initMocks(this) usecase = GetProfile( repo = repo, - channel = channel + channel = channel, + provider = configStorage ) } @@ -60,8 +65,8 @@ class GetProfileTest { ) ) - repo.stub { - onBlocking { getConfig() } doReturn config + configStorage.stub { + onBlocking { get() } doReturn config } channel.stub { @@ -116,8 +121,8 @@ class GetProfileTest { ) ) - repo.stub { - onBlocking { getConfig() } doReturn config + configStorage.stub { + onBlocking { get() } doReturn config } channel.stub { @@ -185,8 +190,8 @@ class GetProfileTest { ) ) - repo.stub { - onBlocking { getConfig() } doReturn config + configStorage.stub { + onBlocking { get() } doReturn config } channel.stub { @@ -265,8 +270,8 @@ class GetProfileTest { ) ) - repo.stub { - onBlocking { getConfig() } doReturn config + configStorage.stub { + onBlocking { get() } doReturn config } channel.stub { diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/OpenDashboardTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/OpenDashboardTest.kt index 149f60820d..776636555a 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/OpenDashboardTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/dashboard/OpenDashboardTest.kt @@ -4,11 +4,13 @@ import com.anytypeio.anytype.domain.block.repo.BlockRepository import com.anytypeio.anytype.core_models.CoroutineTestRule import com.anytypeio.anytype.core_models.Config import com.anytypeio.anytype.domain.auth.repo.AuthRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.dashboard.interactor.OpenDashboard import com.anytypeio.anytype.test_utils.MockDataFactory import com.nhaarman.mockitokotlin2.* import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test @@ -27,17 +29,23 @@ class OpenDashboardTest { @Mock lateinit var auth: AuthRepository + @Mock + lateinit var configStorage: ConfigStorage + private lateinit var usecase: OpenDashboard @Before fun setup() { MockitoAnnotations.initMocks(this) - usecase = OpenDashboard(repo = repo, auth = auth) + usecase = OpenDashboard( + repo = repo, + auth = auth, + provider = configStorage + ) } @Test - fun `should open a dashboard based on the given params if these are present`() = - runBlockingTest { + fun `should open a dashboard based on the given params if these are present`() = runTest { val params = OpenDashboard.Param( contextId = MockDataFactory.randomUuid(), @@ -46,7 +54,7 @@ class OpenDashboardTest { usecase.run(params) - verify(repo, never()).getConfig() + verify(configStorage, never()).get() verify(repo, times(1)).openDashboard(contextId = params.contextId, id = params.id) verifyNoMoreInteractions(repo) } @@ -60,13 +68,13 @@ class OpenDashboardTest { profile = MockDataFactory.randomUuid() ) - repo.stub { - onBlocking { getConfig() } doReturn config + configStorage.stub { + onBlocking { get() } doReturn config } usecase.run(null) - verify(repo, times(1)).getConfig() + verify(configStorage, times(1)).get() verify(repo, times(1)).openDashboard( contextId = config.home, id = config.home diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/misc/UrlBuilderTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/misc/UrlBuilderTest.kt index 1b021bdb67..2e681f6639 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/misc/UrlBuilderTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/misc/UrlBuilderTest.kt @@ -25,7 +25,7 @@ class UrlBuilderTest { val hash = "image001" val expected = - gateway.obtain() + UrlBuilder.IMAGE_PATH + hash + UrlBuilder.DEFAULT_WIDTH_PARAM + gateway.provide() + UrlBuilder.IMAGE_PATH + hash + UrlBuilder.DEFAULT_WIDTH_PARAM val actual = urlBuilder.image(hash) assertEquals(expected, actual) } @@ -35,7 +35,7 @@ class UrlBuilderTest { val hash = null val expected = - gateway.obtain() + UrlBuilder.IMAGE_PATH + null + UrlBuilder.DEFAULT_WIDTH_PARAM + gateway.provide() + UrlBuilder.IMAGE_PATH + null + UrlBuilder.DEFAULT_WIDTH_PARAM val actual = urlBuilder.image(hash) assertEquals(expected, actual) } @@ -44,7 +44,7 @@ class UrlBuilderTest { fun `should return url without hash when image hash is empty`() { val hash = "" - val expected = gateway.obtain() + UrlBuilder.IMAGE_PATH + UrlBuilder.DEFAULT_WIDTH_PARAM + val expected = gateway.provide() + UrlBuilder.IMAGE_PATH + UrlBuilder.DEFAULT_WIDTH_PARAM val actual = urlBuilder.image(hash) assertEquals(expected, actual) } @@ -53,7 +53,7 @@ class UrlBuilderTest { fun `should return file url`() { val hash = "file001" - val expected = gateway.obtain() + UrlBuilder.FILE_PATH + hash + val expected = gateway.provide() + UrlBuilder.FILE_PATH + hash val actual = urlBuilder.file(hash) assertEquals(expected, actual) } @@ -62,7 +62,7 @@ class UrlBuilderTest { fun `should return url with null at the end when file hash is null`() { val hash = null - val expected = gateway.obtain() + UrlBuilder.FILE_PATH + null + val expected = gateway.provide() + UrlBuilder.FILE_PATH + null val actual = urlBuilder.file(hash) assertEquals(expected, actual) } @@ -71,7 +71,7 @@ class UrlBuilderTest { fun `should return url without hash when file hash is empty`() { val hash = "" - val expected = gateway.obtain() + UrlBuilder.FILE_PATH + val expected = gateway.provide() + UrlBuilder.FILE_PATH val actual = urlBuilder.file(hash) assertEquals(expected, actual) } @@ -80,7 +80,7 @@ class UrlBuilderTest { fun `should return video url`() { val hash = "video001" - val expected = gateway.obtain() + UrlBuilder.FILE_PATH + hash + val expected = gateway.provide() + UrlBuilder.FILE_PATH + hash val actual = urlBuilder.video(hash) assertEquals(expected, actual) } @@ -89,7 +89,7 @@ class UrlBuilderTest { fun `should return url with null at the end when video hash is null`() { val hash = null - val expected = gateway.obtain() + UrlBuilder.FILE_PATH + null + val expected = gateway.provide() + UrlBuilder.FILE_PATH + null val actual = urlBuilder.video(hash) assertEquals(expected, actual) } @@ -98,7 +98,7 @@ class UrlBuilderTest { fun `should return url without hash when video hash is empty`() { val hash = "" - val expected = gateway.obtain() + UrlBuilder.FILE_PATH + val expected = gateway.provide() + UrlBuilder.FILE_PATH val actual = urlBuilder.video(hash) assertEquals(expected, actual) } diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/UnsplashMiddleware.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/UnsplashMiddleware.kt index c7ae76d0c7..bb39227a31 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/UnsplashMiddleware.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/UnsplashMiddleware.kt @@ -1,7 +1,7 @@ package com.anytypeio.anytype.middleware -import anytype.Rpc -import anytype.Rpc.UnsplashSearch +import anytype.Rpc.Unsplash.Download +import anytype.Rpc.Unsplash.Search import com.anytypeio.anytype.core_models.Hash import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.UnsplashImage @@ -16,7 +16,7 @@ class UnsplashMiddleware( ) : UnsplashRemote { override fun search(query: String, limit: Int): List { - val request = UnsplashSearch.Request( + val request = Search.Request( query = query, limit = limit ).also { it.logRequest() } @@ -25,7 +25,7 @@ class UnsplashMiddleware( } override fun download(id: Id): Hash { - val request = Rpc.UnsplashDownload.Request(pictureId = id).also { it.logRequest() } + val request = Download.Request(pictureId = id).also { it.logRequest() } val response = service.unsplashDownload(request = request).also { it.logResponse() } return response.hash } diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMappers.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMappers.kt new file mode 100644 index 0000000000..631755532c --- /dev/null +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMappers.kt @@ -0,0 +1,40 @@ +package com.anytypeio.anytype.middleware.auth + +import anytype.Rpc +import com.anytypeio.anytype.core_models.Account +import com.anytypeio.anytype.core_models.AccountSetup +import com.anytypeio.anytype.core_models.Config +import com.anytypeio.anytype.core_models.FeaturesConfig +import com.anytypeio.anytype.middleware.mappers.core + +fun Rpc.Account.Select.Response.core(): AccountSetup { + val acc = account + checkNotNull(acc) { "Account can't be empty" } + val configuration = acc.config + checkNotNull(configuration) { "Config can't be empty" } + val info = acc.info + checkNotNull(info) { "Info can't be empty" } + val status = acc.status + checkNotNull(status) { "Status can't be empty" } + + return AccountSetup( + account = Account( + id = acc.id, + name = acc.name, + color = acc.avatar?.color, + avatar = null + ), + features = FeaturesConfig( + enableDataView = configuration.enableDataview, + enableDebug = configuration.enableDebug, + enableChannelSwitch = configuration.enableReleaseChannelSwitch, + enableSpaces = configuration.enableSpaces + ), + config = Config( + home = info.homeObjectId, + profile = info.profileObjectId, + gateway = info.gatewayUrl + ), + status = status.core() + ) +} \ No newline at end of file diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMiddleware.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMiddleware.kt index 50b340747f..f755e8e275 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMiddleware.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/auth/AuthMiddleware.kt @@ -1,5 +1,6 @@ package com.anytypeio.anytype.middleware.auth +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.data.auth.model.AccountEntity import com.anytypeio.anytype.data.auth.model.FeaturesConfigEntity @@ -21,30 +22,15 @@ class AuthMiddleware( ) : AuthRemote { override suspend fun startAccount( - id: String, - path: String - ): Triple { - val response = middleware.selectAccount(id, path) - val account = AccountEntity( - id = response.id, - name = response.name, - color = response.avatar?.color - ) - val featuresConfig = FeaturesConfigEntity( - enableDataView = response.enableDataView, - enableDebug = response.enableDebug, - enableChannelSwitch = response.enableChannelSwitch, - enableSpaces = response.enableSpaces - ) - return Triple(account, featuresConfig, response.accountStatus ?: AccountStatus.Unknown) - } + id: String, path: String + ): AccountSetup = middleware.accountSelect(id, path) override suspend fun createAccount( name: String, avatarPath: String?, invitationCode: String ) = withContext(Dispatchers.IO) { - middleware.createAccount(name, avatarPath, invitationCode).let { response -> + middleware.accountCreate(name, avatarPath, invitationCode).let { response -> AccountEntity( id = response.id, name = response.name, @@ -53,11 +39,11 @@ class AuthMiddleware( } } - override suspend fun deleteAccount(): AccountStatus = middleware.deleteAccount() - override suspend fun restoreAccount(): AccountStatus = middleware.restoreAccount() + override suspend fun deleteAccount(): AccountStatus = middleware.accountDelete() + override suspend fun restoreAccount(): AccountStatus = middleware.accountRestore() override suspend fun recoverAccount() = withContext(Dispatchers.IO) { - middleware.recoverAccount() + middleware.accountRecover() } override fun observeAccounts() = events @@ -81,19 +67,19 @@ class AuthMiddleware( override suspend fun createWallet( path: String - ) = WalletEntity(mnemonic = middleware.createWallet(path).mnemonic) + ) = WalletEntity(mnemonic = middleware.walletCreate(path).mnemonic) override suspend fun recoverWallet(path: String, mnemonic: String) { - middleware.recoverWallet(path, mnemonic) + middleware.walletRecover(path, mnemonic) } - override suspend fun convertWallet(entropy: String): String = middleware.convertWallet(entropy) + override suspend fun convertWallet(entropy: String): String = middleware.walletConvert(entropy) override suspend fun logout(clearLocalRepositoryData: Boolean) { - middleware.logout(clearLocalRepositoryData) + middleware.accountStop(clearLocalRepositoryData) } override suspend fun getVersion(): String { - return middleware.getMiddlewareVersion().version + return middleware.versionGet().version } } \ No newline at end of file diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt index 914682686c..697f2057b9 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt @@ -27,15 +27,13 @@ class BlockMiddleware( private val middleware: Middleware ) : BlockRemote { - override suspend fun getConfig(): Config = middleware.getConfig() - override suspend fun openDashboard( contextId: String, id: String - ): Payload = middleware.openDashboard(contextId, id) + ): Payload = middleware.dashboardOpen(contextId, id) override suspend fun closeDashboard(id: String) { - middleware.closeDashboard(id) + middleware.objectClose(id) } override suspend fun createPage( @@ -44,7 +42,7 @@ class BlockMiddleware( isDraft: Boolean?, type: String?, template: Id? - ): String = middleware.createPage( + ): String = middleware.blockLinkCreateWithObject( ctx = ctx, emoji = emoji, isDraft = isDraft, @@ -54,23 +52,23 @@ class BlockMiddleware( override suspend fun createPage( command: Command.CreateNewDocument - ): String = middleware.createPage(command) + ): String = middleware.objectCreate(command) - override suspend fun openPage(id: String): Payload = middleware.openBlock(id) - override suspend fun openProfile(id: String): Payload = middleware.openBlock(id) - override suspend fun openObjectSet(id: String): Payload = middleware.openBlock(id) - override suspend fun openObjectPreview(id: Id): Payload = middleware.showBlock(id) + override suspend fun openPage(id: String): Payload = middleware.objectOpen(id) + override suspend fun openProfile(id: String): Payload = middleware.objectOpen(id) + override suspend fun openObjectSet(id: String): Payload = middleware.objectOpen(id) + override suspend fun openObjectPreview(id: Id): Payload = middleware.objectShow(id) override suspend fun closePage(id: String) { - middleware.closePage(id) + middleware.objectClose(id) } override suspend fun updateDocumentTitle(command: Command.UpdateTitle) { - middleware.updateDocumentTitle(command) + middleware.objectSetTitle(command) } override suspend fun updateText(command: Command.UpdateText) { - middleware.updateText( + middleware.blockTextSetText( command.contextId, command.blockId, command.text, @@ -79,27 +77,27 @@ class BlockMiddleware( } override suspend fun uploadBlock(command: Command.UploadBlock): Payload = - middleware.uploadBlock(command) + middleware.blockUpload(command) override suspend fun updateTextStyle( command: Command.UpdateStyle - ): Payload = middleware.updateTextStyle(command) + ): Payload = middleware.blockTextListSetStyle(command) override suspend fun updateTextColor( command: Command.UpdateTextColor - ): Payload = middleware.updateTextColor(command) + ): Payload = middleware.blockTextListSetColor(command) override suspend fun updateBackgroundColor( command: Command.UpdateBackgroundColor - ): Payload = middleware.updateBackgroundColor(command) + ): Payload = middleware.blockListSetBackgroundColor(command) override suspend fun updateAlignment( command: Command.UpdateAlignment - ): Payload = middleware.updateAlignment(command) + ): Payload = middleware.blockListSetAlign(command) override suspend fun updateCheckbox( command: Command.UpdateCheckbox - ): Payload = middleware.updateCheckbox( + ): Payload = middleware.blockTextSetChecked( command.context, command.target, command.isChecked @@ -107,7 +105,7 @@ class BlockMiddleware( override suspend fun create( command: Command.Create - ): Pair = middleware.createBlock( + ): Pair = middleware.blockCreate( command.context, command.target, command.position, @@ -116,119 +114,119 @@ class BlockMiddleware( override suspend fun createDocument( command: Command.CreateDocument - ): Triple = middleware.createDocument(command) + ): Triple = middleware.blockLinkCreateWithObject(command) override suspend fun duplicate( command: Command.Duplicate - ): Pair, Payload> = middleware.duplicate(command) + ): Pair, Payload> = middleware.blockListDuplicate(command) override suspend fun duplicateObject(id: Id) = middleware.objectDuplicate(id) override suspend fun move(command: Command.Move): Payload { - return middleware.move(command) + return middleware.blockListMoveToExistingObject(command) } override suspend fun unlink( command: Command.Unlink - ): Payload = middleware.unlink(command) + ): Payload = middleware.blockListDelete(command) override suspend fun merge( command: Command.Merge - ): Payload = middleware.merge(command) + ): Payload = middleware.blockMerge(command) override suspend fun split( command: Command.Split - ): Pair = middleware.split(command) + ): Pair = middleware.blockSplit(command) override suspend fun setDocumentEmojiIcon( command: Command.SetDocumentEmojiIcon - ): Payload = middleware.setDocumentEmojiIcon(command) + ): Payload = middleware.objectSetEmojiIcon(command) override suspend fun setDocumentImageIcon( command: Command.SetDocumentImageIcon - ): Payload = middleware.setDocumentImageIcon(command) + ): Payload = middleware.objectSetImageIcon(command) override suspend fun setDocumentCoverColor( ctx: String, color: String - ): Payload = middleware.setDocumentCoverColor(ctx = ctx, color = color) + ): Payload = middleware.objectSetCoverColor(ctx = ctx, color = color) override suspend fun setDocumentCoverGradient( ctx: String, gradient: String - ): Payload = middleware.setDocumentCoverGradient(ctx = ctx, gradient = gradient) + ): Payload = middleware.objectSetCoverGradient(ctx = ctx, gradient = gradient) override suspend fun setDocumentCoverImage( ctx: String, hash: String - ): Payload = middleware.setDocumentCoverImage(ctx = ctx, hash = hash) + ): Payload = middleware.objectSetCoverImage(ctx = ctx, hash = hash) override suspend fun removeDocumentCover( ctx: String - ): Payload = middleware.removeDocumentCover(ctx) + ): Payload = middleware.objectRemoveCover(ctx) override suspend fun removeDocumentIcon( ctx: Id - ): Payload = middleware.removeDocumentIcon(ctx) + ): Payload = middleware.objectRemoveIcon(ctx) override suspend fun setupBookmark( command: Command.SetupBookmark - ): Payload = middleware.setupBookmark(command) + ): Payload = middleware.blockBookmarkFetch(command) override suspend fun createBookmark( command: Command.CreateBookmark - ): Payload = middleware.createAndSetupBookmark(command) + ): Payload = middleware.blockBookmarkCreateAndFetch(command) override suspend fun undo( command: Command.Undo - ): Payload = middleware.undo(command) + ): Payload = middleware.objectUndo(command) override suspend fun redo( command: Command.Redo - ): Payload = middleware.redo(command) + ): Payload = middleware.objectRedo(command) override suspend fun turnIntoDocument( command: Command.TurnIntoDocument - ): List = middleware.turnIntoDocument(command) + ): List = middleware.blockListMoveToNewObject(command) override suspend fun replace( command: Command.Replace - ): Pair = middleware.replace(command) + ): Pair = middleware.blockReplace(command) override suspend fun paste( command: Command.Paste - ): Response.Clipboard.Paste = middleware.paste(command) + ): Response.Clipboard.Paste = middleware.blockPaste(command) override suspend fun copy( command: Command.Copy - ): Response.Clipboard.Copy = middleware.copy(command) + ): Response.Clipboard.Copy = middleware.blockCopy(command) override suspend fun uploadFile( command: Command.UploadFile - ): String = middleware.uploadFile(command).hash + ): String = middleware.fileUpload(command).hash override suspend fun getObjectInfoWithLinks(pageId: String): ObjectInfoWithLinks { - return middleware.getObjectInfoWithLinks(pageId).toCoreModel() + return middleware.navigationGetObjectInfoWithLinks(pageId).toCoreModel() } override suspend fun getListPages(): List { - return middleware.listObjects().map { it.toCoreModel() } + return middleware.navigationListObjects().map { it.toCoreModel() } } override suspend fun setRelationKey(command: Command.SetRelationKey): Payload { - return middleware.setRelationKey(command) + return middleware.blockRelationSetKey(command) } override suspend fun updateDivider( command: Command.UpdateDivider - ): Payload = middleware.updateDividerStyle(command) + ): Payload = middleware.blockListSetDivStyle(command) override suspend fun setFields( command: Command.SetFields - ): Payload = middleware.setFields(command) + ): Payload = middleware.blockListSetFields(command) override suspend fun getObjectTypes(): List { - return middleware.getObjectTypes().map { it.toCoreModels() } + return middleware.objectTypeList().map { it.toCoreModels() } } override suspend fun createObjectType( @@ -240,7 +238,7 @@ class BlockMiddleware( targetId: String?, position: Position?, objectType: String? - ): Response.Set.Create = middleware.createSet( + ): Response.Set.Create = middleware.objectCreateSet( contextId = contextId, targetId = targetId, position = position, @@ -253,7 +251,7 @@ class BlockMiddleware( view: String, offset: Int, limit: Int - ): Payload = middleware.setActiveDataViewViewer( + ): Payload = middleware.blockDataViewActiveSet( contextId = context, blockId = block, viewId = view, @@ -267,7 +265,7 @@ class BlockMiddleware( name: String, format: Relation.Format, limitObjectTypes: List - ): Pair = middleware.addNewRelationToDataView( + ): Pair = middleware.blockDataViewRelationAdd( context = context, target = target, format = format, @@ -279,7 +277,7 @@ class BlockMiddleware( ctx: Id, dv: Id, relation: Id - ): Payload = middleware.addRelationToDataView( + ): Payload = middleware.blockDataViewRelationAdd( ctx = ctx, dv = dv, relation = relation @@ -289,7 +287,7 @@ class BlockMiddleware( ctx: Id, dv: Id, relation: Id - ): Payload = middleware.deleteRelationFromDataView( + ): Payload = middleware.blockDataViewRelationDelete( ctx = ctx, dv = dv, relation = relation @@ -299,7 +297,7 @@ class BlockMiddleware( context: String, target: String, viewer: DVViewer - ): Payload = middleware.updateDataViewViewer( + ): Payload = middleware.blockDataViewViewUpdate( context = context, target = target, viewer = viewer @@ -309,7 +307,7 @@ class BlockMiddleware( context: String, target: String, viewer: DVViewer - ): Payload = middleware.duplicateDataViewViewer( + ): Payload = middleware.blockDataViewViewCreate( context = context, target = target, viewer = viewer @@ -319,7 +317,7 @@ class BlockMiddleware( context: String, target: String, template: Id? - ): Map = middleware.createDataViewRecord( + ): Map = middleware.blockDataViewRecordCreate( context = context, target = target, template = template @@ -330,7 +328,7 @@ class BlockMiddleware( target: String, record: String, values: Map - ) = middleware.updateDataViewRecord( + ) = middleware.blockDataViewRecordUpdate( context = context, target = target, record = record, @@ -342,7 +340,7 @@ class BlockMiddleware( target: String, name: String, type: DVViewerType - ): Payload = middleware.addDataViewViewer( + ): Payload = middleware.blockDataViewViewCreate( ctx = ctx, target = target, name = name, @@ -353,7 +351,7 @@ class BlockMiddleware( ctx: String, dataview: String, viewer: String - ): Payload = middleware.removeDataViewViewer( + ): Payload = middleware.blockDataViewViewDelete( ctx = ctx, dataview = dataview, viewer = viewer @@ -366,7 +364,7 @@ class BlockMiddleware( record: Id, name: String, color: String - ): Pair = middleware.addRecordRelationOption( + ): Pair = middleware.blockDataViewRecordRelationOptionAdd( ctx = ctx, dataview = dataview, relation = relation, @@ -380,7 +378,7 @@ class BlockMiddleware( relation: Id, name: Id, color: String - ): Pair = middleware.addObjectRelationOption( + ): Pair = middleware.objectRelationOptionAdd( ctx = ctx, relation = relation, name = name, @@ -394,7 +392,7 @@ class BlockMiddleware( offset: Int, limit: Int, keys: List - ): List> = middleware.searchObjects( + ): List> = middleware.objectSearch( sorts = sorts, filters = filters, fulltext = fulltext, @@ -412,7 +410,7 @@ class BlockMiddleware( limit: Long, beforeId: Id?, afterId: Id? - ): SearchResult = middleware.searchObjectsWithSubscription( + ): SearchResult = middleware.objectSearchSubscribe( subscription = subscription, sorts = sorts, filters = filters, @@ -427,7 +425,7 @@ class BlockMiddleware( subscription: Id, ids: List, keys: List - ): SearchResult = middleware.searchObjectsByIdWithSubscription( + ): SearchResult = middleware.objectIdsSubscribe( subscription = subscription, ids = ids, keys = keys @@ -435,22 +433,22 @@ class BlockMiddleware( override suspend fun cancelObjectSearchSubscription( subscriptions: List - ) = middleware.cancelObjectSearchSubscription(subscriptions = subscriptions) + ) = middleware.objectSearchUnsubscribe(subscriptions = subscriptions) override suspend fun relationListAvailable( ctx: Id - ): List = middleware.relationListAvailable(ctx).map { it.toCoreModels() } + ): List = middleware.objectRelationListAvailable(ctx).map { it.toCoreModels() } override suspend fun addRelationToObject( ctx: Id, relation: Id - ) : Payload = middleware.addRelationToObject(ctx, relation) + ) : Payload = middleware.objectRelationAdd(ctx, relation) override suspend fun addNewRelationToObject( ctx: Id, name: String, format: RelationFormat, limitObjectTypes: List - ): Pair = middleware.addNewRelationToObject( + ): Pair = middleware.objectRelationAdd( ctx = ctx, format = format, name = name, @@ -460,13 +458,13 @@ class BlockMiddleware( override suspend fun deleteRelationFromObject( ctx: Id, relation: Id - ): Payload = middleware.deleteRelationFromObject( + ): Payload = middleware.objectRelationDelete( ctx = ctx, relation = relation ) override suspend fun debugSync(): String = middleware.debugSync() - override suspend fun debugLocalStore(path: String): String = middleware.exportLocalStore(path) + override suspend fun debugLocalStore(path: String): String = middleware.debugExportLocalStore(path) override suspend fun turnInto( context: String, @@ -482,59 +480,59 @@ class BlockMiddleware( ctx: Id, key: String, value: Any? - ): Payload = middleware.updateDetail( + ): Payload = middleware.objectSetDetails( ctx = ctx, key = key, value = value ) override suspend fun updateBlocksMark(command: Command.UpdateBlocksMark): Payload = - middleware.blockListSetTextMarkup(command) + middleware.blockTextListSetMark(command) override suspend fun addRelationToBlock(command: Command.AddRelationToBlock): Payload = - middleware.addRelationToBlock(command) + middleware.blockRelationAdd(command) override suspend fun setObjectTypeToObject(ctx: Id, typeId: Id): Payload = - middleware.setObjectType(ctx = ctx, typeId = typeId) + middleware.objectSetObjectType(ctx = ctx, typeId = typeId) override suspend fun addToFeaturedRelations( ctx: Id, relations: List - ): Payload = middleware.addToFeaturedRelations(ctx, relations) + ): Payload = middleware.objectRelationAddFeatured(ctx, relations) override suspend fun removeFromFeaturedRelations( ctx: Id, relations: List - ): Payload = middleware.removeFromFeaturedRelations(ctx, relations) + ): Payload = middleware.objectRelationRemoveFeatured(ctx, relations) override suspend fun setObjectIsFavorite( ctx: Id, isFavorite: Boolean - ): Payload = middleware.setObjectIsFavorite(ctx = ctx, isFavorite = isFavorite) + ): Payload = middleware.objectSetIsFavorite(ctx = ctx, isFavorite = isFavorite) override suspend fun setObjectIsArchived( ctx: Id, isArchived: Boolean - ): Payload = middleware.setObjectIsArchived(ctx = ctx, isArchived = isArchived) + ): Payload = middleware.objectSetIsArchived(ctx = ctx, isArchived = isArchived) - override suspend fun deleteObjects(targets: List) = middleware.deleteObjects( + override suspend fun deleteObjects(targets: List) = middleware.objectListDelete( targets = targets ) override suspend fun setObjectListIsArchived( targets: List, isArchived: Boolean - ) = middleware.setObjectListIsArchived( + ) = middleware.objectListSetIsArchived( targets = targets, isArchived = isArchived ) override suspend fun setObjectLayout(ctx: Id, layout: ObjectType.Layout) : Payload = - middleware.setObjectLayout(ctx, layout) + middleware.objectSetLayout(ctx, layout) override suspend fun clearFileCache() = middleware.fileListOffload() - override suspend fun applyTemplate(ctx: Id, template: Id) = middleware.applyTemplate( + override suspend fun applyTemplate(ctx: Id, template: Id) = middleware.objectApplyTemplate( ctx = ctx, template = template ) diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/config/DefaultConfigurator.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/config/DefaultConfigurator.kt deleted file mode 100644 index 79b505b4cc..0000000000 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/config/DefaultConfigurator.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.anytypeio.anytype.middleware.config - -import anytype.Rpc.Config -import com.anytypeio.anytype.data.auth.repo.config.Configurator -import service.Service - -typealias CoreConfig = com.anytypeio.anytype.core_models.Config -/** - * Obtains middleware configuration data. - */ -class DefaultConfigurator : Configurator { - - override fun configure() = get() - - private val builder: () -> CoreConfig = { - fetchConfig().let { response -> - CoreConfig( - home = response.homeBlockId, - gateway = response.gatewayUrl, - profile = response.profileBlockId - ) - } - } - - private var instance: CoreConfig? = null - - fun get() = instance ?: builder().also { instance = it } - - fun new() = builder().also { instance = it } - - override fun release() { - instance = null - } - - private fun fetchConfig(): Config.Get.Response { - val request = Config.Get.Request() - val encoded = Service.configGet(Config.Get.Request.ADAPTER.encode(request)) - val response = Config.Get.Response.ADAPTER.decode(encoded) - return parseResponse(response) - } - - private fun parseResponse(response: Config.Get.Response): Config.Get.Response { - val error = response.error - return if (error != null && error.code != Config.Get.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - response - } - } -} \ No newline at end of file diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt index 5d245fee18..1aea2a2114 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt @@ -1,12 +1,11 @@ package com.anytypeio.anytype.middleware.interactor import anytype.Rpc -import anytype.Rpc.BlockList -import anytype.Rpc.BlockList.Set.Fields.Request.BlockField import anytype.model.Block import anytype.model.ObjectInfo import anytype.model.ObjectInfoWithLinks import anytype.model.Range +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus import com.anytypeio.anytype.core_models.CBTextStyle import com.anytypeio.anytype.core_models.Command @@ -22,9 +21,11 @@ import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.Position import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.core_models.RelationFormat +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.Response import com.anytypeio.anytype.core_models.SearchResult import com.anytypeio.anytype.middleware.BuildConfig +import com.anytypeio.anytype.middleware.auth.core import com.anytypeio.anytype.middleware.const.Constants import com.anytypeio.anytype.middleware.mappers.MObjectType import com.anytypeio.anytype.middleware.mappers.MRelation @@ -35,7 +36,6 @@ import com.anytypeio.anytype.middleware.mappers.toMiddlewareModel import com.anytypeio.anytype.middleware.mappers.toPayload import com.anytypeio.anytype.middleware.model.CreateAccountResponse import com.anytypeio.anytype.middleware.model.CreateWalletResponse -import com.anytypeio.anytype.middleware.model.SelectAccountResponse import com.anytypeio.anytype.middleware.service.MiddlewareService import timber.log.Timber @@ -43,49 +43,9 @@ class Middleware( private val service: MiddlewareService, private val factory: MiddlewareFactory ) { - private val iconEmojiKey = "iconEmoji" - private val iconImageKey = "iconImage" - private val coverIdKey = "coverId" - private val coverTypeKey = "coverType" - private val nameKey = "name" - private val typeKey = "type" - private val layoutKey = "layout" - private val isDraftKey = "isDraft" @Throws(Exception::class) - fun getConfig(): Config { - - val request = Rpc.Config.Get.Request() - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.configGet(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return Config( - home = response.homeBlockId, - profile = response.profileBlockId, - gateway = response.gatewayUrl - ) - } - - @Throws(Exception::class) - fun createWallet(path: String): CreateWalletResponse { - - val request = Rpc.Wallet.Create.Request(rootPath = path) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.walletCreate(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return CreateWalletResponse(response.mnemonic) - } - - @Throws(Exception::class) - fun createAccount( + fun accountCreate( name: String, path: String?, invitationCode: String @@ -115,7 +75,7 @@ class Middleware( } @Throws(Exception::class) - fun deleteAccount() : AccountStatus { + fun accountDelete() : AccountStatus { val request = Rpc.Account.Delete.Request( revert = false ) @@ -128,7 +88,15 @@ class Middleware( } @Throws(Exception::class) - fun restoreAccount() : AccountStatus { + fun accountRecover() { + val request = Rpc.Account.Recover.Request() + if (BuildConfig.DEBUG) logRequest(request) + val response = service.accountRecover(request) + if (BuildConfig.DEBUG) logResponse(response) + } + + @Throws(Exception::class) + fun accountRestore() : AccountStatus { val request = Rpc.Account.Delete.Request( revert = true ) @@ -141,28 +109,19 @@ class Middleware( } @Throws(Exception::class) - fun recoverWallet(path: String, mnemonic: String) { - val request = Rpc.Wallet.Recover.Request( - mnemonic = mnemonic, + fun accountSelect(id: String, path: String): AccountSetup { + val request = Rpc.Account.Select.Request( + id = id, rootPath = path ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.walletRecover(request) + val response = service.accountSelect(request) if (BuildConfig.DEBUG) logResponse(response) + return response.core() } @Throws(Exception::class) - fun convertWallet(entropy: String): String { - val request = Rpc.Wallet.Convert.Request(entropy = entropy) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.walletConvert(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.mnemonic - } - - @Throws(Exception::class) - fun logout(clearLocalRepositoryData: Boolean) { + fun accountStop(clearLocalRepositoryData: Boolean) { val request: Rpc.Account.Stop.Request = Rpc.Account.Stop.Request( removeData = clearLocalRepositoryData ) @@ -172,269 +131,58 @@ class Middleware( } @Throws(Exception::class) - fun recoverAccount() { - val request = Rpc.Account.Recover.Request() - if (BuildConfig.DEBUG) logRequest(request) - val response = service.accountRecover(request) - if (BuildConfig.DEBUG) logResponse(response) - } - - @Throws(Exception::class) - fun selectAccount(id: String, path: String): SelectAccountResponse { - - val request = Rpc.Account.Select.Request( - id = id, - rootPath = path - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.accountSelect(request) - - if (BuildConfig.DEBUG) logResponse(response) - - val acc = response.account - val config = response.config - - checkNotNull(acc) - - return SelectAccountResponse( - id = acc.id, - name = acc.name, - avatar = acc.avatar, - enableDataView = config?.enableDataview, - enableDebug = config?.enableDebug, - enableChannelSwitch = config?.enableReleaseChannelSwitch, - enableSpaces = config?.enableSpaces, - accountStatus = acc.status?.core() - ) - } - - @Throws(Exception::class) - fun openDashboard(contextId: String, id: String): Payload { - val request: Rpc.Block.Open.Request = Rpc.Block.Open.Request( - contextId = contextId, - blockId = id - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockOpen(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun openBlock(id: String): Payload { - val request = Rpc.Block.Open.Request(blockId = id) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockOpen(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun showBlock(id: String): Payload { - val request = Rpc.Block.Show.Request(blockId = id) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockShow(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun createPage( - ctx: Id?, - emoji: String?, - isDraft: Boolean?, - type: String?, - template: Id? - ): Id { - - val details: MutableMap = mutableMapOf() - emoji?.let { details[iconEmojiKey] = it } - isDraft?.let { details[isDraftKey] = it } - type?.let { details[typeKey] = it } - - val request = Rpc.Block.CreatePage.Request( - contextId = ctx.orEmpty(), - details = details, - position = Block.Position.Inner, - templateId = template.orEmpty() - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockCreatePage(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return response.targetId - } - - @Throws(Exception::class) - fun closePage(id: String) { - val request = Rpc.Block.Close.Request(blockId = id) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockClose(request) - if (BuildConfig.DEBUG) logResponse(response) - } - - @Throws(Exception::class) - fun closeDashboard(id: String) { - val request = Rpc.Block.Close.Request(blockId = id) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockClose(request) - if (BuildConfig.DEBUG) logResponse(response) - } - - @Throws(Exception::class) - fun updateDocumentTitle(command: Command.UpdateTitle) { - - val detail = Rpc.Block.Set.Details.Detail( - key = nameKey, - value_ = command.title - ) - - val request = Rpc.Block.Set.Details.Request( + fun blockBookmarkCreateAndFetch(command: Command.CreateBookmark): Payload { + val request = Rpc.BlockBookmark.CreateAndFetch.Request( contextId = command.context, - details = listOf(detail) - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockSetDetails(request) - - if (BuildConfig.DEBUG) logResponse(response) - } - - @Throws(Exception::class) - fun updateText( - contextId: String, - blockId: String, - text: String, - marks: List - ) { - val markup: Block.Content.Text.Marks = Block.Content.Text.Marks(marks) - - val request = Rpc.Block.Set.Text.TText.Request( - contextId = contextId, - blockId = blockId, - text = text, - marks = markup - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockSetTextText(request) - - if (BuildConfig.DEBUG) logResponse(response) - } - - @Throws(Exception::class) - fun updateCheckbox( - context: String, - target: String, - isChecked: Boolean - ): Payload { - val request = Rpc.Block.Set.Text.Checked.Request( - contextId = context, - blockId = target, - checked = isChecked - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetTextChecked(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun updateTextStyle(command: Command.UpdateStyle): Payload { - - val style = command.style.toMiddlewareModel() - - val request: BlockList.Set.Text.Style.Request = BlockList.Set.Text.Style.Request( - style = style, - blockIds = command.targets, - contextId = command.context - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockListSetTextStyle(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun updateTextColor(command: Command.UpdateTextColor): Payload { - val request = BlockList.Set.Text.Color.Request( - contextId = command.context, - color = command.color, - blockIds = command.targets - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetTextColor(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun updateBackgroundColor(command: Command.UpdateBackgroundColor): Payload { - val request = BlockList.Set.BackgroundColor.Request( - contextId = command.context, - blockIds = command.targets, - color = command.color - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockListSetBackgroundColor(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun updateAlignment(command: Command.UpdateAlignment): Payload { - - val align: Block.Align = command.alignment.toMiddlewareModel() - - val request = BlockList.Set.Align.Request( - contextId = command.context, - blockIds = command.targets, - align = align - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockListSetAlign(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun uploadBlock(command: Command.UploadBlock): Payload { - val request = Rpc.Block.Upload.Request( - filePath = command.filePath, + targetId = command.target, url = command.url, - contextId = command.contextId, - blockId = command.blockId + position = command.position.toMiddlewareModel() ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockUpload(request) + val response = service.blockBookmarkCreateAndFetch(request) if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() } @Throws(Exception::class) - fun createBlock( + fun blockBookmarkFetch(command: Command.SetupBookmark): Payload { + val request = Rpc.BlockBookmark.Fetch.Request( + contextId = command.context, + blockId = command.target, + url = command.url + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockBookmarkFetch(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockCopy(command: Command.Copy): Response.Clipboard.Copy { + val range: Range? = command.range?.let { + Range( + from = it.first, + to = it.last + ) + } + val blocks: List = command.blocks.map { it.toMiddlewareModel() } + val request = Rpc.Block.Copy.Request( + contextId = command.context, + selectedTextRange = range, + blocks = blocks + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockCopy(request) + if (BuildConfig.DEBUG) logResponse(response) + return Response.Clipboard.Copy( + response.textSlot, + response.htmlSlot, + response.anySlot.toCoreModels() + ) + } + + @Throws(Exception::class) + fun blockCreate( contextId: String, targetId: String, position: Position, @@ -454,7 +202,484 @@ class Middleware( } @Throws(Exception::class) - fun replace(command: Command.Replace): Pair { + fun blockDataViewActiveSet( + contextId: String, + blockId: String, + viewId: String, + offset: Int, + limit: Int + ): Payload { + val request = Rpc.BlockDataview.View.SetActive.Request( + contextId = contextId, + blockId = blockId, + viewId = viewId, + offset = offset, + limit = limit + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewActiveSet(request) + if (BuildConfig.DEBUG) logResponse(response) + + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockDataViewRecordCreate( + context: String, + target: String, + template: Id? + ): Map { + val request = Rpc.BlockDataviewRecord.Create.Request( + contextId = context, + blockId = target, + templateId = template.orEmpty() + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewRecordCreate(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.record?.toMap() ?: emptyMap() + } + + @Throws(Exception::class) + fun blockDataViewRecordRelationOptionAdd( + ctx: Id, + dataview: Id, + relation: Id, + record: Id, + name: String, + color: String + ): Pair { + val request = Rpc.BlockDataviewRecord.RelationOption.Add.Request( + contextId = ctx, + blockId = dataview, + relationKey = relation, + recordId = record, + option = MRelationOption(text = name, color = color) + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewRecordRelationOptionAdd(request) + val option = response.option?.id + if (BuildConfig.DEBUG) logResponse(response) + return Pair(response.event.toPayload(), option) + } + + @Throws(Exception::class) + fun blockDataViewRecordUpdate( + context: String, + target: String, + record: String, + values: Map + ) { + val request = Rpc.BlockDataviewRecord.Update.Request( + contextId = context, + blockId = target, + recordId = record, + record = values + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewRecordUpdate(request) + if (BuildConfig.DEBUG) logResponse(response) + } + + @Throws(Exception::class) + fun blockDataViewRelationAdd( + context: String, + target: String, + name: String, + format: Relation.Format, + limitObjectTypes: List + ): Pair { + val relation = MRelation( + name = name, + format = format.toMiddlewareModel(), + objectTypes = limitObjectTypes + ) + val request = Rpc.BlockDataview.Relation.Add.Request( + contextId = context, + blockId = target, + relation = relation + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewRelationAdd(request) + if (BuildConfig.DEBUG) logResponse(response) + return Pair(response.relationKey, response.event.toPayload()) + } + + @Throws(Exception::class) + fun blockDataViewRelationAdd(ctx: Id, dv: Id, relation: Id): Payload { + val request = Rpc.BlockDataview.Relation.Add.Request( + contextId = ctx, + blockId = dv, + relation = MRelation( + key = relation + ) + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewRelationAdd(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockDataViewRelationDelete(ctx: Id, dv: Id, relation: Id): Payload { + val request = Rpc.BlockDataview.Relation.Delete.Request( + contextId = ctx, + blockId = dv, + relationKey = relation + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewRelationDelete(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockDataViewViewCreate( + ctx: String, + target: String, + name: String, + type: DVViewerType + ): Payload { + val request = Rpc.BlockDataview.View.Create.Request( + contextId = ctx, + blockId = target, + view = Block.Content.Dataview.View( + name = name, + type = type.toMiddlewareModel() + ) + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewViewCreate(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockDataViewViewCreate( + context: String, + target: String, + viewer: DVViewer + ): Payload { + val request = Rpc.BlockDataview.View.Create.Request( + contextId = context, + blockId = target, + view = viewer.toMiddlewareModel() + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewViewCreate(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockDataViewViewDelete( + ctx: String, + dataview: String, + viewer: String + ): Payload { + val request = Rpc.BlockDataview.View.Delete.Request( + contextId = ctx, + blockId = dataview, + viewId = viewer + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewViewDelete(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockDataViewViewUpdate( + context: String, + target: String, + viewer: DVViewer + ): Payload { + val request = Rpc.BlockDataview.View.Update.Request( + contextId = context, + blockId = target, + viewId = viewer.id, + view = viewer.toMiddlewareModel() + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockDataViewViewUpdate(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockLinkCreateWithObject( + ctx: Id?, + emoji: String?, + isDraft: Boolean?, + type: String?, + template: Id? + ): Id { + val details: MutableMap = mutableMapOf() + emoji?.let { details[Relations.ICON_EMOJI] = it } + isDraft?.let { details[Relations.IS_DRAFT] = it } + type?.let { details[Relations.TYPE] = it } + + val request = Rpc.BlockLink.CreateWithObject.Request( + contextId = ctx.orEmpty(), + details = details, + position = Block.Position.Inner, + templateId = template.orEmpty() + ) + + if (BuildConfig.DEBUG) logRequest(request) + + val response = service.blockLinkCreateWithObject(request) + + if (BuildConfig.DEBUG) logResponse(response) + + return response.targetId + } + + @Throws(Exception::class) + fun blockLinkCreateWithObject(command: Command.CreateDocument): Triple { + + val details: MutableMap = mutableMapOf() + + command.emoji?.let { details[Relations.ICON_EMOJI] = it } + command.type?.let { details[Relations.TYPE] = it } + command.layout?.let { details[Relations.LAYOUT] = it.toMiddlewareModel().value.toDouble() } + + val position: Block.Position = command.position.toMiddlewareModel() + + val request = Rpc.BlockLink.CreateWithObject.Request( + contextId = command.context, + targetId = command.target, + position = position, + details = details, + templateId = command.template.orEmpty() + ) + + if (BuildConfig.DEBUG) logRequest(request) + + val response = service.blockLinkCreateWithObject(request) + + if (BuildConfig.DEBUG) logResponse(response) + + return Triple( + response.blockId, + response.targetId, + response.event.toPayload() + ) + } + + @Throws(Exception::class) + fun blockListDelete(command: Command.Unlink): Payload { + val request = Rpc.Block.ListDelete.Request( + contextId = command.context, + blockIds = command.targets + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListDelete(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockListDuplicate(command: Command.Duplicate): Pair, Payload> { + val request = Rpc.Block.ListDuplicate.Request( + contextId = command.context, + targetId = command.target, + blockIds = command.blocks, + position = Block.Position.Bottom + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListDuplicate(request) + if (BuildConfig.DEBUG) logResponse(response) + + return Pair(response.blockIds, response.event.toPayload()) + } + + @Throws(Exception::class) + fun blockListMoveToExistingObject(command: Command.Move): Payload { + val position: Block.Position = command.position.toMiddlewareModel() + + val request = Rpc.Block.ListMoveToExistingObject.Request( + contextId = command.ctx, + targetContextId = command.targetContextId, + position = position, + blockIds = command.blockIds, + dropTargetId = command.targetId + ) + + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListMoveToExistingObject(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockListMoveToNewObject(command: Command.TurnIntoDocument): List { + val request = Rpc.Block.ListMoveToNewObject.Request( + contextId = command.context, + blockIds = command.targets + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListMoveToNewObject(request) + if (BuildConfig.DEBUG) logResponse(response) + return listOf(response.linkId) + } + + @Throws(Exception::class) + fun blockListSetAlign(command: Command.UpdateAlignment): Payload { + + val align: Block.Align = command.alignment.toMiddlewareModel() + + val request = Rpc.Block.ListSetAlign.Request( + contextId = command.context, + blockIds = command.targets, + align = align + ) + + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListSetAlign(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockListSetBackgroundColor(command: Command.UpdateBackgroundColor): Payload { + val request = Rpc.Block.ListSetBackgroundColor.Request( + contextId = command.context, + blockIds = command.targets, + color = command.color + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListSetBackgroundColor(request) + if (BuildConfig.DEBUG) logResponse(response) + + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockListSetDivStyle(command: Command.UpdateDivider): Payload { + val style = command.style.toMiddlewareModel() + val request = Rpc.BlockDiv.ListSetStyle.Request( + contextId = command.context, + blockIds = command.targets, + style = style + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListSetDivStyle(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockListSetFields(command: Command.SetFields): Payload { + val fields: MutableList = ArrayList() + for (i in command.fields.indices) { + val (first, second) = command.fields[i] + val field = Rpc.Block.ListSetFields.Request.BlockField( + blockId = first, + fields = second.map + ) + fields.add(field) + } + val request = Rpc.Block.ListSetFields.Request( + contextId = command.context, + blockFields = fields + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListSetFields(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockListTurnInto( + context: String, + targets: List, + style: CBTextStyle + ): Payload { + val request = Rpc.Block.ListTurnInto.Request( + contextId = context, + blockIds = targets, + style = style.toMiddlewareModel() + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockListTurnInto(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockMerge(command: Command.Merge): Payload { + val request = Rpc.Block.Merge.Request( + contextId = command.context, + firstBlockId = command.pair.first, + secondBlockId = command.pair.second + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockMerge(request) + if (BuildConfig.DEBUG) logResponse(response) + + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockPaste(command: Command.Paste): Response.Clipboard.Paste { + + val range = Range( + from = command.range.first, + to = command.range.last + ) + + val blocks: List = command.blocks.map { it.toMiddlewareModel() } + + val request: Rpc.Block.Paste.Request = Rpc.Block.Paste.Request( + contextId = command.context, + focusedBlockId = command.focus, + textSlot = command.text, + htmlSlot = command.html.orEmpty(), + selectedTextRange = range, + anySlot = blocks, + selectedBlockIds = command.selected + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockPaste(request) + if (BuildConfig.DEBUG) logResponse(response) + return Response.Clipboard.Paste( + response.caretPosition, + response.isSameBlockCaret, + response.blockIds, + response.event.toPayload() + ) + } + + //todo Add Relation mapping + @Throws(Exception::class) + fun blockRelationAdd(command: Command.AddRelationToBlock): Payload { + val request = Rpc.BlockRelation.Add.Request( + contextId = command.contextId, + blockId = command.blockId, + relation = null + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockRelationAdd(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockRelationSetKey(command: Command.SetRelationKey): Payload { + val request = Rpc.BlockRelation.SetKey.Request( + contextId = command.contextId, + blockId = command.blockId, + key = command.key + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockRelationSetKey(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockReplace(command: Command.Replace): Pair { val model: Block = factory.create(command.prototype) @@ -475,125 +700,7 @@ class Middleware( } @Throws(Exception::class) - fun createDocument(command: Command.CreateDocument): Triple { - - val details: MutableMap = mutableMapOf() - - command.emoji?.let { details[iconEmojiKey] = it } - command.type?.let { details[typeKey] = it } - command.layout?.let { details[layoutKey] = it.toMiddlewareModel().value.toDouble() } - - val position: Block.Position = command.position.toMiddlewareModel() - - val request = Rpc.Block.CreatePage.Request( - contextId = command.context, - targetId = command.target, - position = position, - details = details, - templateId = command.template.orEmpty() - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockCreatePage(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return Triple( - response.blockId, - response.targetId, - response.event.toPayload() - ) - } - - @Throws(Exception::class) - fun createPage(command: Command.CreateNewDocument): Id { - - val details: MutableMap = mutableMapOf() - - command.emoji?.let { details[iconEmojiKey] = it } - command.name.let { details[nameKey] = it } - command.type?.let { details[typeKey] = it } - - val request = Rpc.Page.Create.Request( - details = details.toMap() - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.pageCreate(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return response.pageId - } - - @Throws(Exception::class) - fun move(command: Command.Move): Payload { - - val position: Block.Position = command.position.toMiddlewareModel() - - val request: BlockList.Move.Request = BlockList.Move.Request( - contextId = command.ctx, - targetContextId = command.targetContextId, - position = position, - blockIds = command.blockIds, - dropTargetId = command.targetId - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockListMove(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun duplicate(command: Command.Duplicate): Pair, Payload> { - val request = BlockList.Duplicate.Request( - contextId = command.context, - targetId = command.target, - blockIds = command.blocks, - position = Block.Position.Bottom - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockListDuplicate(request) - if (BuildConfig.DEBUG) logResponse(response) - - return Pair(response.blockIds, response.event.toPayload()) - } - - @Throws(Exception::class) - fun unlink(command: Command.Unlink): Payload { - val request = Rpc.Block.Unlink.Request( - contextId = command.context, - blockIds = command.targets - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockUnlink(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun merge(command: Command.Merge): Payload { - val request = Rpc.Block.Merge.Request( - contextId = command.context, - firstBlockId = command.pair.first, - secondBlockId = command.pair.second - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockMerge(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun split(command: Command.Split): Pair { + fun blockSplit(command: Command.Split): Pair { val style = command.style.toMiddlewareModel() @@ -622,332 +729,182 @@ class Middleware( } @Throws(Exception::class) - fun setDocumentEmojiIcon(command: Command.SetDocumentEmojiIcon): Payload { - - val emojiDetail = Rpc.Block.Set.Details.Detail( - key = iconEmojiKey, - value_ = command.emoji - ) - - val imageDetail = Rpc.Block.Set.Details.Detail( - key = iconImageKey, - value_ = null - ) - - val request = Rpc.Block.Set.Details.Request( - contextId = command.context, - details = listOf(emojiDetail, imageDetail) - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockSetDetails(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun setDocumentImageIcon(command: Command.SetDocumentImageIcon): Payload { - - val imageDetail = Rpc.Block.Set.Details.Detail( - key = iconImageKey, - value_ = command.hash - ) - val emojiDetail = Rpc.Block.Set.Details.Detail( - key = iconEmojiKey, - value_ = null - ) - - val request = Rpc.Block.Set.Details.Request( - contextId = command.context, - details = listOf(imageDetail, emojiDetail) - ) - - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockSetDetails(request) - - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun setDocumentCoverColor( - ctx: String, - color: String - ): Payload { - val coverIdDetail = Rpc.Block.Set.Details.Detail( - key = coverIdKey, - value_ = color - ) - val coverTypeDetail = Rpc.Block.Set.Details.Detail( - key = coverTypeKey, - value_ = Constants.COVER_TYPE_COLOR.toDouble() - ) - val request = Rpc.Block.Set.Details.Request( - contextId = ctx, - details = listOf(coverIdDetail, coverTypeDetail) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetDetails(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - @Throws(Exception::class) - fun setDocumentCoverGradient( - ctx: String, - gradient: String - ): Payload { - val coverIdDetail = Rpc.Block.Set.Details.Detail( - key = coverIdKey, - value_ = gradient - ) - val coverTypeDetail = Rpc.Block.Set.Details.Detail( - key = coverTypeKey, - value_ = Constants.COVER_TYPE_GRADIENT.toDouble() - ) - val request = Rpc.Block.Set.Details.Request( - contextId = ctx, - details = listOf(coverIdDetail, coverTypeDetail) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetDetails(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - @Throws(Exception::class) - fun setDocumentCoverImage( - ctx: String, - hash: String - ): Payload { - val coverIdDetail = Rpc.Block.Set.Details.Detail( - key = coverIdKey, - value_ = hash - ) - val coverTypeDetail = Rpc.Block.Set.Details.Detail( - key = coverTypeKey, - value_ = Constants.COVER_TYPE_UPLOADED_IMAGE.toDouble() - ) - val request = Rpc.Block.Set.Details.Request( - contextId = ctx, - details = listOf(coverIdDetail, coverTypeDetail) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetDetails(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - @Throws(Exception::class) - fun removeDocumentCover(ctx: String): Payload { - val coverIdDetail = Rpc.Block.Set.Details.Detail( - key = coverIdKey, - value_ = null - ) - val coverTypeDetail = Rpc.Block.Set.Details.Detail( - key = coverTypeKey, - value_ = Constants.COVER_TYPE_NONE.toDouble() - ) - val request = Rpc.Block.Set.Details.Request( - contextId = ctx, - details = listOf(coverIdDetail, coverTypeDetail) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetDetails(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - @Throws(Exception::class) - fun removeDocumentIcon(ctx: String): Payload { - val imageDetail = Rpc.Block.Set.Details.Detail( - key = iconImageKey, - value_ = null - ) - val emojiDetail = Rpc.Block.Set.Details.Detail( - key = iconEmojiKey, - value_ = null - ) - - val request = Rpc.Block.Set.Details.Request( - contextId = ctx, - details = listOf(imageDetail, emojiDetail) - ) - - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetDetails(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - @Throws(Exception::class) - fun setupBookmark(command: Command.SetupBookmark): Payload { - val request: Rpc.Block.Bookmark.Fetch.Request = Rpc.Block.Bookmark.Fetch.Request( - contextId = command.context, - blockId = command.target, - url = command.url - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockBookmarkFetch(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun createAndSetupBookmark(command: Command.CreateBookmark): Payload { - val request: Rpc.Block.Bookmark.CreateAndFetch.Request = Rpc.Block.Bookmark.CreateAndFetch.Request( - contextId = command.context, - targetId = command.target, - url = command.url, - position = command.position.toMiddlewareModel() - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockBookmarkCreateAndFetch(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun undo(command: Command.Undo): Payload { - val request = Rpc.Block.Undo.Request(contextId = command.context) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockUndo(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun redo(command: Command.Redo): Payload { - val request = Rpc.Block.Redo.Request(contextId = command.context) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockRedo(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() - } - - @Throws(Exception::class) - fun turnIntoDocument(command: Command.TurnIntoDocument): List { - val request = BlockList.ConvertChildrenToPages.Request( + fun blockTextListSetColor(command: Command.UpdateTextColor): Payload { + val request = Rpc.BlockText.ListSetColor.Request( contextId = command.context, + color = command.color, blockIds = command.targets ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.convertChildrenToPages(request) + val response = service.blockTextListSetColor(request) if (BuildConfig.DEBUG) logResponse(response) - return response.linkIds + return response.event.toPayload() } @Throws(Exception::class) - fun paste(command: Command.Paste): Response.Clipboard.Paste { - - val range = Range( - from = command.range.first, - to = command.range.last + fun blockTextListSetMark(command: Command.UpdateBlocksMark): Payload { + val context = command.context + val mark = command.mark.toMiddlewareModel() + val targets = command.targets + val request = Rpc.BlockText.ListSetMark.Request( + contextId = context, + blockIds = targets, + mark = mark ) - - val blocks: List = command.blocks.map { it.toMiddlewareModel() } - - val request: Rpc.Block.Paste.Request = Rpc.Block.Paste.Request( - contextId = command.context, - focusedBlockId = command.focus, - textSlot = command.text, - htmlSlot = command.html.orEmpty(), - selectedTextRange = range, - anySlot = blocks, - selectedBlockIds = command.selected - ) - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockPaste(request) - + val response = service.blockTextListSetMark(request) if (BuildConfig.DEBUG) logResponse(response) - - return Response.Clipboard.Paste( - response.caretPosition, - response.isSameBlockCaret, - response.blockIds, - response.event.toPayload() - ) + return response.event.toPayload() } @Throws(Exception::class) - fun copy(command: Command.Copy): Response.Clipboard.Copy { - - val range: Range? = command.range?.let { - Range( - from = it.first, - to = it.last - ) - } - - val blocks: List = command.blocks.map { it.toMiddlewareModel() } - - val request = Rpc.Block.Copy.Request( - contextId = command.context, - selectedTextRange = range, - blocks = blocks + fun blockTextListSetStyle(command: Command.UpdateStyle): Payload { + val style = command.style.toMiddlewareModel() + val request = Rpc.BlockText.ListSetStyle.Request( + style = style, + blockIds = command.targets, + contextId = command.context ) - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockCopy(request) - + val response = service.blockTextListSetStyle(request) if (BuildConfig.DEBUG) logResponse(response) - - return Response.Clipboard.Copy( - response.textSlot, - response.htmlSlot, - response.anySlot.toCoreModels() - ) + return response.event.toPayload() } @Throws(Exception::class) - fun uploadFile(command: Command.UploadFile): Response.Media.Upload { + fun blockTextSetChecked( + context: String, + target: String, + isChecked: Boolean + ): Payload { + val request = Rpc.BlockText.SetChecked.Request( + contextId = context, + blockId = target, + checked = isChecked + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockTextSetChecked(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun blockTextSetText( + contextId: String, + blockId: String, + text: String, + marks: List + ) { + val markup: Block.Content.Text.Marks = Block.Content.Text.Marks(marks) + val request = Rpc.BlockText.SetText.Request( + contextId = contextId, + blockId = blockId, + text = text, + marks = markup + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockTextSetText(request) + if (BuildConfig.DEBUG) logResponse(response) + } + + @Throws(Exception::class) + fun blockUpload(command: Command.UploadBlock): Payload { + val request = Rpc.Block.Upload.Request( + filePath = command.filePath, + url = command.url, + contextId = command.contextId, + blockId = command.blockId + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.blockUpload(request) + if (BuildConfig.DEBUG) logResponse(response) + + return response.event.toPayload() + } + + private val coverIdKey = "coverId" + private val coverTypeKey = "coverType" + + @Deprecated("Should deleted. Use objectOpen()") + @Throws(Exception::class) + fun dashboardOpen(contextId: String, id: String): Payload { + val request: Rpc.Object.Open.Request = Rpc.Object.Open.Request( + contextId = contextId, + objectId = id + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectOpen(request) + if (BuildConfig.DEBUG) logResponse(response) + + return response.event.toPayload() + } + + @Throws(Exception::class) + fun debugExportLocalStore(path: String): String { + val request = Rpc.Debug.ExportLocalstore.Request(path = path) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.debugExportLocalStore(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.path + } + + @Throws(Exception::class) + fun debugSync(): String { + val request = Rpc.Debug.Sync.Request() + if (BuildConfig.DEBUG) logRequest(request) + val response = service.debugSync(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.toString() + } + + @Throws(Exception::class) + fun fileListOffload() { + val request = Rpc.File.ListOffload.Request() + if (BuildConfig.DEBUG) logRequest(request) + val response = service.fileListOffload(request) + if (BuildConfig.DEBUG) logResponse(response) + } + + @Throws(Exception::class) + fun fileUpload(command: Command.UploadFile): Response.Media.Upload { val type = command.type.toMiddlewareModel() - - val request = Rpc.UploadFile.Request( + val request = Rpc.File.Upload.Request( localPath = command.path, type = type ) - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.uploadFile(request) - + val response = service.fileUpload(request) if (BuildConfig.DEBUG) logResponse(response) - return Response.Media.Upload(response.hash) } @Throws(Exception::class) - fun getMiddlewareVersion(): Rpc.Version.Get.Response { - val request = Rpc.Version.Get.Request() - if (BuildConfig.DEBUG) logRequest(request) - val response = service.versionGet(request) - if (BuildConfig.DEBUG) logResponse(response) - - return response + fun getConfig(): Config { + TODO() +// val request = Rpc.Config.Get.Request() +// +// if (BuildConfig.DEBUG) logRequest(request) +// +// val response = service.configGet(request) +// +// if (BuildConfig.DEBUG) logResponse(response) +// +// return Config( +// home = response.homeBlockId, +// profile = response.profileBlockId, +// gateway = response.gatewayUrl +// ) } @Throws(Exception::class) - fun getObjectInfoWithLinks(pageId: String): ObjectInfoWithLinks { + fun navigationGetObjectInfoWithLinks(pageId: String): ObjectInfoWithLinks { val request = Rpc.Navigation.GetObjectInfoWithLinks.Request( objectId = pageId ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectInfoWithLinks(request) + val response = service.navigationGetObjectInfoWithLinks(request) if (BuildConfig.DEBUG) logResponse(response) val info = response.object_ @@ -958,101 +915,56 @@ class Middleware( } @Throws(Exception::class) - fun listObjects(): List { + fun navigationListObjects(): List { val request = Rpc.Navigation.ListObjects.Request() if (BuildConfig.DEBUG) logRequest(request) - val response = service.listObjects(request) + val response = service.navigationListObjects(request) if (BuildConfig.DEBUG) logResponse(response) return response.objects } @Throws(Exception::class) - fun updateDividerStyle(command: Command.UpdateDivider): Payload { - val style = command.style.toMiddlewareModel() - - val request: BlockList.Set.Div.Style.Request = BlockList.Set.Div.Style.Request( - contextId = command.context, - blockIds = command.targets, - style = style + fun objectApplyTemplate( + ctx: Id, + template: Id + ) { + val request = Rpc.Object.ApplyTemplate.Request( + contextId = ctx, + templateId = template ) - if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockListSetDivStyle(request) - + val response = service.objectApplyTemplate(request) if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() } @Throws(Exception::class) - fun setFields(command: Command.SetFields): Payload { - - val fields: MutableList = ArrayList() - - for (i in command.fields.indices) { - val (first, second) = command.fields[i] - val field = BlockField( - blockId = first, - fields = second.map - ) - fields.add(field) - } - - val request = BlockList.Set.Fields.Request( - contextId = command.context, - blockFields = fields - ) - + fun objectClose(id: String) { + val request = Rpc.Object.Close.Request(objectId = id) if (BuildConfig.DEBUG) logRequest(request) - - val response = service.blockListSetFields(request) - + val response = service.objectClose(request) if (BuildConfig.DEBUG) logResponse(response) - - return response.event.toPayload() } @Throws(Exception::class) - fun getObjectTypes(): List { - val request = Rpc.ObjectType.List.Request() - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectTypeList(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.objectTypes - } + fun objectCreate(command: Command.CreateNewDocument): Id { + val details: MutableMap = mutableMapOf() + command.emoji?.let { details[Relations.ICON_EMOJI] = it } + command.name.let { details[Relations.NAME] = it } + command.type?.let { details[Relations.TYPE] = it } - @Throws(Exception::class) - fun objectTypeCreate(prototype: ObjectType.Prototype): MObjectType { - - val layout = prototype.layout.toMiddlewareModel() - - val objectType = MObjectType( - name = prototype.name, - iconEmoji = prototype.emoji, - layout = layout - ) - - val request = Rpc.ObjectType.Create.Request( - objectType = objectType + val request = Rpc.Object.Create.Request( + details = details.toMap() ) if (BuildConfig.DEBUG) logRequest(request) - - val response = service.objectTypeCreate(request) - + val response = service.objectCreate(request) if (BuildConfig.DEBUG) logResponse(response) - - val result = response.objectType - - checkNotNull(result) { "Empty result" } - - return result + return response.pageId } @Throws(Exception::class) - fun createSet( + fun objectCreateSet( contextId: String, targetId: String?, position: Position?, @@ -1065,214 +977,257 @@ class Middleware( listOf() } - val request = Rpc.Block.CreateSet.Request( - contextId = contextId, - targetId = targetId.orEmpty(), - source = source, - position = position?.toMiddlewareModel() ?: Block.Position.Bottom + val request = Rpc.Object.CreateSet.Request( + source = source ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockCreateSet(request) + val response = service.objectCreateSet(request) if (BuildConfig.DEBUG) logResponse(response) return Response.Set.Create( - blockId = response.blockId.ifEmpty { null }, - targetId = response.targetId, - payload = response.event.toPayload() + targetId = response.id, + payload = response.event.toPayload(), + blockId = null ) } @Throws(Exception::class) - fun setActiveDataViewViewer( - contextId: String, - blockId: String, - viewId: String, - offset: Int, - limit: Int - ): Payload { - val request = Rpc.Block.Dataview.ViewSetActive.Request( - contextId = contextId, - blockId = blockId, - viewId = viewId, - offset = offset, - limit = limit + fun objectDuplicate(id: Id): Id { + val request = Rpc.Object.Duplicate.Request(contextId = id) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectDuplicate(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.id + } + + @Throws(Exception::class) + fun objectIdsSubscribe( + subscription: Id, + ids: List, + keys: List + ): SearchResult { + val request = Rpc.Object.SubscribeIds.Request( + subId = subscription, + keys = keys, + ids = ids ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewActiveSet(request) + val response = service.objectIdsSubscribe(request) + if (BuildConfig.DEBUG) logResponse(response) + return SearchResult( + results = response.records.mapNotNull { record -> + if (record != null && record.isNotEmpty()) + ObjectWrapper.Basic(record) + else + null + }, + dependencies = response.dependencies.mapNotNull { record -> + if (record != null && record.isNotEmpty()) + ObjectWrapper.Basic(record) + else + null + }, + ) + } + + @Throws(Exception::class) + fun objectListDelete(targets: List) { + val request = Rpc.Object.ListDelete.Request(objectIds = targets) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectListDelete(request) + if (BuildConfig.DEBUG) logResponse(response) + } + + @Throws(Exception::class) + fun objectListSetIsArchived( + targets: List, + isArchived: Boolean + ) { + val request = Rpc.Object.ListSetIsArchived.Request( + objectIds = targets, + isArchived = isArchived, + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectListSetIsArchived(request) + if (BuildConfig.DEBUG) logResponse(response) + } + + @Throws(Exception::class) + fun objectOpen(id: String): Payload { + val request = Rpc.Object.Open.Request(objectId = id) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectOpen(request) if (BuildConfig.DEBUG) logResponse(response) return response.event.toPayload() } @Throws(Exception::class) - fun addNewRelationToDataView( - context: String, - target: String, - name: String, - format: Relation.Format, - limitObjectTypes: List - ): Pair { - - val relation = MRelation( - name = name, - format = format.toMiddlewareModel(), - objectTypes = limitObjectTypes - ) - - val request = Rpc.Block.Dataview.RelationAdd.Request( - contextId = context, - blockId = target, - relation = relation - ) - + fun objectRedo(command: Command.Redo): Payload { + val request = Rpc.Object.Redo.Request(contextId = command.context) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewRelationAdd(request) + val response = service.objectRedo(request) if (BuildConfig.DEBUG) logResponse(response) - return Pair(response.relationKey, response.event.toPayload()) + return response.event.toPayload() } + @Throws(Exception::class) + fun objectRelationAdd( + ctx: Id, + format: RelationFormat, + name: String, + limitObjectTypes: List + ): Pair { + val request = Rpc.ObjectRelation.Add.Request( + contextId = ctx, + relation = MRelation( + format = format.toMiddlewareModel(), + name = name, + objectTypes = limitObjectTypes + ) + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectRelationAdd(request) + if (BuildConfig.DEBUG) logResponse(response) + return Pair( + first = response.relation?.key.orEmpty(), + second = response.event.toPayload() + ) + } @Throws(Exception::class) - fun addRelationToDataView(ctx: Id, dv: Id, relation: Id): Payload { - val request = Rpc.Block.Dataview.RelationAdd.Request( + fun objectRelationAdd(ctx: Id, relation: Id): Payload { + val request = Rpc.ObjectRelation.Add.Request( contextId = ctx, - blockId = dv, relation = MRelation( key = relation ) ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewRelationAdd(request) + val response = service.objectRelationAdd(request) if (BuildConfig.DEBUG) logResponse(response) return response.event.toPayload() } @Throws(Exception::class) - fun deleteRelationFromDataView(ctx: Id, dv: Id, relation: Id): Payload { - val request = Rpc.Block.Dataview.RelationDelete.Request( + fun objectRelationAddFeatured( + ctx: Id, + relations: List + ): Payload { + val request = Rpc.ObjectRelation.AddFeatured.Request( + contextId = ctx, + relations = relations + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectRelationAddFeatured(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun objectRelationDelete(ctx: Id, relation: Id): Payload { + val request = Rpc.ObjectRelation.Delete.Request( contextId = ctx, - blockId = dv, relationKey = relation ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewRelationDelete(request) + val response = service.objectRelationDelete(request) if (BuildConfig.DEBUG) logResponse(response) return response.event.toPayload() } @Throws(Exception::class) - fun updateDataViewViewer( - context: String, - target: String, - viewer: DVViewer - ): Payload { - val request = Rpc.Block.Dataview.ViewUpdate.Request( - contextId = context, - blockId = target, - viewId = viewer.id, - view = viewer.toMiddlewareModel() + fun objectRelationListAvailable(ctx: Id): List { + val request = Rpc.ObjectRelation.ListAvailable.Request( + contextId = ctx ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewViewUpdate(request) + val response = service.objectRelationListAvailable(request) if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() + return response.relations } @Throws(Exception::class) - fun duplicateDataViewViewer( - context: String, - target: String, - viewer: DVViewer - ): Payload { - val request = Rpc.Block.Dataview.ViewCreate.Request( - contextId = context, - blockId = target, - view = viewer.toMiddlewareModel() - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewViewCreate(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - @Throws(Exception::class) - fun createDataViewRecord( - context: String, - target: String, - template: Id? - ): Map { - val request = Rpc.Block.Dataview.RecordCreate.Request( - contextId = context, - blockId = target, - templateId = template.orEmpty() - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewRecordCreate(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.record?.toMap() ?: emptyMap() - } - - @Throws(Exception::class) - fun updateDataViewRecord( - context: String, - target: String, - record: String, - values: Map - ) { - val request = Rpc.Block.Dataview.RecordUpdate.Request( - contextId = context, - blockId = target, - recordId = record, - record = values - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewRecordUpdate(request) - if (BuildConfig.DEBUG) logResponse(response) - } - - @Throws(Exception::class) - fun addDataViewViewer( - ctx: String, - target: String, - name: String, - type: DVViewerType - ): Payload { - val request = Rpc.Block.Dataview.ViewCreate.Request( + fun objectRelationOptionAdd( + ctx: Id, + relation: Id, + name: Id, + color: String + ): Pair { + val request = Rpc.ObjectRelationOption.Add.Request( contextId = ctx, - blockId = target, - view = Block.Content.Dataview.View( - name = name, - type = type.toMiddlewareModel() - ) + relationKey = relation, + option = MRelationOption(text = name, color = color) ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewViewCreate(request) + val response = service.objectRelationOptionAdd(request) + val option = response.option?.id if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() + return Pair(response.event.toPayload(), option) } @Throws(Exception::class) - fun removeDataViewViewer( - ctx: String, - dataview: String, - viewer: String + fun objectRelationRemoveFeatured( + ctx: Id, + relations: List ): Payload { - val request = Rpc.Block.Dataview.ViewDelete.Request( + val request = Rpc.ObjectRelation.RemoveFeatured.Request( contextId = ctx, - blockId = dataview, - viewId = viewer + relations = relations ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewViewDelete(request) + val response = service.objectRelationRemoveFeatured(request) if (BuildConfig.DEBUG) logResponse(response) return response.event.toPayload() } @Throws(Exception::class) - fun searchObjects( + fun objectRemoveCover(ctx: String): Payload { + val coverIdDetail = Rpc.Object.SetDetails.Detail( + key = coverIdKey, + value_ = null + ) + val coverTypeDetail = Rpc.Object.SetDetails.Detail( + key = coverTypeKey, + value_ = Constants.COVER_TYPE_NONE.toDouble() + ) + val request = Rpc.Object.SetDetails.Request( + contextId = ctx, + details = listOf(coverIdDetail, coverTypeDetail) + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectSetDetails(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun objectRemoveIcon(ctx: String): Payload { + val imageDetail = Rpc.Object.SetDetails.Detail( + key = Relations.ICON_IMAGE, + value_ = null + ) + val emojiDetail = Rpc.Object.SetDetails.Detail( + key = Relations.ICON_EMOJI, + value_ = null + ) + + val request = Rpc.Object.SetDetails.Request( + contextId = ctx, + details = listOf(imageDetail, emojiDetail) + ) + + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectSetDetails(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun objectSearch( sorts: List, filters: List, fulltext: String, @@ -1294,10 +1249,8 @@ class Middleware( return response.records.map { it?.toMap() ?: emptyMap() } } - //region SEARCHING WITH SUBSCRIPTIONS - @Throws(Exception::class) - fun searchObjectsWithSubscription( + fun objectSearchSubscribe( subscription: Id, sorts: List, filters: List, @@ -1337,37 +1290,7 @@ class Middleware( } @Throws(Exception::class) - fun searchObjectsByIdWithSubscription( - subscription: Id, - ids: List, - keys: List - ): SearchResult { - val request = Rpc.Object.IdsSubscribe.Request( - subId = subscription, - keys = keys, - ids = ids - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectIdsSubscribe(request) - if (BuildConfig.DEBUG) logResponse(response) - return SearchResult( - results = response.records.mapNotNull { record -> - if (record != null && record.isNotEmpty()) - ObjectWrapper.Basic(record) - else - null - }, - dependencies = response.dependencies.mapNotNull { record -> - if (record != null && record.isNotEmpty()) - ObjectWrapper.Basic(record) - else - null - }, - ) - } - - @Throws(Exception::class) - fun cancelObjectSearchSubscription(subscriptions: List) { + fun objectSearchUnsubscribe(subscriptions: List) { val request = Rpc.Object.SearchUnsubscribe.Request( subIds = subscriptions ) @@ -1376,261 +1299,150 @@ class Middleware( if (BuildConfig.DEBUG) logResponse(response) } - //endregion - @Throws(Exception::class) - fun relationListAvailable(ctx: Id): List { - val request = Rpc.Object.RelationListAvailable.Request( - contextId = ctx - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.relationListAvailable(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.relations - } - - //todo Add Relation mapping - @Throws(Exception::class) - fun addRelationToBlock(command: Command.AddRelationToBlock): Payload { - val request = Rpc.Block.Relation.Add.Request( - contextId = command.contextId, - blockId = command.blockId, - relation = null - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockAddRelation(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - fun setRelationKey(command: Command.SetRelationKey): Payload { - Rpc.Block.Relation.Add - val request = Rpc.Block.Relation.SetKey.Request( - contextId = command.contextId, - blockId = command.blockId, - key = command.key - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.relationSetKey(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - @Throws(Exception::class) - fun debugSync(): String { - val request = Rpc.Debug.Sync.Request() - if (BuildConfig.DEBUG) logRequest(request) - val response = service.debugSync(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.toString() - } - - fun addRecordRelationOption( - ctx: Id, - dataview: Id, - relation: Id, - record: Id, - name: String, + fun objectSetCoverColor( + ctx: String, color: String - ): Pair { - val request = Rpc.Block.Dataview.RecordRelationOptionAdd.Request( - contextId = ctx, - blockId = dataview, - relationKey = relation, - recordId = record, - option = MRelationOption(text = name, color = color) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockDataViewRecordRelationOptionAdd(request) - val option = response.option?.id - if (BuildConfig.DEBUG) logResponse(response) - return Pair(response.event.toPayload(), option) - } - - fun addObjectRelationOption( - ctx: Id, - relation: Id, - name: Id, - color: String - ): Pair { - val request = Rpc.Object.RelationOptionAdd.Request( - contextId = ctx, - relationKey = relation, - option = MRelationOption(text = name, color = color) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectRelationOptionAdd(request) - val option = response.option?.id - if (BuildConfig.DEBUG) logResponse(response) - return Pair(response.event.toPayload(), option) - } - - fun blockListTurnInto( - context: String, - targets: List, - style: CBTextStyle ): Payload { - val request = BlockList.TurnInto.Request( - contextId = context, - blockIds = targets, - style = style.toMiddlewareModel() + val coverIdDetail = Rpc.Object.SetDetails.Detail( + key = coverIdKey, + value_ = color + ) + val coverTypeDetail = Rpc.Object.SetDetails.Detail( + key = coverTypeKey, + value_ = Constants.COVER_TYPE_COLOR.toDouble() + ) + val request = Rpc.Object.SetDetails.Request( + contextId = ctx, + details = listOf(coverIdDetail, coverTypeDetail) ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockListTurnInto(request) + val response = service.objectSetDetails(request) if (BuildConfig.DEBUG) logResponse(response) return response.event.toPayload() } - fun updateDetail( + @Throws(Exception::class) + fun objectSetCoverGradient( + ctx: String, + gradient: String + ): Payload { + val coverIdDetail = Rpc.Object.SetDetails.Detail( + key = coverIdKey, + value_ = gradient + ) + val coverTypeDetail = Rpc.Object.SetDetails.Detail( + key = coverTypeKey, + value_ = Constants.COVER_TYPE_GRADIENT.toDouble() + ) + val request = Rpc.Object.SetDetails.Request( + contextId = ctx, + details = listOf(coverIdDetail, coverTypeDetail) + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectSetDetails(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun objectSetCoverImage( + ctx: String, + hash: String + ): Payload { + val coverIdDetail = Rpc.Object.SetDetails.Detail( + key = coverIdKey, + value_ = hash + ) + val coverTypeDetail = Rpc.Object.SetDetails.Detail( + key = coverTypeKey, + value_ = Constants.COVER_TYPE_UPLOADED_IMAGE.toDouble() + ) + val request = Rpc.Object.SetDetails.Request( + contextId = ctx, + details = listOf(coverIdDetail, coverTypeDetail) + ) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectSetDetails(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun objectSetDetails( ctx: Id, key: String, value: Any? ): Payload { - val detail = Rpc.Block.Set.Details.Detail( + val detail = Rpc.Object.SetDetails.Detail( key = key, value_ = value ) - val request = Rpc.Block.Set.Details.Request( + val request = Rpc.Object.SetDetails.Request( contextId = ctx, details = listOf(detail) ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetDetails(request) + val response = service.objectSetDetails(request) if (BuildConfig.DEBUG) logResponse(response) return response.event.toPayload() } @Throws(Exception::class) - fun blockListSetTextMarkup(command: Command.UpdateBlocksMark): Payload { - val context = command.context - val mark = command.mark.toMiddlewareModel() - val targets = command.targets + fun objectSetEmojiIcon(command: Command.SetDocumentEmojiIcon): Payload { - val request = BlockList.Set.Text.Mark.Request( - contextId = context, - blockIds = targets, - mark = mark + val emojiDetail = Rpc.Object.SetDetails.Detail( + key = Relations.ICON_EMOJI, + value_ = command.emoji + ) + + val imageDetail = Rpc.Object.SetDetails.Detail( + key = Relations.ICON_IMAGE, + value_ = null + ) + + val request = Rpc.Object.SetDetails.Request( + contextId = command.context, + details = listOf(emojiDetail, imageDetail) ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockListSetTextMark(request) + + val response = service.objectSetDetails(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() } @Throws(Exception::class) - fun setObjectType(ctx: Id, typeId: Id): Payload { + fun objectSetImageIcon(command: Command.SetDocumentImageIcon): Payload { - val request = Rpc.Block.ObjectType.Set.Request( - contextId = ctx, - objectTypeUrl = typeId + val imageDetail = Rpc.Object.SetDetails.Detail( + key = Relations.ICON_IMAGE, + value_ = command.hash ) + val emojiDetail = Rpc.Object.SetDetails.Detail( + key = Relations.ICON_EMOJI, + value_ = null + ) + + val request = Rpc.Object.SetDetails.Request( + contextId = command.context, + details = listOf(imageDetail, emojiDetail) + ) + if (BuildConfig.DEBUG) logRequest(request) - val response = service.blockSetObjectType(request) + + val response = service.objectSetDetails(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() } - private fun logRequest(any: Any) { - val message = "===> " + any::class.java.canonicalName + ":" + "\n" + any.toString() - Timber.d(message) - } - - private fun logResponse(any: Any) { - val message = "<=== " + any::class.java.canonicalName + ":" + "\n" + any.toString() - Timber.d(message) - } - - fun addRelationToObject(ctx: Id, relation: Id): Payload { - val request = Rpc.Object.RelationAdd.Request( - contextId = ctx, - relation = MRelation( - key = relation - ) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectRelationAdd(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - fun addNewRelationToObject( - ctx: Id, - format: RelationFormat, - name: String, - limitObjectTypes: List - ): Pair { - val request = Rpc.Object.RelationAdd.Request( - contextId = ctx, - relation = MRelation( - format = format.toMiddlewareModel(), - name = name, - objectTypes = limitObjectTypes - ) - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectRelationAdd(request) - if (BuildConfig.DEBUG) logResponse(response) - return Pair( - first = response.relation?.key.orEmpty(), - second = response.event.toPayload() - ) - } - - fun deleteRelationFromObject(ctx: Id, relation: Id): Payload { - val request = Rpc.Object.RelationDelete.Request( - contextId = ctx, - relationKey = relation - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectRelationDelete(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - fun addToFeaturedRelations( - ctx: Id, - relations: List - ): Payload { - val request = Rpc.Object.FeaturedRelation.Add.Request( - contextId = ctx, - relations = relations - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.featuredRelationsAdd(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - fun removeFromFeaturedRelations( - ctx: Id, - relations: List - ): Payload { - val request = Rpc.Object.FeaturedRelation.Remove.Request( - contextId = ctx, - relations = relations - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.featuredRelationsRemove(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - fun setObjectIsFavorite( - ctx: Id, - isFavorite: Boolean - ): Payload { - val request = Rpc.Object.SetIsFavorite.Request( - contextId = ctx, - isFavorite = isFavorite - ) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectSetIsFavorite(request) - if (BuildConfig.DEBUG) logResponse(response) - return response.event.toPayload() - } - - fun setObjectIsArchived( + @Throws(Exception::class) + fun objectSetIsArchived( ctx: Id, isArchived: Boolean ): Payload { @@ -1644,27 +1456,23 @@ class Middleware( return response.event.toPayload() } - fun setObjectListIsArchived( - targets: List, - isArchived: Boolean - ) { - val request = Rpc.ObjectList.Set.IsArchived.Request( - objectIds = targets, - isArchived = isArchived, + @Throws(Exception::class) + fun objectSetIsFavorite( + ctx: Id, + isFavorite: Boolean + ): Payload { + val request = Rpc.Object.SetIsFavorite.Request( + contextId = ctx, + isFavorite = isFavorite ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectListSetIsArchived(request) + val response = service.objectSetIsFavorite(request) if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() } - fun deleteObjects(targets: List) { - val request = Rpc.ObjectList.Delete.Request(objectIds = targets) - if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectListDelete(request) - if (BuildConfig.DEBUG) logResponse(response) - } - - fun setObjectLayout(ctx: Id, layout: ObjectType.Layout): Payload { + @Throws(Exception::class) + fun objectSetLayout(ctx: Id, layout: ObjectType.Layout): Payload { val request = Rpc.Object.SetLayout.Request( contextId = ctx, layout = layout.toMiddlewareModel() @@ -1675,45 +1483,141 @@ class Middleware( return response.event.toPayload() } - fun exportLocalStore(path: String): String { - val request = Rpc.ExportLocalstore.Request(path = path) + @Throws(Exception::class) + fun objectSetObjectType(ctx: Id, typeId: Id): Payload { + val request = Rpc.Object.SetObjectType.Request( + contextId = ctx, + objectTypeUrl = typeId + ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.exportLocalStore(request) + val response = service.objectSetObjectType(request) if (BuildConfig.DEBUG) logResponse(response) - return response.path + return response.event.toPayload() } - fun fileListOffload() { - val request = Rpc.FileList.Offload.Request() + @Throws(Exception::class) + fun objectSetTitle(command: Command.UpdateTitle) { + val detail = Rpc.Object.SetDetails.Detail( + key = Relations.NAME, + value_ = command.title + ) + val request = Rpc.Object.SetDetails.Request( + contextId = command.context, + details = listOf(detail) + ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.fileListOffload(request) + val response = service.objectSetDetails(request) if (BuildConfig.DEBUG) logResponse(response) } @Throws(Exception::class) - fun objectDuplicate(id: Id): Id { + fun objectShow(id: String): Payload { + val request = Rpc.Object.Show.Request(objectId = id) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectShow(request) + if (BuildConfig.DEBUG) logResponse(response) - val request = Rpc.ObjectDuplicate.Request(contextId = id) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun objectTypeCreate(prototype: ObjectType.Prototype): MObjectType { + + val layout = prototype.layout.toMiddlewareModel() + + val objectType = MObjectType( + name = prototype.name, + iconEmoji = prototype.emoji, + layout = layout + ) + + val request = Rpc.ObjectType.Create.Request( + objectType = objectType + ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.objectDuplicate(request) + val response = service.objectTypeCreate(request) if (BuildConfig.DEBUG) logResponse(response) - return response.id + val result = response.objectType + + checkNotNull(result) { "Empty result" } + + return result } - fun applyTemplate( - ctx: Id, - template: Id - ) { - val request = Rpc.ApplyTemplate.Request( - contextId = ctx, - templateId = template + @Throws(Exception::class) + fun objectTypeList(): List { + val request = Rpc.ObjectType.List.Request() + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectTypeList(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.objectTypes + } + + @Throws(Exception::class) + fun objectUndo(command: Command.Undo): Payload { + val request = Rpc.Object.Undo.Request(contextId = command.context) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.objectUndo(request) + if (BuildConfig.DEBUG) logResponse(response) + return response.event.toPayload() + } + + @Throws(Exception::class) + fun versionGet(): Rpc.App.GetVersion.Response { + val request = Rpc.App.GetVersion.Request() + if (BuildConfig.DEBUG) logRequest(request) + val response = service.versionGet(request) + if (BuildConfig.DEBUG) logResponse(response) + return response + } + + @Throws(Exception::class) + fun walletConvert(entropy: String): String { + val request = Rpc.Wallet.Convert.Request(entropy = entropy) + if (BuildConfig.DEBUG) logRequest(request) + val response = service.walletConvert(request) + if (BuildConfig.DEBUG) logResponse(response) + + return response.mnemonic + } + + @Throws(Exception::class) + fun walletCreate(path: String): CreateWalletResponse { + + val request = Rpc.Wallet.Create.Request(rootPath = path) + + if (BuildConfig.DEBUG) logRequest(request) + + val response = service.walletCreate(request) + + if (BuildConfig.DEBUG) logResponse(response) + + return CreateWalletResponse(response.mnemonic) + } + + @Throws(Exception::class) + fun walletRecover(path: String, mnemonic: String) { + val request = Rpc.Wallet.Recover.Request( + mnemonic = mnemonic, + rootPath = path ) if (BuildConfig.DEBUG) logRequest(request) - val response = service.applyTemplate(request) + val response = service.walletRecover(request) if (BuildConfig.DEBUG) logResponse(response) } + + private fun logRequest(any: Any) { + val message = "===> " + any::class.java.canonicalName + ":" + "\n" + any.toString() + Timber.d(message) + } + + private fun logResponse(any: Any) { + val message = "<=== " + any::class.java.canonicalName + ":" + "\n" + any.toString() + Timber.d(message) + } + } \ No newline at end of file diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/UnsplashMapper.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/UnsplashMapper.kt index dd150d72a0..d53b4a7ff5 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/UnsplashMapper.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/UnsplashMapper.kt @@ -1,6 +1,6 @@ package com.anytypeio.anytype.middleware.mappers -import anytype.Rpc.UnsplashSearch.Response.Picture +import anytype.Rpc.Unsplash.Search.Response.Picture import com.anytypeio.anytype.core_models.UnsplashImage fun Picture.core() : UnsplashImage = UnsplashImage( diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareService.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareService.kt index 2b0627dfab..b0fdb8ffb6 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareService.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareService.kt @@ -1,266 +1,298 @@ package com.anytypeio.anytype.middleware.service -import anytype.Rpc.ObjectDuplicate -import anytype.Rpc.Account -import anytype.Rpc.ApplyTemplate -import anytype.Rpc.Block -import anytype.Rpc.BlockList -import anytype.Rpc.Config -import anytype.Rpc.Debug -import anytype.Rpc.ExportLocalstore -import anytype.Rpc.FileList -import anytype.Rpc.Navigation -import anytype.Rpc.Object -import anytype.Rpc.ObjectList -import anytype.Rpc.ObjectType -import anytype.Rpc.Page -import anytype.Rpc.UnsplashDownload -import anytype.Rpc.UnsplashSearch -import anytype.Rpc.UploadFile -import anytype.Rpc.Version -import anytype.Rpc.Wallet +import anytype.Rpc /** * Service for interacting with the backend. */ interface MiddlewareService { - @Throws(Exception::class) - fun configGet(request: Config.Get.Request): Config.Get.Response + + //region APP commands @Throws(Exception::class) - fun walletCreate(request: Wallet.Create.Request): Wallet.Create.Response + fun versionGet(request: Rpc.App.GetVersion.Request): Rpc.App.GetVersion.Response + + //endregion + + //region WALLET commands @Throws(Exception::class) - fun walletConvert(request: Wallet.Convert.Request): Wallet.Convert.Response + fun walletCreate(request: Rpc.Wallet.Create.Request): Rpc.Wallet.Create.Response @Throws(Exception::class) - fun walletRecover(request: Wallet.Recover.Request): Wallet.Recover.Response + fun walletRecover(request: Rpc.Wallet.Recover.Request): Rpc.Wallet.Recover.Response @Throws(Exception::class) - fun accountCreate(request: Account.Create.Request): Account.Create.Response + fun walletConvert(request: Rpc.Wallet.Convert.Request): Rpc.Wallet.Convert.Response + + //endregion com + + //region ACCOUNT commands @Throws(Exception::class) - fun accountDelete(request: Account.Delete.Request) : Account.Delete.Response + fun accountRecover(request: Rpc.Account.Recover.Request): Rpc.Account.Recover.Response @Throws(Exception::class) - fun accountSelect(request: Account.Select.Request): Account.Select.Response + fun accountCreate(request: Rpc.Account.Create.Request): Rpc.Account.Create.Response @Throws(Exception::class) - fun accountRecover(request: Account.Recover.Request): Account.Recover.Response + fun accountDelete(request: Rpc.Account.Delete.Request): Rpc.Account.Delete.Response @Throws(Exception::class) - fun accountStop(request: Account.Stop.Request): Account.Stop.Response + fun accountSelect(request: Rpc.Account.Select.Request): Rpc.Account.Select.Response @Throws(Exception::class) - fun blockOpen(request: Block.Open.Request): Block.Open.Response + fun accountStop(request: Rpc.Account.Stop.Request): Rpc.Account.Stop.Response + + //endregion + + //region OBJECT commands @Throws(Exception::class) - fun blockShow(request: Block.Show.Request): Block.Show.Response + fun objectOpen(request: Rpc.Object.Open.Request): Rpc.Object.Open.Response @Throws(Exception::class) - fun blockClose(request: Block.Close.Request): Block.Close.Response + fun objectClose(request: Rpc.Object.Close.Request): Rpc.Object.Close.Response @Throws(Exception::class) - fun blockCreate(request: Block.Create.Request): Block.Create.Response + fun objectShow(request: Rpc.Object.Show.Request): Rpc.Object.Show.Response @Throws(Exception::class) - fun blockCreatePage(request: Block.CreatePage.Request): Block.CreatePage.Response + fun objectCreate(request: Rpc.Object.Create.Request): Rpc.Object.Create.Response @Throws(Exception::class) - fun blockSetTextText(request: Block.Set.Text.TText.Request): Block.Set.Text.TText.Response + fun objectCreateSet(request: Rpc.Object.CreateSet.Request): Rpc.Object.CreateSet.Response @Throws(Exception::class) - fun blockSetTextChecked(request: Block.Set.Text.Checked.Request): Block.Set.Text.Checked.Response + fun objectSearch(request: Rpc.Object.Search.Request): Rpc.Object.Search.Response @Throws(Exception::class) - fun blockSetTextColor(request: BlockList.Set.Text.Color.Request): BlockList.Set.Text.Color.Response + fun objectSearchSubscribe(request: Rpc.Object.SearchSubscribe.Request): Rpc.Object.SearchSubscribe.Response @Throws(Exception::class) - fun blockListSetBackgroundColor(request: BlockList.Set.BackgroundColor.Request): BlockList.Set.BackgroundColor.Response + fun objectSearchUnsubscribe(request: Rpc.Object.SearchUnsubscribe.Request): Rpc.Object.SearchUnsubscribe.Response @Throws(Exception::class) - fun blockListSetAlign(request: BlockList.Set.Align.Request): BlockList.Set.Align.Response + fun objectIdsSubscribe(request: Rpc.Object.SubscribeIds.Request): Rpc.Object.SubscribeIds.Response @Throws(Exception::class) - fun blockListSetTextStyle(request: BlockList.Set.Text.Style.Request): BlockList.Set.Text.Style.Response + fun objectSetDetails(request: Rpc.Object.SetDetails.Request): Rpc.Object.SetDetails.Response @Throws(Exception::class) - fun blockListSetDivStyle(request: BlockList.Set.Div.Style.Request): BlockList.Set.Div.Style.Response + fun objectDuplicate(request: Rpc.Object.Duplicate.Request): Rpc.Object.Duplicate.Response @Throws(Exception::class) - fun blockListMove(request: BlockList.Move.Request): BlockList.Move.Response + fun objectSetObjectType(request: Rpc.Object.SetObjectType.Request): Rpc.Object.SetObjectType.Response @Throws(Exception::class) - fun blockUnlink(request: Block.Unlink.Request): Block.Unlink.Response + fun objectSetLayout(request: Rpc.Object.SetLayout.Request): Rpc.Object.SetLayout.Response @Throws(Exception::class) - fun blockMerge(request: Block.Merge.Request): Block.Merge.Response + fun objectSetIsFavorite(request: Rpc.Object.SetIsFavorite.Request): Rpc.Object.SetIsFavorite.Response @Throws(Exception::class) - fun blockSplit(request: Block.Split.Request): Block.Split.Response + fun objectSetIsArchived(request: Rpc.Object.SetIsArchived.Request): Rpc.Object.SetIsArchived.Response @Throws(Exception::class) - fun blockListDuplicate(request: BlockList.Duplicate.Request): BlockList.Duplicate.Response + fun objectListSetIsArchived(request: Rpc.Object.ListSetIsArchived.Request): Rpc.Object.ListSetIsArchived.Response @Throws(Exception::class) - fun convertChildrenToPages(request: BlockList.ConvertChildrenToPages.Request): BlockList.ConvertChildrenToPages.Response + fun objectListDelete(request: Rpc.Object.ListDelete.Request): Rpc.Object.ListDelete.Response @Throws(Exception::class) - fun blockBookmarkFetch(request: Block.Bookmark.Fetch.Request): Block.Bookmark.Fetch.Response + fun objectApplyTemplate(request: Rpc.Object.ApplyTemplate.Request): Rpc.Object.ApplyTemplate.Response @Throws(Exception::class) - fun blockBookmarkCreateAndFetch(request: Block.Bookmark.CreateAndFetch.Request): Block.Bookmark.CreateAndFetch.Response + fun objectUndo(request: Rpc.Object.Undo.Request): Rpc.Object.Undo.Response @Throws(Exception::class) - fun blockUpload(request: Block.Upload.Request): Block.Upload.Response + fun objectRedo(request: Rpc.Object.Redo.Request): Rpc.Object.Redo.Response + + //endregion + + //region OBJECT'S RELATIONS command @Throws(Exception::class) - fun blockUndo(request: Block.Undo.Request): Block.Undo.Response + fun objectRelationAdd(request: Rpc.ObjectRelation.Add.Request): Rpc.ObjectRelation.Add.Response @Throws(Exception::class) - fun blockRedo(request: Block.Redo.Request): Block.Redo.Response + fun objectRelationDelete(request: Rpc.ObjectRelation.Delete.Request): Rpc.ObjectRelation.Delete.Response @Throws(Exception::class) - fun blockSetDetails(request: Block.Set.Details.Request): Block.Set.Details.Response + fun objectRelationAddFeatured(request: Rpc.ObjectRelation.AddFeatured.Request): Rpc.ObjectRelation.AddFeatured.Response @Throws(Exception::class) - fun blockPaste(request: Block.Paste.Request): Block.Paste.Response + fun objectRelationRemoveFeatured(request: Rpc.ObjectRelation.RemoveFeatured.Request): Rpc.ObjectRelation.RemoveFeatured.Response @Throws(Exception::class) - fun blockCopy(request: Block.Copy.Request): Block.Copy.Response + fun objectRelationListAvailable(request: Rpc.ObjectRelation.ListAvailable.Request): Rpc.ObjectRelation.ListAvailable.Response @Throws(Exception::class) - fun uploadFile(request: UploadFile.Request): UploadFile.Response + fun objectRelationOptionAdd(request: Rpc.ObjectRelationOption.Add.Request): Rpc.ObjectRelationOption.Add.Response + + //endregion + + //region OBJECT TYPE commands @Throws(Exception::class) - fun objectInfoWithLinks(request: Navigation.GetObjectInfoWithLinks.Request): Navigation.GetObjectInfoWithLinks.Response + fun objectTypeCreate(request: Rpc.ObjectType.Create.Request): Rpc.ObjectType.Create.Response @Throws(Exception::class) - fun listObjects(request: Navigation.ListObjects.Request): Navigation.ListObjects.Response + fun objectTypeList(request: Rpc.ObjectType.List.Request): Rpc.ObjectType.List.Response + + //endregion + + //region FILES commands @Throws(Exception::class) - fun pageCreate(request: Page.Create.Request): Page.Create.Response + fun fileListOffload(request: Rpc.File.ListOffload.Request): Rpc.File.ListOffload.Response @Throws(Exception::class) - fun versionGet(request: Version.Get.Request): Version.Get.Response + fun fileUpload(request: Rpc.File.Upload.Request): Rpc.File.Upload.Response + + //endregion + + //region UNSPLASH commands @Throws(Exception::class) - fun blockListSetFields(request: BlockList.Set.Fields.Request): BlockList.Set.Fields.Response + fun unsplashSearch(request: Rpc.Unsplash.Search.Request): Rpc.Unsplash.Search.Response @Throws(Exception::class) - fun objectTypeList(request: ObjectType.List.Request): ObjectType.List.Response + fun unsplashDownload(request: Rpc.Unsplash.Download.Request): Rpc.Unsplash.Download.Response + + //endregion + + //region BLOCK commands @Throws(Exception::class) - fun objectTypeCreate(request: ObjectType.Create.Request): ObjectType.Create.Response + fun blockCreate(request: Rpc.Block.Create.Request): Rpc.Block.Create.Response @Throws(Exception::class) - fun blockCreateSet(request: Block.CreateSet.Request): Block.CreateSet.Response + fun blockPaste(request: Rpc.Block.Paste.Request): Rpc.Block.Paste.Response @Throws(Exception::class) - fun blockDataViewActiveSet(request: Block.Dataview.ViewSetActive.Request): Block.Dataview.ViewSetActive.Response + fun blockCopy(request: Rpc.Block.Copy.Request): Rpc.Block.Copy.Response @Throws(Exception::class) - fun blockDataViewRelationAdd(request: Block.Dataview.RelationAdd.Request): Block.Dataview.RelationAdd.Response + fun blockUpload(request: Rpc.Block.Upload.Request): Rpc.Block.Upload.Response @Throws(Exception::class) - fun blockDataViewRelationDelete(request: Block.Dataview.RelationDelete.Request): Block.Dataview.RelationDelete.Response + fun blockMerge(request: Rpc.Block.Merge.Request): Rpc.Block.Merge.Response @Throws(Exception::class) - fun blockDataViewViewUpdate(request: Block.Dataview.ViewUpdate.Request): Block.Dataview.ViewUpdate.Response + fun blockSplit(request: Rpc.Block.Split.Request): Rpc.Block.Split.Response @Throws(Exception::class) - fun blockDataViewViewDelete(request: Block.Dataview.ViewDelete.Request): Block.Dataview.ViewDelete.Response + fun blockListDelete(request: Rpc.Block.ListDelete.Request): Rpc.Block.ListDelete.Response @Throws(Exception::class) - fun blockDataViewRecordCreate(request: Block.Dataview.RecordCreate.Request): Block.Dataview.RecordCreate.Response + fun blockListMoveToExistingObject(request: Rpc.Block.ListMoveToExistingObject.Request): Rpc.Block.ListMoveToExistingObject.Response @Throws(Exception::class) - fun blockDataViewRecordUpdate(request: Block.Dataview.RecordUpdate.Request): Block.Dataview.RecordUpdate.Response + fun blockListMoveToNewObject(request: Rpc.Block.ListMoveToNewObject.Request): Rpc.Block.ListMoveToNewObject.Response @Throws(Exception::class) - fun blockDataViewViewCreate(request: Block.Dataview.ViewCreate.Request): Block.Dataview.ViewCreate.Response + fun blockListSetFields(request: Rpc.Block.ListSetFields.Request): Rpc.Block.ListSetFields.Response @Throws(Exception::class) - fun blockDataViewRecordRelationOptionAdd(request: Block.Dataview.RecordRelationOptionAdd.Request): Block.Dataview.RecordRelationOptionAdd.Response + fun blockListSetBackgroundColor(request: Rpc.Block.ListSetBackgroundColor.Request): Rpc.Block.ListSetBackgroundColor.Response @Throws(Exception::class) - fun objectRelationOptionAdd(request: Object.RelationOptionAdd.Request): Object.RelationOptionAdd.Response + fun blockListSetAlign(request: Rpc.Block.ListSetAlign.Request): Rpc.Block.ListSetAlign.Response @Throws(Exception::class) - fun objectSearch(request: Object.Search.Request): Object.Search.Response + fun blockListDuplicate(request: Rpc.Block.ListDuplicate.Request): Rpc.Block.ListDuplicate.Response @Throws(Exception::class) - fun objectSearchSubscribe(request: Object.SearchSubscribe.Request): Object.SearchSubscribe.Response + fun blockListTurnInto(request: Rpc.Block.ListTurnInto.Request): Rpc.Block.ListTurnInto.Response @Throws(Exception::class) - fun objectIdsSubscribe(request: Object.IdsSubscribe.Request): Object.IdsSubscribe.Response + fun blockListSetDivStyle(request: Rpc.BlockDiv.ListSetStyle.Request): Rpc.BlockDiv.ListSetStyle.Response @Throws(Exception::class) - fun objectSearchUnsubscribe(request: Object.SearchUnsubscribe.Request): Object.SearchUnsubscribe.Response + fun blockBookmarkFetch(request: Rpc.BlockBookmark.Fetch.Request): Rpc.BlockBookmark.Fetch.Response @Throws(Exception::class) - fun relationListAvailable(request: Object.RelationListAvailable.Request): Object.RelationListAvailable.Response + fun blockBookmarkCreateAndFetch(request: Rpc.BlockBookmark.CreateAndFetch.Request): Rpc.BlockBookmark.CreateAndFetch.Response @Throws(Exception::class) - fun objectRelationAdd(request: Object.RelationAdd.Request) : Object.RelationAdd.Response + fun blockLinkCreateWithObject(request: Rpc.BlockLink.CreateWithObject.Request): Rpc.BlockLink.CreateWithObject.Response @Throws(Exception::class) - fun objectRelationDelete(request: Object.RelationDelete.Request) : Object.RelationDelete.Response + fun blockRelationAdd(request: Rpc.BlockRelation.Add.Request): Rpc.BlockRelation.Add.Response @Throws(Exception::class) - fun debugSync(request: Debug.Sync.Request) : Debug.Sync.Response + fun blockRelationSetKey(request: Rpc.BlockRelation.SetKey.Request): Rpc.BlockRelation.SetKey.Response + + //endregion + + //region NAVIGATION commands @Throws(Exception::class) - fun relationSetKey(request: Block.Relation.SetKey.Request) : Block.Relation.SetKey.Response + fun navigationGetObjectInfoWithLinks(request: Rpc.Navigation.GetObjectInfoWithLinks.Request): Rpc.Navigation.GetObjectInfoWithLinks.Response @Throws(Exception::class) - fun blockAddRelation(request: Block.Relation.Add.Request) : Block.Relation.Add.Response + fun navigationListObjects(request: Rpc.Navigation.ListObjects.Request): Rpc.Navigation.ListObjects.Response + + //endregion + + //region DATA VIEW commands @Throws(Exception::class) - fun blockListTurnInto(request: BlockList.TurnInto.Request): BlockList.TurnInto.Response + fun blockDataViewActiveSet(request: Rpc.BlockDataview.View.SetActive.Request): Rpc.BlockDataview.View.SetActive.Response @Throws(Exception::class) - fun blockListSetTextMark(request: BlockList.Set.Text.Mark.Request): BlockList.Set.Text.Mark.Response + fun blockDataViewViewCreate(request: Rpc.BlockDataview.View.Create.Request): Rpc.BlockDataview.View.Create.Response @Throws(Exception::class) - fun blockSetObjectType(request: Block.ObjectType.Set.Request): Block.ObjectType.Set.Response + fun blockDataViewViewUpdate(request: Rpc.BlockDataview.View.Update.Request): Rpc.BlockDataview.View.Update.Response @Throws(Exception::class) - fun featuredRelationsAdd(request: Object.FeaturedRelation.Add.Request): Object.FeaturedRelation.Add.Response + fun blockDataViewViewDelete(request: Rpc.BlockDataview.View.Delete.Request): Rpc.BlockDataview.View.Delete.Response @Throws(Exception::class) - fun featuredRelationsRemove(request: Object.FeaturedRelation.Remove.Request): Object.FeaturedRelation.Remove.Response + fun blockDataViewRecordCreate(request: Rpc.BlockDataviewRecord.Create.Request): Rpc.BlockDataviewRecord.Create.Response @Throws(Exception::class) - fun objectSetIsFavorite(request: Object.SetIsFavorite.Request): Object.SetIsFavorite.Response + fun blockDataViewRecordUpdate(request: Rpc.BlockDataviewRecord.Update.Request): Rpc.BlockDataviewRecord.Update.Response @Throws(Exception::class) - fun objectSetIsArchived(request: Object.SetIsArchived.Request): Object.SetIsArchived.Response + fun blockDataViewRecordRelationOptionAdd(request: Rpc.BlockDataviewRecord.RelationOption.Add.Request): Rpc.BlockDataviewRecord.RelationOption.Add.Response @Throws(Exception::class) - fun objectListSetIsArchived(request: ObjectList.Set.IsArchived.Request): ObjectList.Set.IsArchived.Response + fun blockDataViewRelationAdd(request: Rpc.BlockDataview.Relation.Add.Request): Rpc.BlockDataview.Relation.Add.Response @Throws(Exception::class) - fun objectListDelete(request: ObjectList.Delete.Request): ObjectList.Delete.Response + fun blockDataViewRelationDelete(request: Rpc.BlockDataview.Relation.Delete.Request): Rpc.BlockDataview.Relation.Delete.Response + + //endregion + + //region TEXT BLOCK commands @Throws(Exception::class) - fun objectSetLayout(request: Object.SetLayout.Request): Object.SetLayout.Response + fun blockTextSetText(request: Rpc.BlockText.SetText.Request): Rpc.BlockText.SetText.Response @Throws(Exception::class) - fun exportLocalStore(request: ExportLocalstore.Request): ExportLocalstore.Response + fun blockTextSetChecked(request: Rpc.BlockText.SetChecked.Request): Rpc.BlockText.SetChecked.Response @Throws(Exception::class) - fun fileListOffload(request: FileList.Offload.Request): FileList.Offload.Response + fun blockTextListSetColor(request: Rpc.BlockText.ListSetColor.Request): Rpc.BlockText.ListSetColor.Response @Throws(Exception::class) - fun unsplashSearch(request: UnsplashSearch.Request) : UnsplashSearch.Response + fun blockTextListSetMark(request: Rpc.BlockText.ListSetMark.Request): Rpc.BlockText.ListSetMark.Response @Throws(Exception::class) - fun unsplashDownload(request: UnsplashDownload.Request) : UnsplashDownload.Response + fun blockTextListSetStyle(request: Rpc.BlockText.ListSetStyle.Request): Rpc.BlockText.ListSetStyle.Response + + //endregion + + //region DEBUG commands @Throws(Exception::class) - fun objectDuplicate(request: ObjectDuplicate.Request) : ObjectDuplicate.Response + fun debugSync(request: Rpc.Debug.Sync.Request): Rpc.Debug.Sync.Response @Throws(Exception::class) - fun applyTemplate(request: ApplyTemplate.Request): ApplyTemplate.Response + fun debugExportLocalStore(request: Rpc.Debug.ExportLocalstore.Request): Rpc.Debug.ExportLocalstore.Response + + //endregion } \ No newline at end of file diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareServiceImplementation.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareServiceImplementation.kt index 327b80d65b..defec87527 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareServiceImplementation.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/service/MiddlewareServiceImplementation.kt @@ -1,24 +1,6 @@ package com.anytypeio.anytype.middleware.service -import anytype.Rpc.Account -import anytype.Rpc.ApplyTemplate -import anytype.Rpc.Block -import anytype.Rpc.BlockList -import anytype.Rpc.Config -import anytype.Rpc.Debug -import anytype.Rpc.ExportLocalstore -import anytype.Rpc.FileList -import anytype.Rpc.Navigation -import anytype.Rpc.Object -import anytype.Rpc.ObjectDuplicate -import anytype.Rpc.ObjectList -import anytype.Rpc.ObjectType -import anytype.Rpc.Page -import anytype.Rpc.UnsplashDownload -import anytype.Rpc.UnsplashSearch -import anytype.Rpc.UploadFile -import anytype.Rpc.Version -import anytype.Rpc.Wallet +import anytype.Rpc import com.anytypeio.anytype.core_models.exceptions.AccountIsDeletedException import com.anytypeio.anytype.core_models.exceptions.CreateAccountException import com.anytypeio.anytype.data.auth.exception.BackwardCompatilityNotSupportedException @@ -28,63 +10,19 @@ import service.Service class MiddlewareServiceImplementation : MiddlewareService { - override fun configGet(request: Config.Get.Request): Config.Get.Response { - val encoded = Service.configGet(Config.Get.Request.ADAPTER.encode(request)) - val response = Config.Get.Response.ADAPTER.decode(encoded) + override fun accountCreate(request: Rpc.Account.Create.Request): Rpc.Account.Create.Response { + val encoded = Service.accountCreate(Rpc.Account.Create.Request.ADAPTER.encode(request)) + val response = Rpc.Account.Create.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Config.Get.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun walletCreate(request: Wallet.Create.Request): Wallet.Create.Response { - val encoded = Service.walletCreate(Wallet.Create.Request.ADAPTER.encode(request)) - val response = Wallet.Create.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Wallet.Create.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun walletConvert(request: Wallet.Convert.Request): Wallet.Convert.Response { - val encoded = Service.walletConvert(Wallet.Convert.Request.ADAPTER.encode(request)) - val response = Wallet.Convert.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Wallet.Convert.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun walletRecover(request: Wallet.Recover.Request): Wallet.Recover.Response { - val encoded = Service.walletRecover(Wallet.Recover.Request.ADAPTER.encode(request)) - val response = Wallet.Recover.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Wallet.Recover.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun accountCreate(request: Account.Create.Request): Account.Create.Response { - val encoded = Service.accountCreate(Account.Create.Request.ADAPTER.encode(request)) - val response = Account.Create.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Account.Create.Response.Error.Code.NULL) { - when(error.code) { - Account.Create.Response.Error.Code.NET_OFFLINE -> { + if (error != null && error.code != Rpc.Account.Create.Response.Error.Code.NULL) { + when (error.code) { + Rpc.Account.Create.Response.Error.Code.NET_OFFLINE -> { throw CreateAccountException.OfflineDevice } - Account.Create.Response.Error.Code.BAD_INVITE_CODE -> { + Rpc.Account.Create.Response.Error.Code.BAD_INVITE_CODE -> { throw CreateAccountException.BadInviteCode } - Account.Create.Response.Error.Code.NET_ERROR -> { + Rpc.Account.Create.Response.Error.Code.NET_ERROR -> { throw CreateAccountException.NetworkError } else -> throw Exception(error.description) @@ -94,35 +32,24 @@ class MiddlewareServiceImplementation : MiddlewareService { } } - override fun accountDelete(request: Account.Delete.Request): Account.Delete.Response { - val encoded = Service.accountDelete(Account.Delete.Request.ADAPTER.encode(request)) - val response = Account.Delete.Response.ADAPTER.decode(encoded) + override fun accountDelete(request: Rpc.Account.Delete.Request): Rpc.Account.Delete.Response { + val encoded = Service.accountDelete(Rpc.Account.Delete.Request.ADAPTER.encode(request)) + val response = Rpc.Account.Delete.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Account.Delete.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Account.Delete.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun accountSelect(request: Account.Select.Request): Account.Select.Response { - val encoded = Service.accountSelect(Account.Select.Request.ADAPTER.encode(request)) - val response = Account.Select.Response.ADAPTER.decode(encoded) + override fun accountRecover(request: Rpc.Account.Recover.Request): Rpc.Account.Recover.Response { + val encoded = Service.accountRecover(Rpc.Account.Recover.Request.ADAPTER.encode(request)) + val response = Rpc.Account.Recover.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Account.Select.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun accountRecover(request: Account.Recover.Request): Account.Recover.Response { - val encoded = Service.accountRecover(Account.Recover.Request.ADAPTER.encode(request)) - val response = Account.Recover.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Account.Recover.Response.Error.Code.NULL) { - when(error.code) { - Account.Recover.Response.Error.Code.ACCOUNT_IS_DELETED -> { + if (error != null && error.code != Rpc.Account.Recover.Response.Error.Code.NULL) { + when (error.code) { + Rpc.Account.Recover.Response.Error.Code.ACCOUNT_IS_DELETED -> { throw AccountIsDeletedException() } else -> { @@ -134,537 +61,96 @@ class MiddlewareServiceImplementation : MiddlewareService { } } - override fun accountStop(request: Account.Stop.Request): Account.Stop.Response { - val encoded = Service.accountStop(Account.Stop.Request.ADAPTER.encode(request)) - val response = Account.Stop.Response.ADAPTER.decode(encoded) + override fun accountSelect(request: Rpc.Account.Select.Request): Rpc.Account.Select.Response { + val encoded = Service.accountSelect(Rpc.Account.Select.Request.ADAPTER.encode(request)) + val response = Rpc.Account.Select.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Account.Stop.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Account.Select.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockOpen(request: Block.Open.Request): Block.Open.Response { - val encoded = Service.blockOpen(Block.Open.Request.ADAPTER.encode(request)) - val response = Block.Open.Response.ADAPTER.decode(encoded) + override fun accountStop(request: Rpc.Account.Stop.Request): Rpc.Account.Stop.Response { + val encoded = Service.accountStop(Rpc.Account.Stop.Request.ADAPTER.encode(request)) + val response = Rpc.Account.Stop.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.Open.Response.Error.Code.NULL) { - when (error.code) { - Block.Open.Response.Error.Code.NOT_FOUND -> throw NotFoundObjectException() - Block.Open.Response.Error.Code.ANYTYPE_NEEDS_UPGRADE -> - throw BackwardCompatilityNotSupportedException() - else -> throw Exception(error.description) - } - } else { - return response - } - } - - override fun blockShow(request: Block.Show.Request): Block.Show.Response { - val encoded = Service.blockShow(Block.Show.Request.ADAPTER.encode(request)) - val response = Block.Show.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Show.Response.Error.Code.NULL) { - when (error.code) { - Block.Show.Response.Error.Code.NOT_FOUND -> throw NotFoundObjectException() - Block.Show.Response.Error.Code.ANYTYPE_NEEDS_UPGRADE -> - throw BackwardCompatilityNotSupportedException() - else -> throw Exception(error.description) - } - } else { - return response - } - } - - override fun blockClose(request: Block.Close.Request): Block.Close.Response { - val encoded = Service.blockClose(Block.Close.Request.ADAPTER.encode(request)) - val response = Block.Close.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Close.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Account.Stop.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockCreate(request: Block.Create.Request): Block.Create.Response { - val encoded = Service.blockCreate(Block.Create.Request.ADAPTER.encode(request)) - val response = Block.Create.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Create.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockCreatePage(request: Block.CreatePage.Request): Block.CreatePage.Response { - val encoded = Service.blockCreatePage(Block.CreatePage.Request.ADAPTER.encode(request)) - val response = Block.CreatePage.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.CreatePage.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockSetTextText(request: Block.Set.Text.TText.Request): Block.Set.Text.TText.Response { - val encoded = Service.blockSetTextText(Block.Set.Text.TText.Request.ADAPTER.encode(request)) - val response = Block.Set.Text.TText.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Set.Text.TText.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockSetTextChecked(request: Block.Set.Text.Checked.Request): Block.Set.Text.Checked.Response { - val encoded = Service.blockSetTextChecked( - Block.Set.Text.Checked.Request.ADAPTER.encode(request) - ) - val response = Block.Set.Text.Checked.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Set.Text.Checked.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockSetTextColor(request: BlockList.Set.Text.Color.Request): BlockList.Set.Text.Color.Response { - val encoded = Service.blockListSetTextColor( - BlockList.Set.Text.Color.Request.ADAPTER.encode(request) - ) - val response = BlockList.Set.Text.Color.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Set.Text.Color.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockListSetBackgroundColor(request: BlockList.Set.BackgroundColor.Request): BlockList.Set.BackgroundColor.Response { - val encoded = Service.blockListSetBackgroundColor( - BlockList.Set.BackgroundColor.Request.ADAPTER.encode(request) - ) - val response = BlockList.Set.BackgroundColor.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Set.BackgroundColor.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockListSetAlign(request: BlockList.Set.Align.Request): BlockList.Set.Align.Response { - val encoded = Service.blockListSetAlign(BlockList.Set.Align.Request.ADAPTER.encode(request)) - val response = BlockList.Set.Align.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Set.Align.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockListSetTextStyle(request: BlockList.Set.Text.Style.Request): BlockList.Set.Text.Style.Response { - val encoded = - Service.blockListSetTextStyle(BlockList.Set.Text.Style.Request.ADAPTER.encode(request)) - val response = BlockList.Set.Text.Style.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Set.Text.Style.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockListSetDivStyle(request: BlockList.Set.Div.Style.Request): BlockList.Set.Div.Style.Response { - val encoded = - Service.blockListSetDivStyle(BlockList.Set.Div.Style.Request.ADAPTER.encode(request)) - val response = BlockList.Set.Div.Style.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Set.Div.Style.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockListMove(request: BlockList.Move.Request): BlockList.Move.Response { - val encoded = Service.blockListMove(BlockList.Move.Request.ADAPTER.encode(request)) - val response = BlockList.Move.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Move.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockUnlink(request: Block.Unlink.Request): Block.Unlink.Response { - val encoded = Service.blockUnlink(Block.Unlink.Request.ADAPTER.encode(request)) - val response = Block.Unlink.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Unlink.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockMerge(request: Block.Merge.Request): Block.Merge.Response { - val encoded = Service.blockMerge(Block.Merge.Request.ADAPTER.encode(request)) - val response = Block.Merge.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Merge.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockSplit(request: Block.Split.Request): Block.Split.Response { - val encoded = Service.blockSplit(Block.Split.Request.ADAPTER.encode(request)) - val response = Block.Split.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Split.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockListDuplicate(request: BlockList.Duplicate.Request): BlockList.Duplicate.Response { - val encoded = Service.blockListDuplicate( - BlockList.Duplicate.Request.ADAPTER.encode(request) - ) - val response = BlockList.Duplicate.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Duplicate.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun convertChildrenToPages(request: BlockList.ConvertChildrenToPages.Request): BlockList.ConvertChildrenToPages.Response { - val encoded = Service.blockListConvertChildrenToPages( - BlockList.ConvertChildrenToPages.Request.ADAPTER.encode(request) - ) - val response = BlockList.ConvertChildrenToPages.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.ConvertChildrenToPages.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockBookmarkFetch(request: Block.Bookmark.Fetch.Request): Block.Bookmark.Fetch.Response { - val encoded = Service.blockBookmarkFetch( - Block.Bookmark.Fetch.Request.ADAPTER.encode(request) - ) - val response = Block.Bookmark.Fetch.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Bookmark.Fetch.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockBookmarkCreateAndFetch(request: Block.Bookmark.CreateAndFetch.Request): Block.Bookmark.CreateAndFetch.Response { + override fun blockBookmarkCreateAndFetch(request: Rpc.BlockBookmark.CreateAndFetch.Request): Rpc.BlockBookmark.CreateAndFetch.Response { val encoded = Service.blockBookmarkCreateAndFetch( - Block.Bookmark.CreateAndFetch.Request.ADAPTER.encode(request) + Rpc.BlockBookmark.CreateAndFetch.Request.ADAPTER.encode(request) ) - val response = Block.Bookmark.CreateAndFetch.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockBookmark.CreateAndFetch.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.Bookmark.CreateAndFetch.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockBookmark.CreateAndFetch.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockUpload(request: Block.Upload.Request): Block.Upload.Response { - val encoded = Service.blockUpload(Block.Upload.Request.ADAPTER.encode(request)) - val response = Block.Upload.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Upload.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockUndo(request: Block.Undo.Request): Block.Undo.Response { - val encoded = Service.blockUndo(Block.Undo.Request.ADAPTER.encode(request)) - val response = Block.Undo.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Undo.Response.Error.Code.NULL) { - if (error.code == Block.Undo.Response.Error.Code.CAN_NOT_MOVE) - throw UndoRedoExhaustedException() - else - throw Exception(error.description) - } else { - return response - } - } - - override fun blockRedo(request: Block.Redo.Request): Block.Redo.Response { - val encoded = Service.blockRedo(Block.Redo.Request.ADAPTER.encode(request)) - val response = Block.Redo.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Redo.Response.Error.Code.NULL) { - if (error.code == Block.Redo.Response.Error.Code.CAN_NOT_MOVE) - throw UndoRedoExhaustedException() - else - throw Exception(error.description) - } else { - return response - } - } - - override fun blockSetDetails(request: Block.Set.Details.Request): Block.Set.Details.Response { - val encoded = Service.blockSetDetails(Block.Set.Details.Request.ADAPTER.encode(request)) - val response = Block.Set.Details.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Set.Details.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockPaste(request: Block.Paste.Request): Block.Paste.Response { - val encoded = Service.blockPaste(Block.Paste.Request.ADAPTER.encode(request)) - val response = Block.Paste.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Paste.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockCopy(request: Block.Copy.Request): Block.Copy.Response { - val encoded = Service.blockCopy(Block.Copy.Request.ADAPTER.encode(request)) - val response = Block.Copy.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Copy.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun uploadFile(request: UploadFile.Request): UploadFile.Response { - val encoded = Service.uploadFile(UploadFile.Request.ADAPTER.encode(request)) - val response = UploadFile.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != UploadFile.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun objectInfoWithLinks(request: Navigation.GetObjectInfoWithLinks.Request): Navigation.GetObjectInfoWithLinks.Response { - val encoded = Service.navigationGetObjectInfoWithLinks( - Navigation.GetObjectInfoWithLinks.Request.ADAPTER.encode(request) + override fun blockBookmarkFetch(request: Rpc.BlockBookmark.Fetch.Request): Rpc.BlockBookmark.Fetch.Response { + val encoded = Service.blockBookmarkFetch( + Rpc.BlockBookmark.Fetch.Request.ADAPTER.encode(request) ) - val response = Navigation.GetObjectInfoWithLinks.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockBookmark.Fetch.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Navigation.GetObjectInfoWithLinks.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockBookmark.Fetch.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun listObjects(request: Navigation.ListObjects.Request): Navigation.ListObjects.Response { - val encoded = - Service.navigationListObjects(Navigation.ListObjects.Request.ADAPTER.encode(request)) - val response = Navigation.ListObjects.Response.ADAPTER.decode(encoded) + override fun blockCopy(request: Rpc.Block.Copy.Request): Rpc.Block.Copy.Response { + val encoded = Service.blockCopy(Rpc.Block.Copy.Request.ADAPTER.encode(request)) + val response = Rpc.Block.Copy.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Navigation.ListObjects.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Block.Copy.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun pageCreate(request: Page.Create.Request): Page.Create.Response { - val encoded = Service.pageCreate(Page.Create.Request.ADAPTER.encode(request)) - val response = Page.Create.Response.ADAPTER.decode(encoded) + override fun blockCreate(request: Rpc.Block.Create.Request): Rpc.Block.Create.Response { + val encoded = Service.blockCreate(Rpc.Block.Create.Request.ADAPTER.encode(request)) + val response = Rpc.Block.Create.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Page.Create.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Block.Create.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun versionGet(request: Version.Get.Request): Version.Get.Response { - val encoded = Service.versionGet(Version.Get.Request.ADAPTER.encode(request)) - val response = Version.Get.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Version.Get.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockListSetFields(request: BlockList.Set.Fields.Request): BlockList.Set.Fields.Response { - val encoded = Service.blockListSetFields( - BlockList.Set.Fields.Request.ADAPTER.encode(request) - ) - val response = BlockList.Set.Fields.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != BlockList.Set.Fields.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun objectTypeList(request: ObjectType.List.Request): ObjectType.List.Response { - val encoded = Service.objectTypeList(ObjectType.List.Request.ADAPTER.encode(request)) - val response = ObjectType.List.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != ObjectType.List.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun objectTypeCreate(request: ObjectType.Create.Request): ObjectType.Create.Response { - val encoded = Service.objectTypeCreate(ObjectType.Create.Request.ADAPTER.encode(request)) - val response = ObjectType.Create.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != ObjectType.Create.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockCreateSet(request: Block.CreateSet.Request): Block.CreateSet.Response { - val encoded = Service.blockCreateSet(Block.CreateSet.Request.ADAPTER.encode(request)) - val response = Block.CreateSet.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.CreateSet.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockDataViewActiveSet(request: Block.Dataview.ViewSetActive.Request): Block.Dataview.ViewSetActive.Response { + override fun blockDataViewActiveSet(request: Rpc.BlockDataview.View.SetActive.Request): Rpc.BlockDataview.View.SetActive.Response { val encoded = Service.blockDataviewViewSetActive( - Block.Dataview.ViewSetActive.Request.ADAPTER.encode(request) + Rpc.BlockDataview.View.SetActive.Request.ADAPTER.encode(request) ) - val response = Block.Dataview.ViewSetActive.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataview.View.SetActive.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.Dataview.ViewSetActive.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataview.View.SetActive.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockDataViewRelationAdd(request: Block.Dataview.RelationAdd.Request): Block.Dataview.RelationAdd.Response { - val encoded = Service.blockDataviewRelationAdd( - Block.Dataview.RelationAdd.Request.ADAPTER.encode(request) - ) - val response = Block.Dataview.RelationAdd.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Dataview.RelationAdd.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockDataViewRelationDelete(request: Block.Dataview.RelationDelete.Request): Block.Dataview.RelationDelete.Response { - val encoded = Service.blockDataviewRelationDelete( - Block.Dataview.RelationDelete.Request.ADAPTER.encode(request) - ) - val response = Block.Dataview.RelationDelete.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Dataview.RelationDelete.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockDataViewRecordCreate(request: Block.Dataview.RecordCreate.Request): Block.Dataview.RecordCreate.Response { + override fun blockDataViewRecordCreate(request: Rpc.BlockDataviewRecord.Create.Request): Rpc.BlockDataviewRecord.Create.Response { val encoded = Service.blockDataviewRecordCreate( - Block.Dataview.RecordCreate.Request.ADAPTER.encode(request) + Rpc.BlockDataviewRecord.Create.Request.ADAPTER.encode(request) ) - val response = Block.Dataview.RecordCreate.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataviewRecord.Create.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.Dataview.RecordCreate.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockDataViewViewUpdate(request: Block.Dataview.ViewUpdate.Request): Block.Dataview.ViewUpdate.Response { - val encoded = Service.blockDataviewViewUpdate( - Block.Dataview.ViewUpdate.Request.ADAPTER.encode(request) - ) - val response = Block.Dataview.ViewUpdate.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Dataview.ViewUpdate.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockDataViewViewDelete(request: Block.Dataview.ViewDelete.Request): Block.Dataview.ViewDelete.Response { - val encoded = Service.blockDataviewViewDelete( - Block.Dataview.ViewDelete.Request.ADAPTER.encode(request) - ) - val response = Block.Dataview.ViewDelete.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Dataview.ViewDelete.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockDataViewRecordUpdate(request: Block.Dataview.RecordUpdate.Request): Block.Dataview.RecordUpdate.Response { - val encoded = Service.blockDataviewRecordUpdate( - Block.Dataview.RecordUpdate.Request.ADAPTER.encode(request) - ) - val response = Block.Dataview.RecordUpdate.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Dataview.RecordUpdate.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun blockDataViewViewCreate(request: Block.Dataview.ViewCreate.Request): Block.Dataview.ViewCreate.Response { - val encoded = Service.blockDataviewViewCreate( - Block.Dataview.ViewCreate.Request.ADAPTER.encode(request) - ) - val response = Block.Dataview.ViewCreate.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Block.Dataview.ViewCreate.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataviewRecord.Create.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response @@ -672,354 +158,851 @@ class MiddlewareServiceImplementation : MiddlewareService { } override fun blockDataViewRecordRelationOptionAdd( - request: Block.Dataview.RecordRelationOptionAdd.Request - ): Block.Dataview.RecordRelationOptionAdd.Response { + request: Rpc.BlockDataviewRecord.RelationOption.Add.Request + ): Rpc.BlockDataviewRecord.RelationOption.Add.Response { val encoded = Service.blockDataviewRecordRelationOptionAdd( - Block.Dataview.RecordRelationOptionAdd.Request.ADAPTER.encode(request) + Rpc.BlockDataviewRecord.RelationOption.Add.Request.ADAPTER.encode(request) ) - val response = Block.Dataview.RecordRelationOptionAdd.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataviewRecord.RelationOption.Add.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.Dataview.RecordRelationOptionAdd.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataviewRecord.RelationOption.Add.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectRelationOptionAdd(request: Object.RelationOptionAdd.Request): Object.RelationOptionAdd.Response { - val encoded = Service.objectRelationOptionAdd( - Object.RelationOptionAdd.Request.ADAPTER.encode(request) + override fun blockDataViewRecordUpdate(request: Rpc.BlockDataviewRecord.Update.Request): Rpc.BlockDataviewRecord.Update.Response { + val encoded = Service.blockDataviewRecordUpdate( + Rpc.BlockDataviewRecord.Update.Request.ADAPTER.encode(request) ) - val response = Object.RelationOptionAdd.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataviewRecord.Update.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.RelationOptionAdd.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataviewRecord.Update.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectSearch(request: Object.Search.Request): Object.Search.Response { - val encoded = Service.objectSearch(Object.Search.Request.ADAPTER.encode(request)) - val response = Object.Search.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Object.Search.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun objectSearchSubscribe(request: Object.SearchSubscribe.Request): Object.SearchSubscribe.Response { - val encoded = Service.objectSearchSubscribe(Object.SearchSubscribe.Request.ADAPTER.encode(request)) - val response = Object.SearchSubscribe.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Object.SearchSubscribe.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun objectIdsSubscribe(request: Object.IdsSubscribe.Request): Object.IdsSubscribe.Response { - val encoded = Service.objectIdsSubscribe(Object.IdsSubscribe.Request.ADAPTER.encode(request)) - val response = Object.IdsSubscribe.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Object.IdsSubscribe.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun objectSearchUnsubscribe(request: Object.SearchUnsubscribe.Request): Object.SearchUnsubscribe.Response { - val encoded = Service.objectSearchUnsubscribe(Object.SearchUnsubscribe.Request.ADAPTER.encode(request)) - val response = Object.SearchUnsubscribe.Response.ADAPTER.decode(encoded) - val error = response.error - if (error != null && error.code != Object.SearchUnsubscribe.Response.Error.Code.NULL) { - throw Exception(error.description) - } else { - return response - } - } - - override fun relationListAvailable(request: Object.RelationListAvailable.Request): Object.RelationListAvailable.Response { - val encoded = Service.objectRelationListAvailable( - Object.RelationListAvailable.Request.ADAPTER.encode(request) + override fun blockDataViewRelationAdd(request: Rpc.BlockDataview.Relation.Add.Request): Rpc.BlockDataview.Relation.Add.Response { + val encoded = Service.blockDataviewRelationAdd( + Rpc.BlockDataview.Relation.Add.Request.ADAPTER.encode(request) ) - val response = Object.RelationListAvailable.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataview.Relation.Add.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.RelationListAvailable.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataview.Relation.Add.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectRelationAdd(request: Object.RelationAdd.Request): Object.RelationAdd.Response { - val encoded = Service.objectRelationAdd( - Object.RelationAdd.Request.ADAPTER.encode(request) + override fun blockDataViewRelationDelete(request: Rpc.BlockDataview.Relation.Delete.Request): Rpc.BlockDataview.Relation.Delete.Response { + val encoded = Service.blockDataviewRelationDelete( + Rpc.BlockDataview.Relation.Delete.Request.ADAPTER.encode(request) ) - val response = Object.RelationAdd.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataview.Relation.Delete.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.RelationAdd.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataview.Relation.Delete.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectRelationDelete(request: Object.RelationDelete.Request): Object.RelationDelete.Response { - val encoded = Service.objectRelationDelete( - Object.RelationDelete.Request.ADAPTER.encode(request) + override fun blockDataViewViewCreate(request: Rpc.BlockDataview.View.Create.Request): Rpc.BlockDataview.View.Create.Response { + val encoded = Service.blockDataviewViewCreate( + Rpc.BlockDataview.View.Create.Request.ADAPTER.encode(request) ) - val response = Object.RelationDelete.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataview.View.Create.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.RelationDelete.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataview.View.Create.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockAddRelation(request: Block.Relation.Add.Request): Block.Relation.Add.Response { - val encoded = Service.blockRelationAdd( - Block.Relation.Add.Request.ADAPTER.encode(request) + override fun blockDataViewViewDelete(request: Rpc.BlockDataview.View.Delete.Request): Rpc.BlockDataview.View.Delete.Response { + val encoded = Service.blockDataviewViewDelete( + Rpc.BlockDataview.View.Delete.Request.ADAPTER.encode(request) ) - val response = Block.Relation.Add.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockDataview.View.Delete.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.Relation.Add.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataview.View.Delete.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun debugSync(request: Debug.Sync.Request): Debug.Sync.Response { - val encoded = Service.debugSync(Debug.Sync.Request.ADAPTER.encode(request)) - val response = Debug.Sync.Response.ADAPTER.decode(encoded) + override fun blockDataViewViewUpdate(request: Rpc.BlockDataview.View.Update.Request): Rpc.BlockDataview.View.Update.Response { + val encoded = Service.blockDataviewViewUpdate( + Rpc.BlockDataview.View.Update.Request.ADAPTER.encode(request) + ) + val response = Rpc.BlockDataview.View.Update.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Debug.Sync.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockDataview.View.Update.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun relationSetKey(request: Block.Relation.SetKey.Request): Block.Relation.SetKey.Response { + override fun blockLinkCreateWithObject(request: Rpc.BlockLink.CreateWithObject.Request): Rpc.BlockLink.CreateWithObject.Response { + val encoded = Service.blockLinkCreateWithObject( + Rpc.BlockLink.CreateWithObject.Request.ADAPTER.encode(request) + ) + val response = Rpc.BlockLink.CreateWithObject.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.BlockLink.CreateWithObject.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListDelete(request: Rpc.Block.ListDelete.Request): Rpc.Block.ListDelete.Response { + val encoded = Service.blockListDelete(Rpc.Block.ListDelete.Request.ADAPTER.encode(request)) + val response = Rpc.Block.ListDelete.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Block.ListDelete.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListDuplicate(request: Rpc.Block.ListDuplicate.Request): Rpc.Block.ListDuplicate.Response { + val encoded = Service.blockListDuplicate( + Rpc.Block.ListDuplicate.Request.ADAPTER.encode(request) + ) + val response = Rpc.Block.ListDuplicate.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Block.ListDuplicate.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListMoveToExistingObject(request: Rpc.Block.ListMoveToExistingObject.Request): Rpc.Block.ListMoveToExistingObject.Response { + val encoded = Service.blockListMoveToExistingObject( + Rpc.Block.ListMoveToExistingObject.Request.ADAPTER.encode(request) + ) + val response = Rpc.Block.ListMoveToExistingObject.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Block.ListMoveToExistingObject.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListMoveToNewObject(request: Rpc.Block.ListMoveToNewObject.Request): Rpc.Block.ListMoveToNewObject.Response { + val encoded = Service.blockListMoveToNewObject( + Rpc.Block.ListMoveToNewObject.Request.ADAPTER.encode(request) + ) + val response = Rpc.Block.ListMoveToNewObject.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Block.ListMoveToNewObject.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListSetAlign(request: Rpc.Block.ListSetAlign.Request): Rpc.Block.ListSetAlign.Response { val encoded = - Service.blockRelationSetKey(Block.Relation.SetKey.Request.ADAPTER.encode(request)) - val response = Block.Relation.SetKey.Response.ADAPTER.decode(encoded) + Service.blockListSetAlign(Rpc.Block.ListSetAlign.Request.ADAPTER.encode(request)) + val response = Rpc.Block.ListSetAlign.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.Relation.SetKey.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Block.ListSetAlign.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockListTurnInto(request: BlockList.TurnInto.Request): BlockList.TurnInto.Response { + override fun blockListSetBackgroundColor(request: Rpc.Block.ListSetBackgroundColor.Request): Rpc.Block.ListSetBackgroundColor.Response { + val encoded = Service.blockListSetBackgroundColor( + Rpc.Block.ListSetBackgroundColor.Request.ADAPTER.encode(request) + ) + val response = Rpc.Block.ListSetBackgroundColor.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Block.ListSetBackgroundColor.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListSetDivStyle(request: Rpc.BlockDiv.ListSetStyle.Request): Rpc.BlockDiv.ListSetStyle.Response { + val encoded = + Service.blockDivListSetStyle(Rpc.BlockDiv.ListSetStyle.Request.ADAPTER.encode(request)) + val response = Rpc.BlockDiv.ListSetStyle.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.BlockDiv.ListSetStyle.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListSetFields(request: Rpc.Block.ListSetFields.Request): Rpc.Block.ListSetFields.Response { + val encoded = Service.blockListSetFields( + Rpc.Block.ListSetFields.Request.ADAPTER.encode(request) + ) + val response = Rpc.Block.ListSetFields.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Block.ListSetFields.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun blockListTurnInto(request: Rpc.Block.ListTurnInto.Request): Rpc.Block.ListTurnInto.Response { val encoded = Service.blockListTurnInto( - BlockList.TurnInto.Request.ADAPTER.encode(request) + Rpc.Block.ListTurnInto.Request.ADAPTER.encode(request) ) - val response = BlockList.TurnInto.Response.ADAPTER.decode(encoded) + val response = Rpc.Block.ListTurnInto.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != BlockList.TurnInto.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Block.ListTurnInto.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockListSetTextMark(request: BlockList.Set.Text.Mark.Request): BlockList.Set.Text.Mark.Response { - val encoded = Service.blockListSetTextMark( - BlockList.Set.Text.Mark.Request.ADAPTER.encode(request) - ) - val response = BlockList.Set.Text.Mark.Response.ADAPTER.decode(encoded) + override fun blockMerge(request: Rpc.Block.Merge.Request): Rpc.Block.Merge.Response { + val encoded = Service.blockMerge(Rpc.Block.Merge.Request.ADAPTER.encode(request)) + val response = Rpc.Block.Merge.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != BlockList.Set.Text.Mark.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Block.Merge.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun blockSetObjectType(request: Block.ObjectType.Set.Request): Block.ObjectType.Set.Response { - val encoded = Service.blockObjectTypeSet( - Block.ObjectType.Set.Request.ADAPTER.encode(request) - ) - val response = Block.ObjectType.Set.Response.ADAPTER.decode(encoded) + override fun blockPaste(request: Rpc.Block.Paste.Request): Rpc.Block.Paste.Response { + val encoded = Service.blockPaste(Rpc.Block.Paste.Request.ADAPTER.encode(request)) + val response = Rpc.Block.Paste.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Block.ObjectType.Set.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Block.Paste.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun featuredRelationsAdd(request: Object.FeaturedRelation.Add.Request): Object.FeaturedRelation.Add.Response { - val encoded = Service.objectFeaturedRelationAdd( - Object.FeaturedRelation.Add.Request.ADAPTER.encode(request) + override fun blockRelationAdd(request: Rpc.BlockRelation.Add.Request): Rpc.BlockRelation.Add.Response { + val encoded = Service.blockRelationAdd( + Rpc.BlockRelation.Add.Request.ADAPTER.encode(request) ) - val response = Object.FeaturedRelation.Add.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockRelation.Add.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.FeaturedRelation.Add.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockRelation.Add.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun featuredRelationsRemove(request: Object.FeaturedRelation.Remove.Request): Object.FeaturedRelation.Remove.Response { - val encoded = Service.objectFeaturedRelationRemove( - Object.FeaturedRelation.Remove.Request.ADAPTER.encode(request) - ) - val response = Object.FeaturedRelation.Remove.Response.ADAPTER.decode(encoded) + override fun blockRelationSetKey(request: Rpc.BlockRelation.SetKey.Request): Rpc.BlockRelation.SetKey.Response { + val encoded = + Service.blockRelationSetKey(Rpc.BlockRelation.SetKey.Request.ADAPTER.encode(request)) + val response = Rpc.BlockRelation.SetKey.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.FeaturedRelation.Remove.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockRelation.SetKey.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectSetIsFavorite(request: Object.SetIsFavorite.Request): Object.SetIsFavorite.Response { - val encoded = Service.objectSetIsFavorite( - Object.SetIsFavorite.Request.ADAPTER.encode(request) - ) - val response = Object.SetIsFavorite.Response.ADAPTER.decode(encoded) + override fun blockSplit(request: Rpc.Block.Split.Request): Rpc.Block.Split.Response { + val encoded = Service.blockSplit(Rpc.Block.Split.Request.ADAPTER.encode(request)) + val response = Rpc.Block.Split.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.SetIsFavorite.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Block.Split.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectSetIsArchived(request: Object.SetIsArchived.Request): Object.SetIsArchived.Response { - val encoded = Service.objectSetIsArchived( - Object.SetIsArchived.Request.ADAPTER.encode(request) + override fun blockTextListSetColor(request: Rpc.BlockText.ListSetColor.Request): Rpc.BlockText.ListSetColor.Response { + val encoded = Service.blockTextListSetColor( + Rpc.BlockText.ListSetColor.Request.ADAPTER.encode(request) ) - val response = Object.SetIsArchived.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockText.ListSetColor.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.SetIsArchived.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockText.ListSetColor.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectListSetIsArchived(request: ObjectList.Set.IsArchived.Request): ObjectList.Set.IsArchived.Response { - val encoded = Service.objectListSetIsArchived( - ObjectList.Set.IsArchived.Request.ADAPTER.encode(request) + override fun blockTextListSetMark(request: Rpc.BlockText.ListSetMark.Request): Rpc.BlockText.ListSetMark.Response { + val encoded = Service.blockTextListSetMark( + Rpc.BlockText.ListSetMark.Request.ADAPTER.encode(request) ) - val response = ObjectList.Set.IsArchived.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockText.ListSetMark.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != ObjectList.Set.IsArchived.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockText.ListSetMark.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectListDelete(request: ObjectList.Delete.Request): ObjectList.Delete.Response { - val encoded = Service.objectListDelete( - ObjectList.Delete.Request.ADAPTER.encode(request) - ) - val response = ObjectList.Delete.Response.ADAPTER.decode(encoded) + override fun blockTextListSetStyle(request: Rpc.BlockText.ListSetStyle.Request): Rpc.BlockText.ListSetStyle.Response { + val encoded = + Service.blockTextListSetStyle(Rpc.BlockText.ListSetStyle.Request.ADAPTER.encode(request)) + val response = Rpc.BlockText.ListSetStyle.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != ObjectList.Delete.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockText.ListSetStyle.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectSetLayout(request: Object.SetLayout.Request): Object.SetLayout.Response { - val encoded = Service.objectSetLayout( - Object.SetLayout.Request.ADAPTER.encode(request) + override fun blockTextSetChecked(request: Rpc.BlockText.SetChecked.Request): Rpc.BlockText.SetChecked.Response { + val encoded = Service.blockTextSetChecked( + Rpc.BlockText.SetChecked.Request.ADAPTER.encode(request) ) - val response = Object.SetLayout.Response.ADAPTER.decode(encoded) + val response = Rpc.BlockText.SetChecked.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != Object.SetLayout.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockText.SetChecked.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun exportLocalStore(request: ExportLocalstore.Request): ExportLocalstore.Response { - val encoded = Service.exportLocalstore( - ExportLocalstore.Request.ADAPTER.encode(request) - ) - val response = ExportLocalstore.Response.ADAPTER.decode(encoded) + override fun blockTextSetText(request: Rpc.BlockText.SetText.Request): Rpc.BlockText.SetText.Response { + val encoded = + Service.blockTextSetText(Rpc.BlockText.SetText.Request.ADAPTER.encode(request)) + val response = Rpc.BlockText.SetText.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != ExportLocalstore.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.BlockText.SetText.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun fileListOffload(request: FileList.Offload.Request): FileList.Offload.Response { + override fun blockUpload(request: Rpc.Block.Upload.Request): Rpc.Block.Upload.Response { + val encoded = Service.blockUpload(Rpc.Block.Upload.Request.ADAPTER.encode(request)) + val response = Rpc.Block.Upload.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Block.Upload.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun debugExportLocalStore(request: Rpc.Debug.ExportLocalstore.Request): Rpc.Debug.ExportLocalstore.Response { + val encoded = Service.debugExportLocalstore( + Rpc.Debug.ExportLocalstore.Request.ADAPTER.encode(request) + ) + val response = Rpc.Debug.ExportLocalstore.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Debug.ExportLocalstore.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun debugSync(request: Rpc.Debug.Sync.Request): Rpc.Debug.Sync.Response { + val encoded = Service.debugSync(Rpc.Debug.Sync.Request.ADAPTER.encode(request)) + val response = Rpc.Debug.Sync.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Debug.Sync.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun fileListOffload(request: Rpc.File.ListOffload.Request): Rpc.File.ListOffload.Response { val encoded = Service.fileListOffload( - FileList.Offload.Request.ADAPTER.encode(request) + Rpc.File.ListOffload.Request.ADAPTER.encode(request) ) - val response = FileList.Offload.Response.ADAPTER.decode(encoded) + val response = Rpc.File.ListOffload.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != FileList.Offload.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.File.ListOffload.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun unsplashSearch(request: UnsplashSearch.Request): UnsplashSearch.Response { - val encoded = Service.unsplashSearch( - UnsplashSearch.Request.ADAPTER.encode(request) - ) - val response = UnsplashSearch.Response.ADAPTER.decode(encoded) + override fun fileUpload(request: Rpc.File.Upload.Request): Rpc.File.Upload.Response { + val encoded = Service.fileUpload(Rpc.File.Upload.Request.ADAPTER.encode(request)) + val response = Rpc.File.Upload.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != UnsplashSearch.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.File.Upload.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun unsplashDownload(request: UnsplashDownload.Request): UnsplashDownload.Response { - val encoded = Service.unsplashDownload( - UnsplashDownload.Request.ADAPTER.encode(request) - ) - val response = UnsplashDownload.Response.ADAPTER.decode(encoded) + override fun navigationListObjects(request: Rpc.Navigation.ListObjects.Request): Rpc.Navigation.ListObjects.Response { + val encoded = + Service.navigationListObjects(Rpc.Navigation.ListObjects.Request.ADAPTER.encode(request)) + val response = Rpc.Navigation.ListObjects.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != UnsplashDownload.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Navigation.ListObjects.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun objectDuplicate(request: ObjectDuplicate.Request): ObjectDuplicate.Response { + override fun objectApplyTemplate(request: Rpc.Object.ApplyTemplate.Request): Rpc.Object.ApplyTemplate.Response { + val encoded = Service.objectApplyTemplate( + Rpc.Object.ApplyTemplate.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.ApplyTemplate.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.ApplyTemplate.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectClose(request: Rpc.Object.Close.Request): Rpc.Object.Close.Response { + val encoded = Service.objectClose(Rpc.Object.Close.Request.ADAPTER.encode(request)) + val response = Rpc.Object.Close.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.Close.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectCreate(request: Rpc.Object.Create.Request): Rpc.Object.Create.Response { + val encoded = Service.blockCreate(Rpc.Object.Create.Request.ADAPTER.encode(request)) + val response = Rpc.Object.Create.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.Create.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectCreateSet(request: Rpc.Object.CreateSet.Request): Rpc.Object.CreateSet.Response { + val encoded = Service.objectCreateSet(Rpc.Object.CreateSet.Request.ADAPTER.encode(request)) + val response = Rpc.Object.CreateSet.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.CreateSet.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectDuplicate(request: Rpc.Object.Duplicate.Request): Rpc.Object.Duplicate.Response { val encoded = Service.objectDuplicate( - ObjectDuplicate.Request.ADAPTER.encode(request) + Rpc.Object.Duplicate.Request.ADAPTER.encode(request) ) - val response = ObjectDuplicate.Response.ADAPTER.decode(encoded) + val response = Rpc.Object.Duplicate.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != ObjectDuplicate.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Object.Duplicate.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response } } - override fun applyTemplate(request: ApplyTemplate.Request): ApplyTemplate.Response { - val encoded = Service.applyTemplate( - ApplyTemplate.Request.ADAPTER.encode(request) - ) - val response = ApplyTemplate.Response.ADAPTER.decode(encoded) + override fun objectIdsSubscribe(request: Rpc.Object.SubscribeIds.Request): Rpc.Object.SubscribeIds.Response { + val encoded = + Service.objectSubscribeIds(Rpc.Object.SubscribeIds.Request.ADAPTER.encode(request)) + val response = Rpc.Object.SubscribeIds.Response.ADAPTER.decode(encoded) val error = response.error - if (error != null && error.code != ApplyTemplate.Response.Error.Code.NULL) { + if (error != null && error.code != Rpc.Object.SubscribeIds.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun navigationGetObjectInfoWithLinks(request: Rpc.Navigation.GetObjectInfoWithLinks.Request): Rpc.Navigation.GetObjectInfoWithLinks.Response { + val encoded = Service.navigationGetObjectInfoWithLinks( + Rpc.Navigation.GetObjectInfoWithLinks.Request.ADAPTER.encode(request) + ) + val response = Rpc.Navigation.GetObjectInfoWithLinks.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Navigation.GetObjectInfoWithLinks.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectListDelete(request: Rpc.Object.ListDelete.Request): Rpc.Object.ListDelete.Response { + val encoded = Service.objectListDelete( + Rpc.Object.ListDelete.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.ListDelete.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.ListDelete.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectListSetIsArchived(request: Rpc.Object.ListSetIsArchived.Request): Rpc.Object.ListSetIsArchived.Response { + val encoded = Service.objectListSetIsArchived( + Rpc.Object.ListSetIsArchived.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.ListSetIsArchived.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.ListSetIsArchived.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectOpen(request: Rpc.Object.Open.Request): Rpc.Object.Open.Response { + val encoded = Service.objectOpen(Rpc.Object.Open.Request.ADAPTER.encode(request)) + val response = Rpc.Object.Open.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.Open.Response.Error.Code.NULL) { + when (error.code) { + Rpc.Object.Open.Response.Error.Code.NOT_FOUND -> throw NotFoundObjectException() + Rpc.Object.Open.Response.Error.Code.ANYTYPE_NEEDS_UPGRADE -> + throw BackwardCompatilityNotSupportedException() + else -> throw Exception(error.description) + } + } else { + return response + } + } + + override fun objectRedo(request: Rpc.Object.Redo.Request): Rpc.Object.Redo.Response { + val encoded = Service.objectRedo(Rpc.Object.Redo.Request.ADAPTER.encode(request)) + val response = Rpc.Object.Redo.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.Redo.Response.Error.Code.NULL) { + if (error.code == Rpc.Object.Redo.Response.Error.Code.CAN_NOT_MOVE) + throw UndoRedoExhaustedException() + else + throw Exception(error.description) + } else { + return response + } + } + + override fun objectRelationAdd(request: Rpc.ObjectRelation.Add.Request): Rpc.ObjectRelation.Add.Response { + val encoded = Service.objectRelationAdd( + Rpc.ObjectRelation.Add.Request.ADAPTER.encode(request) + ) + val response = Rpc.ObjectRelation.Add.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectRelation.Add.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectRelationAddFeatured(request: Rpc.ObjectRelation.AddFeatured.Request): Rpc.ObjectRelation.AddFeatured.Response { + val encoded = Service.objectRelationAddFeatured( + Rpc.ObjectRelation.AddFeatured.Request.ADAPTER.encode(request) + ) + val response = Rpc.ObjectRelation.AddFeatured.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectRelation.AddFeatured.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectRelationDelete(request: Rpc.ObjectRelation.Delete.Request): Rpc.ObjectRelation.Delete.Response { + val encoded = Service.objectRelationDelete( + Rpc.ObjectRelation.Delete.Request.ADAPTER.encode(request) + ) + val response = Rpc.ObjectRelation.Delete.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectRelation.Delete.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectRelationListAvailable(request: Rpc.ObjectRelation.ListAvailable.Request): Rpc.ObjectRelation.ListAvailable.Response { + val encoded = Service.objectRelationListAvailable( + Rpc.ObjectRelation.ListAvailable.Request.ADAPTER.encode(request) + ) + val response = Rpc.ObjectRelation.ListAvailable.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectRelation.ListAvailable.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectRelationOptionAdd(request: Rpc.ObjectRelationOption.Add.Request): Rpc.ObjectRelationOption.Add.Response { + val encoded = Service.objectRelationOptionAdd( + Rpc.ObjectRelationOption.Add.Request.ADAPTER.encode(request) + ) + val response = Rpc.ObjectRelationOption.Add.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectRelationOption.Add.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectRelationRemoveFeatured(request: Rpc.ObjectRelation.RemoveFeatured.Request): Rpc.ObjectRelation.RemoveFeatured.Response { + val encoded = Service.objectRelationRemoveFeatured( + Rpc.ObjectRelation.RemoveFeatured.Request.ADAPTER.encode(request) + ) + val response = Rpc.ObjectRelation.RemoveFeatured.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectRelation.RemoveFeatured.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSearch(request: Rpc.Object.Search.Request): Rpc.Object.Search.Response { + val encoded = Service.objectSearch(Rpc.Object.Search.Request.ADAPTER.encode(request)) + val response = Rpc.Object.Search.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.Search.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSearchSubscribe(request: Rpc.Object.SearchSubscribe.Request): Rpc.Object.SearchSubscribe.Response { + val encoded = + Service.objectSearchSubscribe(Rpc.Object.SearchSubscribe.Request.ADAPTER.encode(request)) + val response = Rpc.Object.SearchSubscribe.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.SearchSubscribe.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSearchUnsubscribe(request: Rpc.Object.SearchUnsubscribe.Request): Rpc.Object.SearchUnsubscribe.Response { + val encoded = Service.objectSearchUnsubscribe( + Rpc.Object.SearchUnsubscribe.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.SearchUnsubscribe.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.SearchUnsubscribe.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSetDetails(request: Rpc.Object.SetDetails.Request): Rpc.Object.SetDetails.Response { + val encoded = + Service.objectSetDetails(Rpc.Object.SetDetails.Request.ADAPTER.encode(request)) + val response = Rpc.Object.SetDetails.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.SetDetails.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSetIsArchived(request: Rpc.Object.SetIsArchived.Request): Rpc.Object.SetIsArchived.Response { + val encoded = Service.objectSetIsArchived( + Rpc.Object.SetIsArchived.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.SetIsArchived.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.SetIsArchived.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSetIsFavorite(request: Rpc.Object.SetIsFavorite.Request): Rpc.Object.SetIsFavorite.Response { + val encoded = Service.objectSetIsFavorite( + Rpc.Object.SetIsFavorite.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.SetIsFavorite.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.SetIsFavorite.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSetLayout(request: Rpc.Object.SetLayout.Request): Rpc.Object.SetLayout.Response { + val encoded = Service.objectSetLayout( + Rpc.Object.SetLayout.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.SetLayout.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.SetLayout.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectSetObjectType(request: Rpc.Object.SetObjectType.Request): Rpc.Object.SetObjectType.Response { + val encoded = Service.objectSetObjectType( + Rpc.Object.SetObjectType.Request.ADAPTER.encode(request) + ) + val response = Rpc.Object.SetObjectType.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.SetObjectType.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectShow(request: Rpc.Object.Show.Request): Rpc.Object.Show.Response { + val encoded = Service.objectShow(Rpc.Object.Show.Request.ADAPTER.encode(request)) + val response = Rpc.Object.Show.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.Show.Response.Error.Code.NULL) { + when (error.code) { + Rpc.Object.Show.Response.Error.Code.NOT_FOUND -> throw NotFoundObjectException() + Rpc.Object.Show.Response.Error.Code.ANYTYPE_NEEDS_UPGRADE -> + throw BackwardCompatilityNotSupportedException() + else -> throw Exception(error.description) + } + } else { + return response + } + } + + override fun objectTypeCreate(request: Rpc.ObjectType.Create.Request): Rpc.ObjectType.Create.Response { + val encoded = + Service.objectTypeCreate(Rpc.ObjectType.Create.Request.ADAPTER.encode(request)) + val response = Rpc.ObjectType.Create.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectType.Create.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectTypeList(request: Rpc.ObjectType.List.Request): Rpc.ObjectType.List.Response { + val encoded = Service.objectTypeList(Rpc.ObjectType.List.Request.ADAPTER.encode(request)) + val response = Rpc.ObjectType.List.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.ObjectType.List.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun objectUndo(request: Rpc.Object.Undo.Request): Rpc.Object.Undo.Response { + val encoded = Service.objectUndo(Rpc.Object.Undo.Request.ADAPTER.encode(request)) + val response = Rpc.Object.Undo.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Object.Undo.Response.Error.Code.NULL) { + if (error.code == Rpc.Object.Undo.Response.Error.Code.CAN_NOT_MOVE) + throw UndoRedoExhaustedException() + else + throw Exception(error.description) + } else { + return response + } + } + + override fun unsplashDownload(request: Rpc.Unsplash.Download.Request): Rpc.Unsplash.Download.Response { + val encoded = Service.unsplashDownload( + Rpc.Unsplash.Download.Request.ADAPTER.encode(request) + ) + val response = Rpc.Unsplash.Download.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Unsplash.Download.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun unsplashSearch(request: Rpc.Unsplash.Search.Request): Rpc.Unsplash.Search.Response { + val encoded = Service.unsplashSearch( + Rpc.Unsplash.Search.Request.ADAPTER.encode(request) + ) + val response = Rpc.Unsplash.Search.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Unsplash.Search.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun versionGet(request: Rpc.App.GetVersion.Request): Rpc.App.GetVersion.Response { + val encoded = Service.appGetVersion(Rpc.App.GetVersion.Request.ADAPTER.encode(request)) + val response = Rpc.App.GetVersion.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.App.GetVersion.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun walletConvert(request: Rpc.Wallet.Convert.Request): Rpc.Wallet.Convert.Response { + val encoded = Service.walletConvert(Rpc.Wallet.Convert.Request.ADAPTER.encode(request)) + val response = Rpc.Wallet.Convert.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Wallet.Convert.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun walletCreate(request: Rpc.Wallet.Create.Request): Rpc.Wallet.Create.Response { + val encoded = Service.walletCreate(Rpc.Wallet.Create.Request.ADAPTER.encode(request)) + val response = Rpc.Wallet.Create.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Wallet.Create.Response.Error.Code.NULL) { + throw Exception(error.description) + } else { + return response + } + } + + override fun walletRecover(request: Rpc.Wallet.Recover.Request): Rpc.Wallet.Recover.Response { + val encoded = Service.walletRecover(Rpc.Wallet.Recover.Request.ADAPTER.encode(request)) + val response = Rpc.Wallet.Recover.Response.ADAPTER.decode(encoded) + val error = response.error + if (error != null && error.code != Rpc.Wallet.Recover.Response.Error.Code.NULL) { throw Exception(error.description) } else { return response diff --git a/middleware/src/test/java/com/anytypeio/anytype/MiddlewareTest.kt b/middleware/src/test/java/com/anytypeio/anytype/MiddlewareTest.kt index ecce62b05d..5c59b42a3a 100644 --- a/middleware/src/test/java/com/anytypeio/anytype/MiddlewareTest.kt +++ b/middleware/src/test/java/com/anytypeio/anytype/MiddlewareTest.kt @@ -53,7 +53,7 @@ class MiddlewareTest { // TESTING - middleware.logout(false) + middleware.accountStop(false) verify(service, times(1)).accountStop(request) verifyNoMoreInteractions(service) @@ -73,13 +73,13 @@ class MiddlewareTest { layout = null ) - val response = Rpc.Block.CreatePage.Response( + val response = Rpc.BlockLink.CreateWithObject.Response( blockId = MockDataFactory.randomUuid(), targetId = MockDataFactory.randomUuid(), event = ResponseEvent() ) - val request = Rpc.Block.CreatePage.Request( + val request = Rpc.BlockLink.CreateWithObject.Request( contextId = command.context, targetId = command.target, position = Block.Position.Inner, @@ -87,14 +87,14 @@ class MiddlewareTest { ) service.stub { - on { blockCreatePage(any()) } doReturn response + on { blockLinkCreateWithObject(any()) } doReturn response } // TESTING - val (block, target) = middleware.createDocument(command) + val (block, target) = middleware.blockLinkCreateWithObject(command) - verify(service, times(1)).blockCreatePage(request) + verify(service, times(1)).blockLinkCreateWithObject(request) assertEquals( expected = response.blockId, @@ -123,13 +123,13 @@ class MiddlewareTest { layout = null ) - val response = Rpc.Block.CreatePage.Response( + val response = Rpc.BlockLink.CreateWithObject.Response( blockId = MockDataFactory.randomUuid(), targetId = MockDataFactory.randomUuid(), event = ResponseEvent() ) - val request = Rpc.Block.CreatePage.Request( + val request = Rpc.BlockLink.CreateWithObject.Request( contextId = command.context, targetId = command.target, position = Block.Position.Inner, @@ -137,14 +137,14 @@ class MiddlewareTest { ) service.stub { - on { blockCreatePage(any()) } doReturn response + on { blockLinkCreateWithObject(any()) } doReturn response } // TESTING - val (block, target) = middleware.createDocument(command) + val (block, target) = middleware.blockLinkCreateWithObject(command) - verify(service, times(1)).blockCreatePage(request) + verify(service, times(1)).blockLinkCreateWithObject(request) assertEquals( expected = response.blockId, @@ -194,7 +194,7 @@ class MiddlewareTest { // TESTING - val result = middleware.replace(command) + val result = middleware.blockReplace(command) verify(service, times(1)).blockCreate(request) @@ -217,35 +217,35 @@ class MiddlewareTest { emoji = MockDataFactory.randomString() ) - val response = Rpc.Block.Set.Details.Response(event = ResponseEvent()) + val response = Rpc.Object.SetDetails.Response(event = ResponseEvent()) val emojiIconKey = "iconEmoji" val imageIconKey = "iconImage" val emojiValue = command.emoji - val emojiDetail = Rpc.Block.Set.Details.Detail( + val emojiDetail = Rpc.Object.SetDetails.Detail( key = emojiIconKey, value_ = emojiValue ) - val imageDetail = Rpc.Block.Set.Details.Detail( + val imageDetail = Rpc.Object.SetDetails.Detail( key = imageIconKey ) - val request = Rpc.Block.Set.Details.Request( + val request = Rpc.Object.SetDetails.Request( contextId = command.context, details = listOf(emojiDetail, imageDetail) ) service.stub { - on { blockSetDetails(any()) } doReturn response + on { objectSetDetails(any()) } doReturn response } // TESTING - middleware.setDocumentEmojiIcon(command) + middleware.objectSetEmojiIcon(command) - verify(service, times(1)).blockSetDetails(request) + verify(service, times(1)).objectSetDetails(request) verifyNoMoreInteractions(service) } @@ -259,32 +259,32 @@ class MiddlewareTest { hash = MockDataFactory.randomUuid() ) - val response = Rpc.Block.Set.Details.Response(event = ResponseEvent()) + val response = Rpc.Object.SetDetails.Response(event = ResponseEvent()) val imageIconKey = "iconImage" val imageIconValue = command.hash - val imageIconDetail = Rpc.Block.Set.Details.Detail(imageIconKey,imageIconValue) + val imageIconDetail = Rpc.Object.SetDetails.Detail(imageIconKey, imageIconValue) val emojiIconKey = "iconEmoji" - val emojiIconDetail = Rpc.Block.Set.Details.Detail(emojiIconKey) + val emojiIconDetail = Rpc.Object.SetDetails.Detail(emojiIconKey) - val request = Rpc.Block.Set.Details.Request( + val request = Rpc.Object.SetDetails.Request( contextId = command.context, details = listOf(imageIconDetail, emojiIconDetail) ) service.stub { - on { blockSetDetails(any()) } doReturn response + on { objectSetDetails(any()) } doReturn response } // TESTING - middleware.setDocumentImageIcon(command) + middleware.objectSetImageIcon(command) - verify(service, times(1)).blockSetDetails(request) + verify(service, times(1)).objectSetDetails(request) verifyNoMoreInteractions(service) } @@ -298,28 +298,28 @@ class MiddlewareTest { title = MockDataFactory.randomString() ) - val response = Rpc.Block.Set.Details.Response() + val response = Rpc.Object.SetDetails.Response() val key = "name" val value = command.title - val details = Rpc.Block.Set.Details.Detail(key, value) + val details = Rpc.Object.SetDetails.Detail(key, value) - val request = Rpc.Block.Set.Details.Request( + val request = Rpc.Object.SetDetails.Request( contextId = command.context, details = listOf(details) ) service.stub { - on { blockSetDetails(any()) } doReturn response + on { objectSetDetails(any()) } doReturn response } // TESTING - middleware.updateDocumentTitle(command) + middleware.objectSetTitle(command) - verify(service, times(1)).blockSetDetails(request) + verify(service, times(1)).objectSetDetails(request) verifyNoMoreInteractions(service) } @@ -337,15 +337,17 @@ class MiddlewareTest { ) ) - val request = Rpc.BlockList.Set.Text.Style.Request( + val request = Rpc.BlockText.ListSetStyle.Request( contextId = command.context, blockIds = command.targets, style = Block.Content.Text.Style.Checkbox ) service.stub { - on { blockListSetTextStyle(request) } doReturn - Rpc.BlockList.Set.Text.Style.Response(event = ResponseEvent()) + on { blockTextListSetStyle(request) } doReturn + Rpc.BlockText.ListSetStyle.Response( + event = ResponseEvent() + ) } // TESTING @@ -354,9 +356,9 @@ class MiddlewareTest { assertTrue { request.blockIds[0] == command.targets[0] } assertTrue { request.blockIds[1] == command.targets[1] } - middleware.updateTextStyle(command) + middleware.blockTextListSetStyle(command) - verify(service, times(1)).blockListSetTextStyle(request) + verify(service, times(1)).blockTextListSetStyle(request) verifyNoMoreInteractions(service) } @@ -377,7 +379,7 @@ class MiddlewareTest { val position = Block.Position.Top - val request = Rpc.BlockList.Move.Request( + val request = Rpc.Block.ListMoveToExistingObject.Request( contextId = command.ctx, targetContextId = command.ctx, position = position, @@ -386,14 +388,14 @@ class MiddlewareTest { ) service.stub { - on { blockListMove(request) } doReturn Rpc.BlockList.Move.Response(event = ResponseEvent()) + on { blockListMoveToExistingObject(request) } doReturn Rpc.Block.ListMoveToExistingObject.Response(event = ResponseEvent()) } // TESTING - middleware.move(command) + middleware.blockListMoveToExistingObject(command) - verify(service, times(1)).blockListMove(request) + verify(service, times(1)).blockListMoveToExistingObject(request) verifyNoMoreInteractions(service) } @@ -431,7 +433,7 @@ class MiddlewareTest { // TESTING - middleware.paste(command) + middleware.blockPaste(command) verify(service, times(1)).blockPaste(request) verifyNoMoreInteractions(service) @@ -466,7 +468,7 @@ class MiddlewareTest { // TESTING - middleware.split(command) + middleware.blockSplit(command) verify(service, times(1)).blockSplit(request) verifyNoMoreInteractions(service) @@ -484,20 +486,20 @@ class MiddlewareTest { type = CBlockFileType.IMAGE ) - val request = Rpc.UploadFile.Request( + val request = Rpc.File.Upload.Request( localPath = path, type = Block.Content.File.Type.Image ) service.stub { - on { uploadFile(request) } doReturn Rpc.UploadFile.Response() + on { fileUpload(request) } doReturn Rpc.File.Upload.Response() } // TESTING - middleware.uploadFile(command) + middleware.fileUpload(command) - verify(service, times(1)).uploadFile(request) + verify(service, times(1)).fileUpload(request) verifyNoMoreInteractions(service) } @@ -513,20 +515,20 @@ class MiddlewareTest { type = CBlockFileType.FILE ) - val request = Rpc.UploadFile.Request( + val request = Rpc.File.Upload.Request( localPath = path, type = Block.Content.File.Type.File ) service.stub { - on { uploadFile(request) } doReturn Rpc.UploadFile.Response() + on { fileUpload(request) } doReturn Rpc.File.Upload.Response() } // TESTING - middleware.uploadFile(command) + middleware.fileUpload(command) - verify(service, times(1)).uploadFile(request) + verify(service, times(1)).fileUpload(request) verifyNoMoreInteractions(service) } @@ -542,20 +544,20 @@ class MiddlewareTest { type = CBlockFileType.VIDEO ) - val request = Rpc.UploadFile.Request( + val request = Rpc.File.Upload.Request( localPath = path, type = Block.Content.File.Type.Video ) service.stub { - on { uploadFile(request) } doReturn Rpc.UploadFile.Response() + on { fileUpload(request) } doReturn Rpc.File.Upload.Response() } // TESTING - middleware.uploadFile(command) + middleware.fileUpload(command) - verify(service, times(1)).uploadFile(request) + verify(service, times(1)).fileUpload(request) verifyNoMoreInteractions(service) } @@ -592,28 +594,28 @@ class MiddlewareTest { ) val fields = listOf( - Rpc.BlockList.Set.Fields.Request.BlockField( + Rpc.Block.ListSetFields.Request.BlockField( blockId = block1, fields = mapOf("lang" to "kotlin") ), - Rpc.BlockList.Set.Fields.Request.BlockField( + Rpc.Block.ListSetFields.Request.BlockField( blockId = block2, fields = mapOf("lang" to "python") ) ) - val request = Rpc.BlockList.Set.Fields.Request( + val request = Rpc.Block.ListSetFields.Request( contextId = ctx, blockFields = fields ) service.stub { - on { blockListSetFields(request) } doReturn Rpc.BlockList.Set.Fields.Response(event = ResponseEvent()) + on { blockListSetFields(request) } doReturn Rpc.Block.ListSetFields.Response(event = ResponseEvent()) } // TESTING - middleware.setFields(command) + middleware.blockListSetFields(command) verify(service, times(1)).blockListSetFields(request) verifyNoMoreInteractions(service) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/auth/account/SelectAccountViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/auth/account/SelectAccountViewModel.kt index 570d637bfd..601dce2f6b 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/auth/account/SelectAccountViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/auth/account/SelectAccountViewModel.kt @@ -4,16 +4,21 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.anytypeio.anytype.analytics.base.Analytics +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.core_models.exceptions.AccountIsDeletedException import com.anytypeio.anytype.core_utils.common.EventWrapper import com.anytypeio.anytype.domain.auth.interactor.ObserveAccounts import com.anytypeio.anytype.domain.auth.interactor.StartLoadingAccounts -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.presentation.auth.model.SelectAccountView import com.anytypeio.anytype.presentation.navigation.AppNavigation import com.anytypeio.anytype.presentation.navigation.SupportNavigation import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.consumeAsFlow +import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.scan +import kotlinx.coroutines.flow.take import kotlinx.coroutines.launch import timber.log.Timber diff --git a/presentation/src/test/java/FakeGateWay.kt b/presentation/src/test/java/FakeGateWay.kt index 93421b27e8..3aaf4fe92f 100644 --- a/presentation/src/test/java/FakeGateWay.kt +++ b/presentation/src/test/java/FakeGateWay.kt @@ -1,5 +1,5 @@ import com.anytypeio.anytype.domain.config.Gateway object FakeGateWay : Gateway { - override fun obtain(): String = "anytype.io" + override fun provide(): String = "anytype.io" } \ No newline at end of file diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/DeleteAccountViewModelTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/DeleteAccountViewModelTest.kt index 53af74d070..6bcb484dae 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/DeleteAccountViewModelTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/DeleteAccountViewModelTest.kt @@ -5,6 +5,7 @@ import com.anytypeio.anytype.domain.account.DateHelper import com.anytypeio.anytype.domain.account.RestoreAccount import com.anytypeio.anytype.domain.auth.interactor.Logout import com.anytypeio.anytype.domain.auth.repo.AuthRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.presentation.auth.account.DeletedAccountViewModel import com.anytypeio.anytype.presentation.util.CoroutinesTestRule import org.junit.Before @@ -32,6 +33,9 @@ class DeleteAccountViewModelTest { @Mock lateinit var helper: DateHelper + @Mock + lateinit var configStorage: ConfigStorage + lateinit var restoreAccount: RestoreAccount lateinit var logout: Logout @@ -44,7 +48,8 @@ class DeleteAccountViewModelTest { repo = repo ) logout = Logout( - repo = repo + repo = repo, + provider = configStorage ) vm = DeletedAccountViewModel( restoreAccount = restoreAccount, diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SelectAccountViewModelTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SelectAccountViewModelTest.kt index ca06319c76..eb2d088ace 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SelectAccountViewModelTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SelectAccountViewModelTest.kt @@ -2,9 +2,9 @@ package com.anytypeio.anytype.presentation.auth import androidx.arch.core.executor.testing.InstantTaskExecutorRule import com.anytypeio.anytype.analytics.base.Analytics +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.domain.auth.interactor.ObserveAccounts import com.anytypeio.anytype.domain.auth.interactor.StartLoadingAccounts -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.presentation.auth.account.SelectAccountViewModel import com.anytypeio.anytype.presentation.util.CoroutinesTestRule import com.anytypeio.anytype.test_utils.MockDataFactory diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SetupSelectedAccountViewModelTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SetupSelectedAccountViewModelTest.kt index e2fd6abbe6..26369446b3 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SetupSelectedAccountViewModelTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/auth/SetupSelectedAccountViewModelTest.kt @@ -2,14 +2,17 @@ package com.anytypeio.anytype.presentation.auth import androidx.arch.core.executor.testing.InstantTaskExecutorRule import com.anytypeio.anytype.analytics.base.Analytics +import com.anytypeio.anytype.core_models.Account +import com.anytypeio.anytype.core_models.AccountSetup import com.anytypeio.anytype.core_models.AccountStatus +import com.anytypeio.anytype.core_models.Config import com.anytypeio.anytype.core_models.FeaturesConfig import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider import com.anytypeio.anytype.domain.auth.interactor.StartAccount -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.block.interactor.sets.StoreObjectTypes import com.anytypeio.anytype.domain.block.repo.BlockRepository +import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.config.FeaturesConfigProvider import com.anytypeio.anytype.domain.device.PathProvider import com.anytypeio.anytype.presentation.auth.account.SetupSelectedAccountViewModel @@ -49,6 +52,9 @@ class SetupSelectedAccountViewModelTest { @Mock lateinit var featuresConfigProvider: FeaturesConfigProvider + @Mock + lateinit var configStorage: ConfigStorage + @Mock lateinit var objectTypesProvider: ObjectTypesProvider @@ -61,7 +67,8 @@ class SetupSelectedAccountViewModelTest { MockitoAnnotations.openMocks(this) startAccount = StartAccount( repository = authRepo, - featuresConfigProvider = featuresConfigProvider + featuresConfigProvider = featuresConfigProvider, + configStorage = configStorage ) storeObjectTypes = StoreObjectTypes( repo = blockRepo, @@ -105,7 +112,7 @@ class SetupSelectedAccountViewModelTest { ) } -// @Test + // @Test fun `should hide migration-in-progress msg if succeeded to start account`() { // SETUP @@ -120,15 +127,20 @@ class SetupSelectedAccountViewModelTest { id = any(), path = any() ) - } doReturn Triple( - Account( + } doReturn AccountSetup( + account = Account( id = MockDataFactory.randomUuid(), name = MockDataFactory.randomString(), avatar = null, color = null ), - FeaturesConfig(), - AccountStatus.Active + features = FeaturesConfig(), + status = AccountStatus.Active, + config = Config( + home = MockDataFactory.randomUuid(), + gateway = MockDataFactory.randomUuid(), + profile = MockDataFactory.randomUuid() + ) ) } @@ -150,7 +162,7 @@ class SetupSelectedAccountViewModelTest { ) } -// @Test + // @Test fun `should hide migration-in-progress msg if failed to start account`() { // SETUP diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/dashboard/DashboardTestSetup.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/dashboard/DashboardTestSetup.kt index 2e038c019c..28d768aa0c 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/dashboard/DashboardTestSetup.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/dashboard/DashboardTestSetup.kt @@ -2,13 +2,13 @@ package com.anytypeio.anytype.presentation.dashboard import androidx.arch.core.executor.testing.InstantTaskExecutorRule import com.anytypeio.anytype.analytics.base.Analytics +import com.anytypeio.anytype.core_models.Account import com.anytypeio.anytype.core_models.Config import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider import com.anytypeio.anytype.domain.auth.interactor.GetProfile -import com.anytypeio.anytype.domain.auth.model.Account import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers import com.anytypeio.anytype.domain.base.Either import com.anytypeio.anytype.domain.block.interactor.Move diff --git a/protocol/src/main/proto/block.proto b/protocol/src/main/proto/block.proto index b3a1bfd498..158b06b65c 100644 --- a/protocol/src/main/proto/block.proto +++ b/protocol/src/main/proto/block.proto @@ -1,10 +1,11 @@ syntax = "proto3"; package anytype.storage; -option go_package = "pkg/lib/pb/storage"; -import "models.proto"; import "file.proto"; import "google/protobuf/struct.proto"; +import "models.proto"; + +option go_package = "pkg/lib/pb/storage"; message SmartBlockSnapshot { map state = 1; diff --git a/protocol/src/main/proto/commands.proto b/protocol/src/main/proto/commands.proto index 291679089d..78fc5af366 100644 --- a/protocol/src/main/proto/commands.proto +++ b/protocol/src/main/proto/commands.proto @@ -1,12 +1,12 @@ syntax = "proto3"; package anytype; +option go_package = "pb"; + +import "models.proto"; +import "localstore.proto"; import "events.proto"; import "google/protobuf/struct.proto"; -import "localstore.proto"; -import "models.proto"; - -option go_package = "pb"; /* * Rpc is a namespace, that agregates all of the service commands between client and middleware. @@ -15,15 +15,1447 @@ option go_package = "pb"; * Response – message from a middleware. */ message Rpc { - - message Metrics { - message SetParameters { + message App { + message GetVersion { message Request { - string platform = 1; + } + message Response { + Error error = 1; + string version = 2; + string details = 3; // build date, branch and commit + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + VERSION_IS_EMPTY = 3; + + NOT_FOUND = 101; + TIMEOUT = 102; + } + } + } + } + message SetDeviceState { + message Request { + DeviceState deviceState = 1; + + enum DeviceState { + BACKGROUND = 0; + FOREGROUND = 1; + } } message Response { Error error = 1; + + message Error { + Code code = 1; + string description = 2; + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + + NODE_NOT_STARTED = 101; + } + } + + } + } + + + message Shutdown { + message Request { + } + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + + NODE_NOT_STARTED = 101; + } + } + + } + } + } + + message Wallet { + message Create { + /** + * Front-end-to-middleware request to create a new wallet + */ + message Request { + string rootPath = 1; // Path to a wallet directory + } + + /** + * Middleware-to-front-end response, that can contain mnemonic of a created account and a NULL error or an empty mnemonic and a non-NULL error + */ + message Response { + Error error = 1; + string mnemonic = 2; // Mnemonic of a new account (sequence of words, divided by spaces) + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error; mnemonic should be non-empty + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; // Root path is wrong + + FAILED_TO_CREATE_LOCAL_REPO = 101; + // ... + } + } + } + } + + message Recover { + /** + * Front end to middleware request-to-recover-a wallet with this mnemonic and a rootPath + */ + message Request { + string rootPath = 1; // Path to a wallet directory + string mnemonic = 2; // Mnemonic of a wallet to recover + } + + /** + * Middleware-to-front-end response, that can contain a NULL error or a non-NULL error + */ + message Response { + Error error = 1; // Error while trying to recover a wallet + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error; wallet successfully recovered + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; // Root path or mnemonic is wrong + + FAILED_TO_CREATE_LOCAL_REPO = 101; + } + } + } + } + + message Convert { + message Request { + string mnemonic = 1; // Mnemonic of a wallet to convert + string entropy = 2; // entropy of a wallet to convert + + } + + message Response { + Error error = 1; // Error while trying to recover a wallet + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error; wallet successfully recovered + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; // mnemonic is wrong + } + } + + string entropy = 2; + string mnemonic = 3; + } + } + + } + + message Account { + message Config { + bool enableDataview = 1; + bool enableDebug = 2; + bool enableReleaseChannelSwitch = 3; + bool enableSpaces = 4; + + google.protobuf.Struct extra = 100; + } + + message Create { + /** + * Front end to middleware request-to-create-an account + */ + message Request { + string name = 1; // Account name + oneof avatar { + string avatarLocalPath = 2; // Path to an image, that will be used as an avatar of this account + } + + + string alphaInviteCode = 20; + } + + /** + * Middleware-to-front-end response for an account creation request, that can contain a NULL error and created account or a non-NULL error and an empty account + */ + message Response { + Error error = 1; // Error while trying to create an account + anytype.model.Account account = 2; // A newly created account; In case of a failure, i.e. error is non-NULL, the account model should contain empty/default-value fields + Config config = 3; // deprecated, use account + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error; Account should be non-empty + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; // Avatar or name is not correct + + ACCOUNT_CREATED_BUT_FAILED_TO_START_NODE = 101; + ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME = 102; + ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR = 103; + FAILED_TO_STOP_RUNNING_NODE = 104; + + BAD_INVITE_CODE = 900; + + NET_ERROR = 901; // means general network error + NET_CONNECTION_REFUSED = 902; // means we wasn't able to connect to the cafe server + NET_OFFLINE = 903; // client can additionally support this error code to notify user that device is offline + } + } + } + } + + message Recover { + /** + * Front end to middleware request-to-start-search of an accounts for a recovered mnemonic. + * Each of an account that would be found will come with an AccountAdd event + */ + message Request { + } + + /** + * Middleware-to-front-end response to an account recover request, that can contain a NULL error and created account or a non-NULL error and an empty account + */ + message Response { + Error error = 1; // Error while trying to recover an account + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error; + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; + + NO_ACCOUNTS_FOUND = 101; + NEED_TO_RECOVER_WALLET_FIRST = 102; + FAILED_TO_CREATE_LOCAL_REPO = 103; + LOCAL_REPO_EXISTS_BUT_CORRUPTED = 104; + FAILED_TO_RUN_NODE = 105; + WALLET_RECOVER_NOT_PERFORMED = 106; + FAILED_TO_STOP_RUNNING_NODE = 107; + ANOTHER_ANYTYPE_PROCESS_IS_RUNNING = 108; + ACCOUNT_IS_DELETED = 109; + } + } + } + } + + message Delete { + message Request { + bool revert = 1; + } + + message Response { + Error error = 1; // Error while trying to recover an account + anytype.model.Account.Status status = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error; + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; + + ACCOUNT_IS_ALREADY_DELETED = 101; + ACCOUNT_IS_ACTIVE = 102; + } + } + } + } + + message Select { + /** + * Front end to middleware request-to-launch-a specific account using account id and a root path + * User can select an account from those, that came with an AccountAdd events + */ + message Request { + string id = 1; // Id of a selected account + string rootPath = 2; // Root path is optional, set if this is a first request + } + + /** + * Middleware-to-front-end response for an account select request, that can contain a NULL error and selected account or a non-NULL error and an empty account + */ + message Response { + Error error = 1; // Error while trying to launch/select an account + anytype.model.Account account = 2; // Selected account + Config config = 3; // deprecated, use account + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; // Id or root path is wrong + + FAILED_TO_CREATE_LOCAL_REPO = 101; + LOCAL_REPO_EXISTS_BUT_CORRUPTED = 102; + FAILED_TO_RUN_NODE = 103; + FAILED_TO_FIND_ACCOUNT_INFO = 104; + LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET = 105; + FAILED_TO_STOP_SEARCHER_NODE = 106; + FAILED_TO_RECOVER_PREDEFINED_BLOCKS = 107; + ANOTHER_ANYTYPE_PROCESS_IS_RUNNING = 108; + + } + } + } + } + + message Stop { + /** + * Front end to middleware request to stop currently running account node and optionally remove the locally stored data + */ + message Request { + bool removeData = 1; + } + + /** + * Middleware-to-front-end response for an account stop request + */ + message Response { + Error error = 1; // Error while trying to launch/select an account + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; // No error + UNKNOWN_ERROR = 1; // Any other errors + BAD_INPUT = 2; // Id or root path is wrong + + ACCOUNT_IS_NOT_RUNNING = 101; + FAILED_TO_STOP_NODE = 102; + FAILED_TO_REMOVE_ACCOUNT_DATA = 103; + } + } + } + } + + message GetConfig { + message Get { + message Request { + } + + } + } + } + + message Workspace { + message GetCurrent { + message Request { + } + message Response { + Error error = 1; + string workspaceId = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message GetAll { + message Request { + } + + message Response { + Error error = 1; + repeated string workspaceIds = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message Create { + message Request { + string name = 1; + } + + message Response { + Error error = 1; + string workspaceId = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetIsHighlighted { + message Request { + string objectId = 1; + bool isHighlighted = 2; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message Select { + message Request { + string workspaceId = 1; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message Export { + message Request { + // the path where export files will place + string path = 1; + string workspaceId = 2; + } + message Response { + Error error = 1; + string path = 2; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + } + + message Object { + message Open { + message Request { + string contextId = 1; // id of the context blo1k + string objectId = 2; + string traceId = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + + NOT_FOUND = 3; + ANYTYPE_NEEDS_UPGRADE = 10; // failed to read unknown data format – need to upgrade anytype + // ... + } + } + } + } + + message Close { + message Request { + string contextId = 1; // deprecated + string objectId = 2; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message Show { + message Request { + string contextId = 1; // deprecated + string objectId = 2; + string traceId = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + NOT_FOUND = 3; + ANYTYPE_NEEDS_UPGRADE = 10; // failed to read unknown data format – need to upgrade anytype + // ... + } + } + } + } + + message Create { + message Request { + google.protobuf.Struct details = 1; // object details + } + + message Response { + Error error = 1; + string pageId = 3; + ResponseEvent event = 4; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message CreateSet { + message Request { + repeated string source = 1; + google.protobuf.Struct details = 2; // if omitted the name of page will be the same with object type + string templateId = 3; // optional template id for creating from template + } + + message Response { + Error error = 1; + string id = 3; + ResponseEvent event = 4; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + UNKNOWN_OBJECT_TYPE_URL = 3; + } + } + } + } + + message Duplicate { + message Request { + string contextId = 1; + } + + message Response { + Error error = 1; + // created template id + string id = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message OpenBreadcrumbs { + message Request { + string contextId = 1; // deprecated + string traceId = 2; + } + + message Response { + Error error = 1; + string objectId = 2; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetBreadcrumbs { + message Request { + string breadcrumbsId = 1; + repeated string ids = 2; // page ids + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ImportMarkdown { + message Request { + string contextId = 1; + string importPath = 2; + } + + message Response { + Error error = 1; + repeated string rootLinkIds = 2; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ShareByLink { + message Request { + string objectId = 1; + } + + message Response { + string link = 1; + Error error = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message AddWithObjectId { + message Request { + string objectId = 1; + string payload = 2; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message Search { + message Request { + repeated anytype.model.Block.Content.Dataview.Filter filters = 1; + repeated anytype.model.Block.Content.Dataview.Sort sorts = 2; + string fullText = 3; + int32 offset = 4; + int32 limit = 5; + // additional filter by objectTypes + repeated string objectTypeFilter = 6; // deprecated, to be removed + // needed keys in details for return, when empty - will return all + repeated string keys = 7; + } + + message Response { + Error error = 1; + repeated google.protobuf.Struct records = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message Graph { + message Request { + repeated anytype.model.Block.Content.Dataview.Filter filters = 1; + int32 limit = 2; + // additional filter by objectTypes + repeated string objectTypeFilter = 3; + repeated string keys = 4; + } + + message Edge { + enum Type { + Link = 0; + Relation = 1; + } + string source = 1; + string target = 2; + string name = 3; + Type type = 4; + string description = 5; + string iconImage = 6; + string iconEmoji = 7; + bool hidden = 8; + } + + message Response { + Error error = 1; + repeated google.protobuf.Struct nodes = 2; + repeated Edge edges = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SearchSubscribe { + message Request { + // (optional) subscription identifier + // client can provide some string or middleware will generate it automatically + // if subId is already registered on middleware, the new query will replace previous subscription + string subId = 1; + // filters + repeated anytype.model.Block.Content.Dataview.Filter filters = 2; + // sorts + repeated anytype.model.Block.Content.Dataview.Sort sorts = 3; + // results limit + int64 limit = 5; + // initial offset; middleware will find afterId + int64 offset = 6; + // (required) needed keys in details for return, for object fields mw will return (and subscribe) objects as dependent + repeated string keys = 7; + + // (optional) pagination: middleware will return results after given id + string afterId = 8; + // (optional) pagination: middleware will return results before given id + string beforeId = 9; + + repeated string source = 10; + + string ignoreWorkspace = 12; + // disable dependent subscription + bool noDepSubscription = 13; + } + + message Response { + Error error = 1; + + repeated google.protobuf.Struct records = 2; + repeated google.protobuf.Struct dependencies = 3; + + string subId = 4; + + Event.Object.Subscription.Counters counters = 5; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SubscribeIds { + message Request { + // (optional) subscription identifier + // client can provide some string or middleware will generate it automatically + // if subId is already registered on middleware, the new query will replace previous subscription + string subId = 1; + // ids for subscribe + repeated string ids = 2; + // sorts + // (required) needed keys in details for return, for object fields mw will return (and subscribe) objects as dependent + repeated string keys = 3; + + string ignoreWorkspace = 11; + } + + message Response { + Error error = 1; + + repeated google.protobuf.Struct records = 2; + repeated google.protobuf.Struct dependencies = 3; + + string subId = 4; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SearchUnsubscribe { + message Request { + repeated string subIds = 1; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + + message SetLayout { + message Request { + string contextId = 1; + anytype.model.ObjectType.Layout layout = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetIsFavorite { + message Request { + string contextId = 1; + bool isFavorite = 2; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetIsArchived { + message Request { + string contextId = 1; + bool isArchived = 2; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetObjectType { + message Request { + string contextId = 1; + string objectTypeUrl = 3; + } + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + UNKNOWN_OBJECT_TYPE_URL = 3; + } + } + } + } + + message SetDetails { + message Detail { + string key = 1; + google.protobuf.Value value = 2; // NUll - removes key + } + message Request { + string contextId = 1; + repeated Detail details = 2; + } + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ToSet { + message Request { + string contextId = 1; + repeated string source = 2; + } + + message Response { + Error error = 1; + string setId = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + // Available undo/redo operations + message UndoRedoCounter { + int32 undo = 1; + int32 redo = 2; + } + + message Undo { + message Request { + string contextId = 1; // id of the context object + } + message Response { + Error error = 1; + ResponseEvent event = 2; + UndoRedoCounter counters = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + CAN_NOT_MOVE = 3; + // ... + } + } + } + } + + message Redo { + message Request { + string contextId = 1; // id of the context object + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + UndoRedoCounter counters = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + CAN_NOT_MOVE = 3; + // ... + } + } + } + } + + message ListDuplicate { + message Request { + repeated string objectIds = 1; + } + + message Response { + Error error = 1; + repeated string ids = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ListDelete { + // Deletes the object, keys from the local store and unsubscribe from remote changes. Also offloads all orphan files + message Request { + repeated string objectIds = 1; // objects to remove + } + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ListSetIsArchived { + message Request { + repeated string objectIds = 1; + bool isArchived = 2; + } + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ListSetIsFavorite { + message Request { + repeated string objectIds = 1; + bool isFavorite = 2; + } + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ApplyTemplate { + message Request { + string contextId = 1; + // id of template + string templateId = 2; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ListExport { + message Request { + // the path where export files will place + string path = 1; + // ids of documents for export, when empty - will export all available docs + repeated string objectIds = 2; + // export format + Format format = 3; + // save as zip file + bool zip = 4; + // include all nested + bool includeNested = 5; + // include all files + bool includeFiles = 6; + } + + message Response { + Error error = 1; + string path = 2; + int32 succeed = 4; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + + enum Format { + Markdown = 0; + Protobuf = 1; + JSON = 2; + DOT = 3; + SVG = 4; + GRAPH_JSON = 5; + } + } + } + + message ObjectRelation { + message Add { + message Request { + string contextId = 1; + anytype.model.Relation relation = 2; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + string relationKey = 3; // deprecated + anytype.model.Relation relation = 4; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message Update { + message Request { + string contextId = 1; + string relationKey = 2; // key of relation to update + anytype.model.Relation relation = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message Delete { + message Request { + string contextId = 1; + string relationKey = 2; + } + + message Response { + Error error = 1; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message ListAvailable { + message Request { + string contextId = 1; + } + message Response { + Error error = 1; + repeated anytype.model.Relation relations = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message AddFeatured { + message Request { + string contextId = 1; + repeated string relations = 2; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message RemoveFeatured { + message Request { + string contextId = 1; + repeated string relations = 2; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + message Error { Code code = 1; string description = 2; @@ -39,15 +1471,424 @@ message Rpc { } } - message ExternalDrop { - message Files { + message ObjectRelationOption { + message Add { + message Request { + string contextId = 1; + string relationKey = 2; // relation key to add the option + anytype.model.Relation.Option option = 3; // id of select options will be autogenerated + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + anytype.model.Relation.Option option = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message Update { + message Request { + string contextId = 1; + string relationKey = 2; // relation key to add the option + anytype.model.Relation.Option option = 3; // id of select options will be autogenerated + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message Delete { + message Request { + string contextId = 1; + string relationKey = 2; // relation key to add the option + string optionId = 3; // id of select options to remove + bool confirmRemoveAllValuesInRecords = 4; // confirm remove all values in records + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + SOME_RECORDS_HAS_RELATION_VALUE_WITH_THIS_OPTION = 3; // need to confirm with confirmRemoveAllValuesInRecords=true + } + } + } + } + } + + message ObjectType { + message List { + message Request { + } + + message Response { + Error error = 1; + repeated anytype.model.ObjectType objectTypes = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message Create { + message Request { + anytype.model.ObjectType objectType = 1; + } + + message Response { + Error error = 1; + anytype.model.ObjectType objectType = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + UNKNOWN_OBJECT_TYPE_URL = 3; + // ... + } + } + } + } + message Relation { + message Add { + message Request { + string objectTypeUrl = 1; + repeated anytype.model.Relation relations = 2; + } + + message Response { + Error error = 1; + repeated anytype.model.Relation relations = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + UNKNOWN_OBJECT_TYPE_URL = 3; + READONLY_OBJECT_TYPE = 4; + // ... + } + } + } + } + message Remove { + message Request { + string objectTypeUrl = 1; + string relationKey = 2; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + UNKNOWN_OBJECT_TYPE_URL = 3; + READONLY_OBJECT_TYPE = 4; + // ... + } + } + } + } + message Update { + message Request { + string objectTypeUrl = 1; + anytype.model.Relation relation = 2; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + UNKNOWN_OBJECT_TYPE_URL = 3; + READONLY_OBJECT_TYPE = 4; + // ... + } + } + } + } + message List { + message Request { + string objectTypeUrl = 1; + bool appendRelationsFromOtherTypes = 2; // add relations from other object types in the end + } + + message Response { + Error error = 1; + repeated anytype.model.Relation relations = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + UNKNOWN_OBJECT_TYPE_URL = 3; + // ... + } + } + } + } + } + } + + message History { + message Version { + string id = 1; + repeated string previousIds = 2; + string authorId = 3; + string authorName = 4; + int64 time = 5; + int64 groupId = 6; + } + + // returns list of versions (changes) + message GetVersions { + message Request { + string pageId = 1; + // when indicated, results will include versions before given id + string lastVersionId = 2; + // desired count of versions + int32 limit = 3; + } + + message Response { + Error error = 1; + repeated Version versions = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + // returns blockShow event for given version + message ShowVersion { + message Request { + string pageId = 1; + string versionId = 2; + string traceId = 3; + } + + message Response { + Error error = 1; + Event.Object.Show objectShow = 2; + History.Version version = 3; + string traceId = 4; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetVersion { + message Request { + string pageId = 1; + string versionId = 2; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message File { + message Offload { + message Request { + string id = 1; + bool includeNotPinned = 2; + } + message Response { + Error error = 1; + uint64 bytesOffloaded = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + NODE_NOT_STARTED = 103; + FILE_NOT_YET_PINNED = 104; + + } + } + } + } + message ListOffload { + message Request { + repeated string onlyIds = 1; // empty means all + bool includeNotPinned = 2; // false mean not-yet-pinned files will be not + } + + message Response { + Error error = 1; + int32 filesOffloaded = 2; + uint64 bytesOffloaded = 3; + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + NODE_NOT_STARTED = 103; + + } + } + } + } + message Upload { + message Request { + string url = 1; + string localPath = 2; + anytype.model.Block.Content.File.Type type = 3; + bool disableEncryption = 4; // deprecated, has no affect + anytype.model.Block.Content.File.Style style = 5; + + } + + message Response { + Error error = 1; + string hash = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message Download { + message Request { + string hash = 1; + string path = 2; // path to save file. Temp directory is used if empty + } + + message Response { + Error error = 1; + string localPath = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + NOT_FOUND = 3; + } + } + } + } + message Drop { message Request { string contextId = 1; string dropTargetId = 2; // id of the simple block to insert considering position anytype.model.Block.Position position = 3; // position relatively to the dropTargetId simple block repeated string localFilePaths = 4; } - message Response { Error error = 1; ResponseEvent event = 2; @@ -64,99 +1905,26 @@ message Rpc { } } } - - message Content { - message Request { - string contextId = 1; - string focusedBlockId = 2; // can be null - bytes content = 3; // TODO - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } } - message BlockList { - - message ConvertChildrenToPages { - message Request { - string contextId = 1; - repeated string blockIds = 2; - string objectType = 3; - } - - message Response { - Error error = 1; - repeated string linkIds = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } + message Navigation { + enum Context { + Navigation = 0; + MoveTo = 1; // do not show sets/archive + LinkTo = 2; // same for mention, do not show sets/archive } - message Move { + message ListObjects { message Request { - string contextId = 1; - repeated string blockIds = 2; - string targetContextId = 3; - string dropTargetId = 4; // id of the simple block to insert considering position - anytype.model.Block.Position position = 5; // position relatively to the dropTargetId simple block + Context context = 1; + string fullText = 2; + int32 limit = 3; + int32 offset = 4; } message Response { Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message MoveToNewPage { - message Request { - string contextId = 1; - repeated string blockIds = 2; - google.protobuf.Struct details = 3; // page details - string dropTargetId = 4; // id of the simple block to insert considering position - anytype.model.Block.Position position = 5; // position relatively to the dropTargetId simple block - } - - message Response { - Error error = 1; - string linkId = 2; - ResponseEvent event = 3; + repeated anytype.model.ObjectInfo objects = 2; message Error { Code code = 1; @@ -173,19 +1941,115 @@ message Rpc { } /* - * Makes blocks copy by given ids and paste it to shown place + * Get the info for page alongside with info for all inbound and outbound links from/to this page */ - message Duplicate { + message GetObjectInfoWithLinks { message Request { - string contextId = 1; // id of the context block - string targetId = 2; // id of the closest block - repeated string blockIds = 3; // id of block for duplicate - anytype.model.Block.Position position = 4; + string objectId = 1; + Context context = 2; } message Response { Error error = 1; - repeated string blockIds = 2; + anytype.model.ObjectInfoWithLinks object = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message Template { + message CreateFromObject { + message Request { + // id of block for making them template + string contextId = 1; + } + + message Response { + Error error = 1; + // created template id + string id = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message CreateFromObjectType { + message Request { + // id of desired object type + string objectType = 1; + } + + message Response { + Error error = 1; + // created template id + string id = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message Clone { + message Request { + // id of template block for cloning + string contextId = 1; + } + + message Response { + Error error = 1; + // created template id + string id = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message ExportAll { + message Request { + // the path where export files will place + string path = 1; + } + + message Response { + Error error = 1; + string path = 2; ResponseEvent event = 3; message Error { @@ -201,253 +2065,47 @@ message Rpc { } } } + } - message Set { - // commands acceptable only for text blocks, others will be ignored - message Text { - message Style { - message Request { - string contextId = 1; - repeated string blockIds = 2; - anytype.model.Block.Content.Text.Style style = 3; - } + message LinkPreview { + message Request { + string url = 1; + } - message Response { - Error error = 1; - ResponseEvent event = 2; + message Response { + Error error = 1; + anytype.model.LinkPreview linkPreview = 2; - message Error { - Code code = 1; - string description = 2; + message Error { + Code code = 1; + string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Color { - message Request { - string contextId = 1; - repeated string blockIds = 2; - string color = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Mark { - message Request { - string contextId = 1; - repeated string blockIds = 2; - anytype.model.Block.Content.Text.Mark mark = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message BackgroundColor { - message Request { - string contextId = 1; - repeated string blockIds = 2; - string color = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Align { - message Request { - string contextId = 1; - repeated string blockIds = 2; // when empty - align will be applied as layoutAlign - anytype.model.Block.Align align = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Fields { - message Request { - string contextId = 1; - repeated BlockField blockFields = 2; - - message BlockField { - string blockId = 1; - google.protobuf.Struct fields = 2; - } - } - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Div { - message Style { - message Request { - string contextId = 1; - repeated string blockIds = 2; - anytype.model.Block.Content.Div.Style style = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - message File { - message Style { - message Request { - string contextId = 1; - repeated string blockIds = 2; - model.Block.Content.File.Style style = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - message Link { - message Appearance { - message Request { - string contextId = 1; - repeated string blockIds = 2; - anytype.model.Block.Content.Link.IconSize iconSize = 4; - anytype.model.Block.Content.Link.CardStyle cardStyle = 5; - anytype.model.Block.Content.Link.Description description = 6; - repeated string relations = 7; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; } } } + } - message TurnInto { - + message Unsplash { + message Search { message Request { - string contextId = 1; - repeated string blockIds = 2; - anytype.model.Block.Content.Text.Style style = 3; + string query = 1; // empty means random images + int32 limit = 2; // may be omitted if the request was cached previously with another limit } message Response { Error error = 1; - ResponseEvent event = 2; + repeated Picture pictures = 2; + + message Picture { + string id = 1; + string url = 2; + string artist = 3; + string artistUrl = 4; + } message Error { Code code = 1; @@ -457,17 +2115,41 @@ message Rpc { NULL = 0; UNKNOWN_ERROR = 1; BAD_INPUT = 2; + + RATE_LIMIT_EXCEEDED = 100; // ... } } } + } + message Download { + message Request { + string pictureId = 1; + } + + message Response { + Error error = 1; + string hash = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + + RATE_LIMIT_EXCEEDED = 100; + // ... + } + } + } } } - /* - * Namespace, that agregates subtopics and actions, that relates to blocks. - */ + // Block commands message Block { message Replace { message Request { @@ -495,31 +2177,6 @@ message Rpc { } } - message UpdateContent { - message Request { - string contextId = 1; - string blockId = 2; - anytype.model.Block block = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Split { message Request { string contextId = 1; @@ -680,56 +2337,6 @@ message Rpc { } } - message ImportMarkdown { - message Request { - string contextId = 1; - string importPath = 2; - } - - message Response { - Error error = 1; - repeated string rootLinkIds = 2; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Export { - message Request { - string contextId = 1; - repeated anytype.model.Block blocks = 2; - } - - message Response { - Error error = 1; - string path = 2; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Upload { message Request { string contextId = 1; @@ -780,986 +2387,446 @@ message Rpc { } } - message Set { - message Fields { - message Request { - string contextId = 1; - string blockId = 2; - google.protobuf.Struct fields = 3; - } + /* + * Create a Smart/Internal block. Request can contain a block with a content, or it can be an empty block with a specific block.content. + * **Example scenario** + * 1A. Create Page on a dashboard + * 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:bottom, block: emtpy block with page content and id = "") + * 2. Front -> MW: Rpc.Block.Close.Request(block: dashboard.id) + * 3. Front <- MW: Rpc.Block.Close.Response(err) + * 4. Front <- MW: Rpc.Block.Create.Response(page.id) + * 5. Front <- MW: Rpc.Block.Open.Response(err) + * 6. Front <- MW: Event.Block.Show(page) + * 1B. Create Page on a Page + * 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:bottom, block: emtpy block with page content and id = "") + * 2. Front <- MW: Rpc.Block.Create.Response(newPage.id) + * 3. Front <- MW: Event.Block.Show(newPage) + */ + message Create { + // common simple block command + message Request { + string contextId = 1; // id of the context object + string targetId = 2; // id of the closest block + anytype.model.Block block = 3; + anytype.model.Block.Position position = 4; + } - message Response { - Error error = 1; - ResponseEvent event = 2; + message Response { + Error error = 1; + string blockId = 2; + ResponseEvent event = 3; - message Error { - Code code = 1; - string description = 2; + message Error { + Code code = 1; + string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } + } - message Details { - message Detail { - string key = 1; - google.protobuf.Value value = 2; // NUll - removes key - } - message Request { - string contextId = 1; - repeated Detail details = 2; - } - message Response { - Error error = 1; - ResponseEvent event = 2; + /* + * Remove blocks from the childrenIds of its parents + */ + message ListDelete { + message Request { + string contextId = 1; // id of the context object + repeated string blockIds = 2; // targets to remove - message Error { - Code code = 1; - string description = 2; + } - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } + } - message Restrictions { - message Request { - string contextId = 1; - string blockId = 2; - anytype.model.Block.Restrictions restrictions = 3; - } + message SetFields { + message Request { + string contextId = 1; + string blockId = 2; + google.protobuf.Struct fields = 3; + } - message Response { - Error error = 1; - ResponseEvent event = 2; + message Response { + Error error = 1; + ResponseEvent event = 2; - message Error { - Code code = 1; - string description = 2; + message Error { + Code code = 1; + string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } + } - message Page { - message IsArchived { - message Request { - string contextId = 1; - string blockId = 2; - bool isArchived = 3; - } + message ListSetAlign { + message Request { + string contextId = 1; + repeated string blockIds = 2; // when empty - align will be applied as layoutAlign + anytype.model.Block.Align align = 3; + } - message Response { - Error error = 1; + message Response { + Error error = 1; + ResponseEvent event = 2; - message Error { - Code code = 1; - string description = 2; + message Error { + Code code = 1; + string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } + } - message Latex { + message ListSetFields { + message Request { + string contextId = 1; + repeated BlockField blockFields = 2; + + message BlockField { + string blockId = 1; + google.protobuf.Struct fields = 2; + } + } + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + /* + * Makes blocks copy by given ids and paste it to shown place + */ + message ListDuplicate { + message Request { + string contextId = 1; // id of the context object + string targetId = 2; // id of the closest block + repeated string blockIds = 3; // id of block for duplicate + anytype.model.Block.Position position = 4; + } + + message Response { + Error error = 1; + repeated string blockIds = 2; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ListUpdate { + message Request { + string contextId = 1; + repeated string blockIds = 2; + oneof field { + Text text = 3; + string backgroundColor = 4; + anytype.model.Block.Align align = 5; + google.protobuf.Struct fields = 6; + anytype.model.Block.Content.Div.Style divStyle = 7; + model.Block.Content.File.Style fileStyle = 8; + } message Text { - message Request { - string contextId = 1; - string blockId = 2; - string text = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - message Text { - message TText { - message Request { - string contextId = 1; - string blockId = 2; - string text = 3; - anytype.model.Block.Content.Text.Marks marks = 4; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Color { - message Request { - string contextId = 1; - string blockId = 2; - string color = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Style { - message Request { - string contextId = 1; - string blockId = 2; - anytype.model.Block.Content.Text.Style style = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Checked { - message Request { - string contextId = 1; - string blockId = 2; - bool checked = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Icon { - message Request { - string contextId = 1; - string blockId = 2; - string iconImage = 3; // in case both image and emoji are set, image has a priority to show - string iconEmoji = 5; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message File { - message Name { - message Request { - string contextId = 1; - string blockId = 2; - string name = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - } - - message Image { - message Name { - message Request { - string contextId = 1; - string blockId = 2; - string name = 3; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Width { - message Request { - string contextId = 1; - string blockId = 2; - int32 width = 3; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message Video { - message Name { - message Request { - string contextId = 1; - string blockId = 2; - string name = 3; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Width { - message Request { - string contextId = 1; - string blockId = 2; - int32 width = 3; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message Link { - message TargetBlockId { - message Request { - string contextId = 1; - string blockId = 2; - string targetBlockId = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } + oneof field { + anytype.model.Block.Content.Text.Style style = 1; + string color = 2; + anytype.model.Block.Content.Text.Mark mark = 3; } } } } - message Relation { - message SetKey { - message Request { - string contextId = 1; - string blockId = 2; - string key = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } + message ListConvertToObjects { + message Request { + string contextId = 1; + repeated string blockIds = 2; + string objectType = 3; } - message Add { - message Request { - string contextId = 1; - string blockId = 2; - anytype.model.Relation relation = 3; - } - message Response { - Error error = 1; - ResponseEvent event = 2; + message Response { + Error error = 1; + repeated string linkIds = 2; - message Error { - Code code = 1; - string description = 2; + message Error { + Code code = 1; + string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } } - message ObjectType { - message Set { - message Request { - string contextId = 1; - string objectTypeUrl = 3; - } - message Response { - Error error = 1; - ResponseEvent event = 2; + message ListMoveToExistingObject { + message Request { + string contextId = 1; + repeated string blockIds = 2; + string targetContextId = 3; + string dropTargetId = 4; // id of the simple block to insert considering position + anytype.model.Block.Position position = 5; // position relatively to the dropTargetId simple block + } - message Error { - Code code = 1; - string description = 2; + message Response { + Error error = 1; + ResponseEvent event = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - } + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } } - message Bookmark { - message Fetch { - message Request { - string contextId = 1; - string blockId = 2; - string url = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } + message ListMoveToNewObject { + message Request { + string contextId = 1; + repeated string blockIds = 2; + google.protobuf.Struct details = 3; // new object details + string dropTargetId = 4; // id of the simple block to insert considering position + anytype.model.Block.Position position = 5; // position relatively to the dropTargetId simple block } - message CreateAndFetch { - message Request { - string contextId = 1; - string targetId = 2; - anytype.model.Block.Position position = 3; - string url = 4; - } + message Response { + Error error = 1; + string linkId = 2; + ResponseEvent event = 3; - message Response { - Error error = 1; - string blockId = 2; - ResponseEvent event = 3; + message Error { + Code code = 1; + string description = 2; - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } } - message File { - message CreateAndUpload { - message Request { - string contextId = 1; - string targetId = 2; - anytype.model.Block.Position position = 3; - string url = 4; - string localPath = 5; - anytype.model.Block.Content.File.Type fileType = 6; - } + message ListTurnInto { + message Request { + string contextId = 1; + repeated string blockIds = 2; + anytype.model.Block.Content.Text.Style style = 3; + } + message Response { + Error error = 1; + ResponseEvent event = 2; - message Response { - Error error = 1; - string blockId = 2; - ResponseEvent event = 3; + message Error { + Code code = 1; + string description = 2; - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } } - message Dataview { - message ViewCreate { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to insert the new block - anytype.model.Block.Content.Dataview.View view = 4; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - string viewId = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message ViewUpdate { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to update - string viewId = 3; // id of view to update - anytype.model.Block.Content.Dataview.View view = 4; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message ViewDelete { - message Request { - string contextId = 1; // id of the context block - string blockId = 2; // id of the dataview - string viewId = 4; // id of the view to remove - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message ViewSetPosition { - message Request { - string contextId = 1; // id of the context block - string blockId = 2; // id of the dataview - string viewId = 4; // id of the view to remove - uint32 position = 5; // index of view position (0 - means first) - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } + message ListSetBackgroundColor { + message Request { + string contextId = 1; + repeated string blockIds = 2; + string color = 3; } - // set the current active view (persisted only within a session) - message ViewSetActive { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block - string viewId = 3; // id of active view - uint32 offset = 4; - uint32 limit = 5; - } + message Response { + Error error = 1; + ResponseEvent event = 2; - message Response { - Error error = 1; - ResponseEvent event = 2; + message Error { + Code code = 1; + string description = 2; - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message RecordUpdate { - message Request { - string contextId = 1; - string blockId = 2; - string recordId = 3; - google.protobuf.Struct record = 4; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message RecordDelete { - message Request { - string contextId = 1; - string blockId = 2; - string recordId = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message RecordCreate { - message Request { - string contextId = 1; - string blockId = 2; - google.protobuf.Struct record = 3; - string templateId = 4; - } - - message Response { - Error error = 1; - google.protobuf.Struct record = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message RelationAdd { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to add relation - anytype.model.Relation relation = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - string relationKey = 3; // deprecated - anytype.model.Relation relation = 4; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - message RelationUpdate { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to add relation - string relationKey = 3; // key of relation to update - anytype.model.Relation relation = 4; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - message RelationDelete { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to add relation - string relationKey = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - - // RecordRelationOptionAdd may return existing option in case object specified with recordId already have the option with the same name or ID - message RecordRelationOptionAdd { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to add relation - string relationKey = 3; // relation key to add the option - anytype.model.Relation.Option option = 4; // id of select options will be autogenerated - string recordId = 5; // id of record which is used to add an option - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - anytype.model.Relation.Option option = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - message RecordRelationOptionUpdate { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to add relation - string relationKey = 3; // relation key to add the option - anytype.model.Relation.Option option = 4; // id of select options will be autogenerated - string recordId = 5; // id of record which is used to update an option - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - message RecordRelationOptionDelete { - message Request { - string contextId = 1; - string blockId = 2; // id of dataview block to add relation - string relationKey = 3; // relation key to add the option - string optionId = 4; // id of select options to remove - string recordId = 5; // id of record which is used to delete an option - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - - message RelationListAvailable { - message Request { - string contextId = 1; - string blockId = 2; - } - - message Response { - Error error = 1; - repeated anytype.model.Relation relations = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - NOT_A_DATAVIEW_BLOCK = 3; - // ... - } - } - } - } - - message SetSource { - message Request { - string contextId = 1; - string blockId = 2; - repeated string source = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 4; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... } } } } - message Get { + message Export { + message Request { + string contextId = 1; + repeated anytype.model.Block blocks = 2; + } + + message Response { + Error error = 1; + string path = 2; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message BlockLatex { + message SetText { + message Request { + string contextId = 1; + string blockId = 2; + string text = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message BlockText { + message SetText { + message Request { + string contextId = 1; + string blockId = 2; + string text = 3; + anytype.model.Block.Content.Text.Marks marks = 4; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetColor { + message Request { + string contextId = 1; + string blockId = 2; + string color = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetMarks { /* - * Get marks list in the selected range in text block. - */ - message Marks { + * Get marks list in the selected range in text block. + */ + message Get { message Request { string contextId = 1; string blockId = 2; @@ -1785,84 +2852,11 @@ message Rpc { } } - // Available undo/redo operations - message UndoRedoCounter { - int32 undo = 1; - int32 redo = 2; - } - - message Undo { + message SetStyle { message Request { - string contextId = 1; // id of the context block - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - UndoRedoCounter counters = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - CAN_NOT_MOVE = 3; - // ... - } - } - } - } - - message Redo { - message Request { - string contextId = 1; // id of the context block - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - UndoRedoCounter counters = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - CAN_NOT_MOVE = 3; - // ... - } - } - } - } - - /* - * Works with a smart blocks (block-organizers, like page, dashboard etc) - * **Example scenario** - * 1A. On front-end start. - * 1. Front -> MW: Rpc.Block.Open.Request(dashboard.id) - * 2. MW -> Front: BlockShow(dashboard) - * 3. MW -> Front: Rpc.Block.Open.Response(err) - * 1B. User clicks on a page icon on the dashboard. - * 1. Front -> MW: Rpc.Block.Close.Request(dashboard.id) - * Get close response first, then open request: - * 2. MW -> Front: Rpc.Block.Close.Response(err) - * 3. Front -> MW: Rpc.Block.Open.Request(page.id) - * 4. MW -> Front: BlockShow() - * 5. MW -> Front: Rpc.Block.Open.Response(err) - * Image/Video/File blocks then: - * 6. MW -> Front: BlockShow() - */ - message Open { - message Request { - string contextId = 1; // id of the context blo1k + string contextId = 1; string blockId = 2; - string traceId = 3; + anytype.model.Block.Content.Text.Style style = 3; } message Response { @@ -1877,20 +2871,17 @@ message Rpc { NULL = 0; UNKNOWN_ERROR = 1; BAD_INPUT = 2; - - NOT_FOUND = 3; - ANYTYPE_NEEDS_UPGRADE = 10; // failed to read unknown data format – need to upgrade anytype // ... } } } } - message Show { + message SetChecked { message Request { - string contextId = 1; // id of the context blo1k + string contextId = 1; string blockId = 2; - string traceId = 3; + bool checked = 3; } message Response { @@ -1905,24 +2896,24 @@ message Rpc { NULL = 0; UNKNOWN_ERROR = 1; BAD_INPUT = 2; - NOT_FOUND = 3; - ANYTYPE_NEEDS_UPGRADE = 10; // failed to read unknown data format – need to upgrade anytype // ... } } } } - - message GetPublicWebURL { + message SetIcon { message Request { - string blockId = 1; + string contextId = 1; + string blockId = 2; + string iconImage = 3; // in case both image and emoji are set, image has a priority to show + string iconEmoji = 5; } message Response { Error error = 1; + ResponseEvent event = 2; - string url = 2; message Error { Code code = 1; string description = 2; @@ -1937,10 +2928,115 @@ message Rpc { } } - message OpenBreadcrumbs { + message ListSetStyle { message Request { - string contextId = 1; // id of the context blo1k - string traceId = 2; + string contextId = 1; + repeated string blockIds = 2; + anytype.model.Block.Content.Text.Style style = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ListSetColor { + message Request { + string contextId = 1; + repeated string blockIds = 2; + string color = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message ListSetMark { + message Request { + string contextId = 1; + repeated string blockIds = 2; + anytype.model.Block.Content.Text.Mark mark = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message BlockFile { + message SetName { + message Request { + string contextId = 1; + string blockId = 2; + string name = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message CreateAndUpload { + message Request { + string contextId = 1; + string targetId = 2; + anytype.model.Block.Position position = 3; + string url = 4; + string localPath = 5; + anytype.model.Block.Content.File.Type fileType = 6; } message Response { @@ -1956,16 +3052,15 @@ message Rpc { NULL = 0; UNKNOWN_ERROR = 1; BAD_INPUT = 2; - // ... } } } } - - message SetBreadcrumbs { + message ListSetStyle { message Request { - string breadcrumbsId = 1; - repeated string ids = 2; // page ids + string contextId = 1; + repeated string blockIds = 2; + model.Block.Content.File.Style style = 3; } message Response { @@ -1985,35 +3080,18 @@ message Rpc { } } } + } - /* - * Create a Smart/Internal block. Request can contain a block with a content, or it can be an empty block with a specific block.content. - * **Example scenario** - * 1A. Create Page on a dashboard - * 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:bottom, block: emtpy block with page content and id = "") - * 2. Front -> MW: Rpc.Block.Close.Request(block: dashboard.id) - * 3. Front <- MW: Rpc.Block.Close.Response(err) - * 4. Front <- MW: Rpc.Block.Create.Response(page.id) - * 5. Front <- MW: Rpc.Block.Open.Response(err) - * 6. Front <- MW: Event.Block.Show(page) - * 1B. Create Page on a Page - * 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:bottom, block: emtpy block with page content and id = "") - * 2. Front <- MW: Rpc.Block.Create.Response(newPage.id) - * 3. Front <- MW: Event.Block.Show(newPage) - */ - message Create { - // common simple block command + message BlockImage { + message SetName { message Request { - string contextId = 1; // id of the context block - string targetId = 2; // id of the closest block - anytype.model.Block block = 3; - anytype.model.Block.Position position = 4; + string contextId = 1; + string blockId = 2; + string name = 3; } message Response { Error error = 1; - string blockId = 2; - ResponseEvent event = 3; message Error { Code code = 1; @@ -2029,10 +3107,86 @@ message Rpc { } } - message CreatePage { + message SetWidth { message Request { - string contextId = 1; // id of the context block - google.protobuf.Struct details = 3; // new page details + string contextId = 1; + string blockId = 2; + int32 width = 3; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message BlockVideo { + message SetName { + message Request { + string contextId = 1; + string blockId = 2; + string name = 3; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message SetWidth { + message Request { + string contextId = 1; + string blockId = 2; + int32 width = 3; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message BlockLink { + message CreateWithObject { + message Request { + string contextId = 1; // id of the context object + google.protobuf.Struct details = 3; // new object details string templateId = 5; // optional template id for creating from template // link block params @@ -2060,45 +3214,14 @@ message Rpc { } } } - - message CreateSet { + message ListSetAppearance { message Request { - string contextId = 1; // id of the context block - string targetId = 2; // id of the closest block - repeated string source = 3; - google.protobuf.Struct details = 4; // details - - anytype.model.Block.Position position = 5; - } - - message Response { - Error error = 1; - string blockId = 2; // (optional) id of the link block pointing to this set - string targetId = 3; // id of the new set - ResponseEvent event = 4; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - // ... - } - } - } - } - /* - * Remove blocks from the childrenIds of its parents - */ - message Unlink { - message Request { - string contextId = 1; // id of the context block - repeated string blockIds = 2; // targets to remove - + string contextId = 1; + repeated string blockIds = 2; + anytype.model.Block.Content.Link.IconSize iconSize = 4; + anytype.model.Block.Content.Link.CardStyle cardStyle = 5; + anytype.model.Block.Content.Link.Description description = 6; + repeated string relations = 7; } message Response { @@ -2117,1168 +3240,20 @@ message Rpc { } } } - } + } + } - /* - * Block.Close – it means unsubscribe from a block. - * Precondition: block should be opened. - */ - message Close { + message BlockRelation { + message SetKey { message Request { - string contextId = 1; // id of the context blo1k + string contextId = 1; string blockId = 2; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message Workspace { - message GetCurrent { - message Request { - } - - message Response { - Error error = 1; - string workspaceId = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message GetAll { - message Request { - } - - message Response { - Error error = 1; - repeated string workspaceIds = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Create { - message Request { - string name = 1; - } - - message Response { - Error error = 1; - string workspaceId = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message SetIsHighlighted { - message Request { - string objectId = 1; - bool isHighlighted = 2; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Select { - message Request { - string workspaceId = 1; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - /* - * Namespace, that aggregates subtopics and actions, that relates to wallet. - */ - message Wallet { - message Create { - /** - * Front-end-to-middleware request to create a new wallet - */ - message Request { - string rootPath = 1; // Path to a wallet directory - } - - /** - * Middleware-to-front-end response, that can contain mnemonic of a created account and a NULL error or an empty mnemonic and a non-NULL error - */ - message Response { - Error error = 1; - string mnemonic = 2; // Mnemonic of a new account (sequence of words, divided by spaces) - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error; mnemonic should be non-empty - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; // Root path is wrong - - FAILED_TO_CREATE_LOCAL_REPO = 101; - // ... - } - } - } - } - - message Recover { - /** - * Front end to middleware request-to-recover-a wallet with this mnemonic and a rootPath - */ - message Request { - string rootPath = 1; // Path to a wallet directory - string mnemonic = 2; // Mnemonic of a wallet to recover - } - - /** - * Middleware-to-front-end response, that can contain a NULL error or a non-NULL error - */ - message Response { - Error error = 1; // Error while trying to recover a wallet - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error; wallet successfully recovered - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; // Root path or mnemonic is wrong - - FAILED_TO_CREATE_LOCAL_REPO = 101; - } - } - } - } - - message Convert { - message Request { - string mnemonic = 1; // Mnemonic of a wallet to convert - string entropy = 2; // entropy of a wallet to convert - - } - - message Response { - Error error = 1; // Error while trying to recover a wallet - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error; wallet successfully recovered - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; // mnemonic is wrong - } - } - - string entropy = 2; - string mnemonic = 3; - } - } - - } - - /* - * Namespace, that agregates subtopics and actions, that relates to account. - */ - message Account { - // TODO: use model from models.proto - message Config { - bool enableDataview = 1; - bool enableDebug = 2; - bool enableReleaseChannelSwitch = 3; - bool enableSpaces = 4; - - google.protobuf.Struct extra = 100; - } - message Create { - /** - * Front end to middleware request-to-create-an account - */ - message Request { - string name = 1; // Account name - oneof avatar { - string avatarLocalPath = 2; // Path to an image, that will be used as an avatar of this account - } - - - string alphaInviteCode = 20; - } - - /** - * Middleware-to-front-end response for an account creation request, that can contain a NULL error and created account or a non-NULL error and an empty account - */ - message Response { - Error error = 1; // Error while trying to create an account - anytype.model.Account account = 2; // A newly created account; In case of a failure, i.e. error is non-NULL, the account model should contain empty/default-value fields - Config config = 3; // deprecated, use account - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error; Account should be non-empty - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; // Avatar or name is not correct - - ACCOUNT_CREATED_BUT_FAILED_TO_START_NODE = 101; - ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME = 102; - ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR = 103; - FAILED_TO_STOP_RUNNING_NODE = 104; - - BAD_INVITE_CODE = 900; - - NET_ERROR = 901; // means general network error - NET_CONNECTION_REFUSED = 902; // means we wasn't able to connect to the cafe server - NET_OFFLINE = 903; // client can additionally support this error code to notify user that device is offline - } - } - } - } - - message Recover { - /** - * Front end to middleware request-to-start-search of an accounts for a recovered mnemonic. - * Each of an account that would be found will come with an AccountAdd event - */ - message Request { - } - - /** - * Middleware-to-front-end response to an account recover request, that can contain a NULL error and created account or a non-NULL error and an empty account - */ - message Response { - Error error = 1; // Error while trying to recover an account - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error; - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; - - NO_ACCOUNTS_FOUND = 101; - NEED_TO_RECOVER_WALLET_FIRST = 102; - FAILED_TO_CREATE_LOCAL_REPO = 103; - LOCAL_REPO_EXISTS_BUT_CORRUPTED = 104; - FAILED_TO_RUN_NODE = 105; - WALLET_RECOVER_NOT_PERFORMED = 106; - FAILED_TO_STOP_RUNNING_NODE = 107; - ANOTHER_ANYTYPE_PROCESS_IS_RUNNING = 108; - ACCOUNT_IS_DELETED = 109; - } - } - } - } - - message Delete { - message Request { - bool revert = 1; - } - - message Response { - Error error = 1; // Error while trying to recover an account - anytype.model.Account.Status status = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error; - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; - - ACCOUNT_IS_ALREADY_DELETED = 101; - ACCOUNT_IS_ACTIVE = 102; - } - } - } - } - - message Select { - /** - * Front end to middleware request-to-launch-a specific account using account id and a root path - * User can select an account from those, that came with an AccountAdd events - */ - message Request { - string id = 1; // Id of a selected account - string rootPath = 2; // Root path is optional, set if this is a first request - } - - /** - * Middleware-to-front-end response for an account select request, that can contain a NULL error and selected account or a non-NULL error and an empty account - */ - message Response { - Error error = 1; // Error while trying to launch/select an account - anytype.model.Account account = 2; // Selected account - Config config = 3; // deprecated, use account - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; // Id or root path is wrong - - FAILED_TO_CREATE_LOCAL_REPO = 101; - LOCAL_REPO_EXISTS_BUT_CORRUPTED = 102; - FAILED_TO_RUN_NODE = 103; - FAILED_TO_FIND_ACCOUNT_INFO = 104; - LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET = 105; - FAILED_TO_STOP_SEARCHER_NODE = 106; - FAILED_TO_RECOVER_PREDEFINED_BLOCKS = 107; - ANOTHER_ANYTYPE_PROCESS_IS_RUNNING = 108; - - } - } - } - } - - message Stop { - /** - * Front end to middleware request to stop currently running account node and optionally remove the locally stored data - */ - message Request { - bool removeData = 1; - } - - /** - * Middleware-to-front-end response for an account stop request - */ - message Response { - Error error = 1; // Error while trying to launch/select an account - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; // No error - UNKNOWN_ERROR = 1; // Any other errors - BAD_INPUT = 2; // Id or root path is wrong - - ACCOUNT_IS_NOT_RUNNING = 101; - FAILED_TO_STOP_NODE = 102; - FAILED_TO_REMOVE_ACCOUNT_DATA = 103; - } - } - } - } - } - - /* - * Namespace, that agregates log subtopics and actions. - * Usage: send request with topic (Level) and description (message) from client to middleware to log. - */ - message Log { - message Send { - message Request { - string message = 1; - Level level = 2; - - enum Level { - DEBUG = 0; - ERROR = 1; - FATAL = 2; - INFO = 3; - PANIC = 4; - WARNING = 5; - } - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - - NOT_FOUND = 101; - TIMEOUT = 102; - } - } - } - } - } - - /* - * Get info about a version of a middleware. - * Info is a string, that contains: BuildDate, GitCommit, GitBranch, GitState - */ - message Version { - message Get { - message Request { - } - - message Response { - Error error = 1; - string version = 2; - string details = 3; // build date, branch and commit - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - VERSION_IS_EMPTY = 3; - - NOT_FOUND = 101; - TIMEOUT = 102; - } - } - } - } - } - - message File { - message Offload { - message Request { - string id = 1; - bool includeNotPinned = 2; - } - message Response { - Error error = 1; - uint64 bytesOffloaded = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - NODE_NOT_STARTED = 103; - FILE_NOT_YET_PINNED = 104; - - } - } - } - } - } - message FileList { - message Offload { - message Request { - repeated string onlyIds = 1; // empty means all - bool includeNotPinned = 2; // false mean not-yet-pinned files will be not - } - - message Response { - Error error = 1; - int32 filesOffloaded = 2; - uint64 bytesOffloaded = 3; - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - NODE_NOT_STARTED = 103; - - } - } - } - } - - } - - message Shutdown { - message Request { - } - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - - NODE_NOT_STARTED = 101; - } - } - - } - } - - message DeviceState { - message Request { - DeviceState deviceState = 1; - - enum DeviceState { - BACKGROUND = 0; - FOREGROUND = 1; - } - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - - NODE_NOT_STARTED = 101; - } - } - - } - } - - message Config { - message Get { - message Request { - } - message Response { - Error error = 1; - string homeBlockId = 2; // home dashboard block id - string archiveBlockId = 3; // archive block id - string profileBlockId = 4; // profile block id - string marketplaceTypeId = 5; // marketplace type id - string marketplaceRelationId = 6; // marketplace relation id - string marketplaceTemplateId = 7; // marketplace template id - string deviceId = 8; - string gatewayUrl = 101; // gateway url for fetching static files - message Error { - Code code = 1; - string description = 2; - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - - NODE_NOT_STARTED = 101; - } - } - } - } - } - - message Ping { - message Request { - int32 index = 1; - int32 numberOfEventsToSend = 2; - } - - message Response { - Error error = 1; - int32 index = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - - message Process { - message Cancel { - message Request { - string id = 1; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - } - - message LinkPreview { - message Request { - string url = 1; - } - - message Response { - Error error = 1; - anytype.model.LinkPreview linkPreview = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - - message UploadFile { - message Request { - string url = 1; - string localPath = 2; - anytype.model.Block.Content.File.Type type = 3; - bool disableEncryption = 4; // deprecated, has no affect - anytype.model.Block.Content.File.Style style = 5; - - } - - message Response { - Error error = 1; - string hash = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - - message DownloadFile { - message Request { - string hash = 1; - string path = 2; // path to save file. Temp directory is used if empty - } - - message Response { - Error error = 1; - string localPath = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - NOT_FOUND = 3; - } - } - } - } - - message Navigation { - enum Context { - Navigation = 0; - MoveTo = 1; // do not show sets/archive - LinkTo = 2; // same for mention, do not show sets/archive - } - - message ListObjects { - message Request { - Context context = 1; - string fullText = 2; - int32 limit = 3; - int32 offset = 4; - } - - message Response { - Error error = 1; - repeated anytype.model.ObjectInfo objects = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - /* - * Get the info for page alongside with info for all inbound and outbound links from/to this page - */ - message GetObjectInfoWithLinks { - message Request { - string objectId = 1; - Context context = 2; - } - - message Response { - Error error = 1; - anytype.model.ObjectInfoWithLinks object = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message History { - // returns list of versions (changes) - message Versions { - message Version { - string id = 1; - repeated string previousIds = 2; - string authorId = 3; - string authorName = 4; - int64 time = 5; - int64 groupId = 6; - } - - message Request { - string pageId = 1; - // when indicated, results will include versions before given id - string lastVersionId = 2; - // desired count of versions - int32 limit = 3; - } - - message Response { - Error error = 1; - repeated Version versions = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - // returns blockShow event for given version - message Show { - message Request { - string pageId = 1; - string versionId = 2; - string traceId = 3; - } - - message Response { - Error error = 1; - Event.Object.Show objectShow = 2; - History.Versions.Version version = 3; - string traceId = 4; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message SetVersion { - message Request { - string pageId = 1; - string versionId = 2; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message Page { - message Create { - message Request { - google.protobuf.Struct details = 1; // page details - } - - message Response { - Error error = 1; - string pageId = 3; - ResponseEvent event = 4; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message Set { - message Create { - message Request { - repeated string source = 1; - google.protobuf.Struct details = 2; // if omitted the name of page will be the same with object type - string templateId = 3; // optional template id for creating from template - } - - message Response { - Error error = 1; - string id = 3; - ResponseEvent event = 4; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - } - } - } - } - } - - message ObjectType { - message List { - message Request { - } - - message Response { - Error error = 1; - repeated anytype.model.ObjectType objectTypes = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Create { - message Request { - anytype.model.ObjectType objectType = 1; - } - - message Response { - Error error = 1; - anytype.model.ObjectType objectType = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - // ... - } - } - } - } - - message Relation { - message Add { - message Request { - string objectTypeUrl = 1; - repeated anytype.model.Relation relations = 2; - } - - message Response { - Error error = 1; - repeated anytype.model.Relation relations = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - READONLY_OBJECT_TYPE = 4; - // ... - } - } - } - } - message Remove { - message Request { - string objectTypeUrl = 1; - string relationKey = 2; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - READONLY_OBJECT_TYPE = 4; - // ... - } - } - } - } - message Update { - message Request { - string objectTypeUrl = 1; - anytype.model.Relation relation = 2; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - READONLY_OBJECT_TYPE = 4; - // ... - } - } - } - } - message List { - message Request { - string objectTypeUrl = 1; - bool appendRelationsFromOtherTypes = 2; // add relations from other object types in the end - } - - message Response { - Error error = 1; - repeated anytype.model.Relation relations = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - UNKNOWN_OBJECT_TYPE_URL = 3; - // ... - } - } - } - } - } - } - - message Object { - message ShareByLink { - message Request { - string objectId = 1; - } - - message Response { - string link = 1; - Error error = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message AddWithObjectId { - message Request { - string objectId = 1; - string payload = 2; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message RelationAdd { - message Request { - string contextId = 1; - anytype.model.Relation relation = 2; + string key = 3; } message Response { Error error = 1; ResponseEvent event = 2; - string relationKey = 3; // deprecated - anytype.model.Relation relation = 4; message Error { Code code = 1; @@ -3288,15 +3263,14 @@ message Rpc { NULL = 0; UNKNOWN_ERROR = 1; BAD_INPUT = 2; - ALREADY_EXISTS = 10; } } } } - message RelationUpdate { + message Add { message Request { string contextId = 1; - string relationKey = 2; // key of relation to update + string blockId = 2; anytype.model.Relation relation = 3; } @@ -3316,14 +3290,44 @@ message Rpc { } } } - message RelationDelete { + } + + message BlockBookmark { + message Fetch { message Request { string contextId = 1; - string relationKey = 2; + string blockId = 2; + string url = 3; } message Response { Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + + message CreateAndFetch { + message Request { + string contextId = 1; + string targetId = 2; + anytype.model.Block.Position position = 3; + string url = 4; + } + + message Response { + Error error = 1; + string blockId = 2; ResponseEvent event = 3; message Error { @@ -3338,416 +3342,19 @@ message Rpc { } } } + } - // RelationOptionAdd may return existing option in case dataview already has one with the same text - message RelationOptionAdd { + message BlockDiv { + message ListSetStyle { message Request { string contextId = 1; - string relationKey = 2; // relation key to add the option - anytype.model.Relation.Option option = 3; // id of select options will be autogenerated + repeated string blockIds = 2; + anytype.model.Block.Content.Div.Style style = 3; } message Response { Error error = 1; ResponseEvent event = 2; - anytype.model.Relation.Option option = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - message RelationOptionUpdate { - message Request { - string contextId = 1; - string relationKey = 2; // relation key to add the option - anytype.model.Relation.Option option = 3; // id of select options will be autogenerated - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - message RelationOptionDelete { - message Request { - string contextId = 1; - string relationKey = 2; // relation key to add the option - string optionId = 3; // id of select options to remove - bool confirmRemoveAllValuesInRecords = 4; // confirm remove all values in records - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - SOME_RECORDS_HAS_RELATION_VALUE_WITH_THIS_OPTION = 3; // need to confirm with confirmRemoveAllValuesInRecords=true - } - } - } - } - message RelationListAvailable { - message Request { - string contextId = 1; - } - message Response { - Error error = 1; - repeated anytype.model.Relation relations = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Search { - message Request { - repeated anytype.model.Block.Content.Dataview.Filter filters = 1; - repeated anytype.model.Block.Content.Dataview.Sort sorts = 2; - string fullText = 3; - int32 offset = 4; - int32 limit = 5; - // additional filter by objectTypes - repeated string objectTypeFilter = 6; // deprecated, to be removed - // needed keys in details for return, when empty - will return all - repeated string keys = 7; - } - - message Response { - Error error = 1; - repeated google.protobuf.Struct records = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - message Graph { - message Request { - repeated anytype.model.Block.Content.Dataview.Filter filters = 1; - int32 limit = 2; - // additional filter by objectTypes - repeated string objectTypeFilter = 3; - repeated string keys = 4; - } - - message Edge { - enum Type { - Link = 0; - Relation = 1; - } - string source = 1; - string target = 2; - string name = 3; - Type type = 4; - string description = 5; - string iconImage = 6; - string iconEmoji = 7; - bool hidden = 8; - } - - message Response { - Error error = 1; - repeated google.protobuf.Struct nodes = 2; - repeated Edge edges = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message SearchSubscribe { - message Request { - // (optional) subscription identifier - // client can provide some string or middleware will generate it automatically - // if subId is already registered on middleware, the new query will replace previous subscription - string subId = 1; - // filters - repeated anytype.model.Block.Content.Dataview.Filter filters = 2; - // sorts - repeated anytype.model.Block.Content.Dataview.Sort sorts = 3; - // results limit - int64 limit = 5; - // initial offset; middleware will find afterId - int64 offset = 6; - // (required) needed keys in details for return, for object fields mw will return (and subscribe) objects as dependent - repeated string keys = 7; - - // (optional) pagination: middleware will return results after given id - string afterId = 8; - // (optional) pagination: middleware will return results before given id - string beforeId = 9; - - repeated string source = 10; - - string ignoreWorkspace = 12; - // disable dependent subscription - bool noDepSubscription = 13; - } - - message Response { - Error error = 1; - - repeated google.protobuf.Struct records = 2; - repeated google.protobuf.Struct dependencies = 3; - - string subId = 4; - - Event.Object.Subscription.Counters counters = 5; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message IdsSubscribe { - message Request { - // (optional) subscription identifier - // client can provide some string or middleware will generate it automatically - // if subId is already registered on middleware, the new query will replace previous subscription - string subId = 1; - // ids for subscribe - repeated string ids = 2; - // sorts - // (required) needed keys in details for return, for object fields mw will return (and subscribe) objects as dependent - repeated string keys = 3; - - string ignoreWorkspace = 11; - } - - message Response { - Error error = 1; - - repeated google.protobuf.Struct records = 2; - repeated google.protobuf.Struct dependencies = 3; - - string subId = 4; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message SearchUnsubscribe { - message Request { - repeated string subIds = 1; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - } - } - } - } - - message SetLayout { - message Request { - string contextId = 1; - anytype.model.ObjectType.Layout layout = 3; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message SetIsFavorite { - message Request { - string contextId = 1; - bool isFavorite = 2; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message SetIsArchived { - message Request { - string contextId = 1; - bool isArchived = 2; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message FeaturedRelation { - message Add { - message Request { - string contextId = 1; - repeated string relations = 2; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message Remove { - message Request { - string contextId = 1; - repeated string relations = 2; - } - - message Response { - Error error = 1; - ResponseEvent event = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - } - - message ToSet { - message Request { - string contextId = 1; - repeated string source = 2; - } - - message Response { - Error error = 1; - string setId = 2; message Error { Code code = 1; @@ -3764,15 +3371,267 @@ message Rpc { } } - message ObjectList { - message Duplicate { + message BlockDataview { + message View { + message Create { + message Request { + string contextId = 1; + string blockId = 2; // id of dataview block to insert the new block + anytype.model.Block.Content.Dataview.View view = 4; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + string viewId = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message Update { + message Request { + string contextId = 1; + string blockId = 2; // id of dataview block to update + string viewId = 3; // id of view to update + anytype.model.Block.Content.Dataview.View view = 4; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message Delete { + message Request { + string contextId = 1; // id of the context object + string blockId = 2; // id of the dataview + string viewId = 4; // id of the view to remove + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message SetPosition { + message Request { + string contextId = 1; // id of the context object + string blockId = 2; // id of the dataview + string viewId = 4; // id of the view to remove + uint32 position = 5; // index of view position (0 - means first) + } + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + // set the current active view (persisted only within a session) + message SetActive { + message Request { + string contextId = 1; + string blockId = 2; // id of dataview block + string viewId = 3; // id of active view + uint32 offset = 4; + uint32 limit = 5; + } + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + message Relation { + message Add { + message Request { + string contextId = 1; + string blockId = 2; // id of dataview block to add relation + anytype.model.Relation relation = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + string relationKey = 3; // deprecated + anytype.model.Relation relation = 4; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message Update { + message Request { + string contextId = 1; + string blockId = 2; // id of dataview block to add relation + string relationKey = 3; // key of relation to update + anytype.model.Relation relation = 4; + } + + message Response { + Error error = 1; + ResponseEvent event = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message Delete { + message Request { + string contextId = 1; + string blockId = 2; // id of dataview block to add relation + string relationKey = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + message ListAvailable { + message Request { + string contextId = 1; + string blockId = 2; + } + + message Response { + Error error = 1; + repeated anytype.model.Relation relations = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + NOT_A_DATAVIEW_BLOCK = 3; + // ... + } + } + } + } + } + message SetSource { message Request { - repeated string objectIds = 1; + string contextId = 1; + string blockId = 2; + repeated string source = 3; + } + + message Response { + Error error = 1; + ResponseEvent event = 4; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + } + + message BlockDataviewRecord { + message Update { + message Request { + string contextId = 1; + string blockId = 2; + string recordId = 3; + google.protobuf.Struct record = 4; } message Response { Error error = 1; - repeated string ids = 2; message Error { Code code = 1; @@ -3788,10 +3647,12 @@ message Rpc { } } message Delete { - // Deletes the object, keys from the local store and unsubscribe from remote changes. Also offloads all orphan files message Request { - repeated string objectIds = 1; // objects to remove + string contextId = 1; + string blockId = 2; + string recordId = 3; } + message Response { Error error = 1; ResponseEvent event = 2; @@ -3809,15 +3670,46 @@ message Rpc { } } } - message Set { - message IsArchived { + message Create { + message Request { + string contextId = 1; + string blockId = 2; + google.protobuf.Struct record = 3; + string templateId = 4; + } + + message Response { + Error error = 1; + google.protobuf.Struct record = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + message RelationOption { + // Add may return existing option in case object specified with recordId already have the option with the same name or ID + message Add { message Request { - repeated string objectIds = 1; - bool isArchived = 2; + string contextId = 1; + string blockId = 2; // id of dataview block to add relation + string relationKey = 3; // relation key to add the option + anytype.model.Relation.Option option = 4; // id of select options will be autogenerated + string recordId = 5; // id of record which is used to add an option } message Response { Error error = 1; + ResponseEvent event = 2; + anytype.model.Relation.Option option = 3; message Error { Code code = 1; @@ -3827,19 +3719,22 @@ message Rpc { NULL = 0; UNKNOWN_ERROR = 1; BAD_INPUT = 2; - // ... } } } } - message IsFavorite { + message Update { message Request { - repeated string objectIds = 1; - bool isFavorite = 2; + string contextId = 1; + string blockId = 2; // id of dataview block to add relation + string relationKey = 3; // relation key to add the option + anytype.model.Relation.Option option = 4; // id of select options will be autogenerated + string recordId = 5; // id of record which is used to update an option } message Response { Error error = 1; + ResponseEvent event = 2; message Error { Code code = 1; @@ -3849,313 +3744,33 @@ message Rpc { NULL = 0; UNKNOWN_ERROR = 1; BAD_INPUT = 2; - // ... } } } } - } - } - - message Export { - message Request { - // the path where export files will place - string path = 1; - // ids of documents for export, when empty - will export all available docs - repeated string docIds = 2; - // export format - Format format = 3; - // save as zip file - bool zip = 4; - // include all nested - bool includeNested = 5; - // include all files - bool includeFiles = 6; - } - - message Response { - Error error = 1; - string path = 2; - int32 succeed = 4; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... + message Delete { + message Request { + string contextId = 1; + string blockId = 2; // id of dataview block to add relation + string relationKey = 3; // relation key to add the option + string optionId = 4; // id of select options to remove + string recordId = 5; // id of record which is used to delete an option } - } - } - enum Format { - Markdown = 0; - Protobuf = 1; - JSON = 2; - DOT = 3; - SVG = 4; - GRAPH_JSON = 5; - } - } + message Response { + Error error = 1; + ResponseEvent event = 2; - message ExportWorkspace { - message Request { - // the path where export files will place - string path = 1; - string workspaceId = 2; - } + message Error { + Code code = 1; + string description = 2; - message Response { - Error error = 1; - string path = 2; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message ExportTemplates { - message Request { - // the path where export files will place - string path = 1; - } - - message Response { - Error error = 1; - string path = 2; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message ExportLocalstore { - message Request { - // the path where export files will place - string path = 1; - // ids of documents for export, when empty - will export all available docs - repeated string docIds = 2; - } - - message Response { - Error error = 1; - string path = 2; - ResponseEvent event = 3; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - - message MakeTemplate { - message Request { - // id of block for making them template - string contextId = 1; - } - - message Response { - Error error = 1; - // created template id - string id = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message MakeTemplateByObjectType { - message Request { - // id of desired object type - string objectType = 1; - } - - message Response { - Error error = 1; - // created template id - string id = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message CloneTemplate { - message Request { - // id of template block for cloning - string contextId = 1; - } - - message Response { - Error error = 1; - // created template id - string id = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message ObjectDuplicate { - message Request { - string contextId = 1; - } - - message Response { - Error error = 1; - string id = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... - } - } - } - } - - message UnsplashSearch { - message Request { - string query = 1; // empty means random images - int32 limit = 2; // may be omitted if the request was cached previously with another limit - } - - message Response { - Error error = 1; - repeated Picture pictures = 2; - - message Picture { - string id = 1; - string url = 2; - string artist = 3; - string artistUrl = 4; - } - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - - RATE_LIMIT_EXCEEDED = 100; - // ... - } - } - } - } - - message UnsplashDownload { - message Request { - string pictureId = 1; - } - - message Response { - Error error = 1; - string hash = 2; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - - RATE_LIMIT_EXCEEDED = 100; - // ... - } - } - } - } - - message ApplyTemplate { - message Request { - string contextId = 1; - // id of template - string templateId = 2; - } - - message Response { - Error error = 1; - - message Error { - Code code = 1; - string description = 2; - - enum Code { - NULL = 0; - UNKNOWN_ERROR = 1; - BAD_INPUT = 2; - // ... + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } } } } @@ -4252,7 +3867,7 @@ message Rpc { message Tree { message Request { - string blockId = 1; + string objectId = 1; string path = 2; bool unanonymized = 3; // set to true to disable mocking of the actual data inside changes bool generateSvg = 4; // set to true to write both ZIP and SVG files @@ -4276,7 +3891,137 @@ message Rpc { } } + message ExportLocalstore { + message Request { + // the path where export files will place + string path = 1; + // ids of documents for export, when empty - will export all available docs + repeated string docIds = 2; + } + message Response { + Error error = 1; + string path = 2; + ResponseEvent event = 3; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + + message Ping { + message Request { + int32 index = 1; + int32 numberOfEventsToSend = 2; + } + + message Response { + Error error = 1; + int32 index = 2; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } + } + + message Metrics { + message SetParameters { + message Request { + string platform = 1; + } + + message Response { + Error error = 1; + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + // ... + } + } + } + } + } + + message Log { + message Send { + message Request { + string message = 1; + Level level = 2; + + enum Level { + DEBUG = 0; + ERROR = 1; + FATAL = 2; + INFO = 3; + PANIC = 4; + WARNING = 5; + } + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + + NOT_FOUND = 101; + TIMEOUT = 102; + } + } + } + } + } + + message Process { + message Cancel { + message Request { + string id = 1; + } + + message Response { + Error error = 1; + + message Error { + Code code = 1; + string description = 2; + + enum Code { + NULL = 0; + UNKNOWN_ERROR = 1; + BAD_INPUT = 2; + } + } + } + } } message GenericErrorResponse { diff --git a/protocol/src/main/proto/events.proto b/protocol/src/main/proto/events.proto index 3e45e4c7a8..5bf17d8cba 100644 --- a/protocol/src/main/proto/events.proto +++ b/protocol/src/main/proto/events.proto @@ -1,11 +1,10 @@ syntax = "proto3"; package anytype; - -import "google/protobuf/struct.proto"; -import "models.proto"; - option go_package = "pb"; +import "models.proto"; +import "google/protobuf/struct.proto"; + /* * Event – type of message, that could be sent from a middleware to the corresponding front-end. */ @@ -98,7 +97,6 @@ message Event { google.protobuf.Struct details = 2; } - // Deprecated message Config { message Update { anytype.model.Account.Config config = 1; @@ -306,7 +304,7 @@ message Event { message Text { string id = 1; - TText text = 2; + Text text = 2; Style style = 3; Marks marks = 4; Checked checked = 5; @@ -314,7 +312,7 @@ message Event { IconEmoji iconEmoji = 7; IconImage iconImage = 8; - message TText { + message Text { string value = 1; } @@ -520,13 +518,13 @@ message Event { message Text { string id = 1; - TText text = 2; + Text text = 2; Style style = 3; Marks marks = 4; Checked checked = 5; Color color = 6; - message TText { + message Text { string value = 1; } diff --git a/protocol/src/main/proto/localstore.proto b/protocol/src/main/proto/localstore.proto index bed763ba35..8cb3555fcc 100644 --- a/protocol/src/main/proto/localstore.proto +++ b/protocol/src/main/proto/localstore.proto @@ -1,11 +1,10 @@ syntax = "proto3"; package anytype.model; +option go_package = "pkg/lib/pb/model"; import "google/protobuf/struct.proto"; import "models.proto"; -option go_package = "pkg/lib/pb/model"; - message ObjectInfo { string id = 1; repeated string objectTypeUrls = 2; // deprecated diff --git a/protocol/src/main/proto/models.proto b/protocol/src/main/proto/models.proto index 8b53e13a47..5aa4498db4 100644 --- a/protocol/src/main/proto/models.proto +++ b/protocol/src/main/proto/models.proto @@ -1,10 +1,9 @@ syntax = "proto3"; package anytype.model; +option go_package = "pkg/lib/pb/model"; import "google/protobuf/struct.proto"; -option go_package = "pkg/lib/pb/model"; - message SmartBlockSnapshotBase { repeated Block blocks = 1; google.protobuf.Struct details = 2; @@ -413,6 +412,7 @@ message Account { Avatar avatar = 3; // Avatar of a user's account Config config = 4; Status status = 5; + Info info = 6; /** * Avatar of a user's account. It could be an image or color @@ -423,7 +423,6 @@ message Account { string color = 2; // Color of the avatar, used if image not set. } } - message Config { bool enableDataview = 1; bool enableDebug = 2; @@ -444,6 +443,18 @@ message Account { StartedDeletion = 2; Deleted = 3; } + + message Info { + string homeObjectId = 2; // home dashboard block id + string archiveObjectId = 3; // archive block id + string profileObjectId = 4; // profile block id + string marketplaceTypeObjectId = 5; // marketplace type id + string marketplaceRelationObjectId = 6; // marketplace relation id + string marketplaceTemplateObjectId = 7; // marketplace template id + string deviceId = 8; + string gatewayUrl = 101; // gateway url for fetching static files + } + } message LinkPreview { diff --git a/test/core-models-stub/src/main/java/com/anytypeio/anytype/core_models/Auth.kt b/test/core-models-stub/src/main/java/com/anytypeio/anytype/core_models/Auth.kt new file mode 100644 index 0000000000..0019e7ff98 --- /dev/null +++ b/test/core-models-stub/src/main/java/com/anytypeio/anytype/core_models/Auth.kt @@ -0,0 +1,49 @@ +package com.anytypeio.anytype.core_models + +import com.anytypeio.anytype.test_utils.MockDataFactory + +fun StubAccountSetup( + account : Account = StubAccount(), + config: Config = StubConfig(), + features: FeaturesConfig = StubFeatureConfig(), + status: AccountStatus = AccountStatus.Active +) : AccountSetup = AccountSetup( + account = account, + features = features, + status = status, + config = config +) + +fun StubAccount( + id : Id = MockDataFactory.randomUuid(), + name: String = MockDataFactory.randomString(), + avatar: Url? = null, + color: String? = null +) : Account = Account( + id = id, + name = name, + avatar = avatar, + color = color +) + +fun StubConfig( + home: Id = MockDataFactory.randomUuid(), + profile: Id = MockDataFactory.randomUuid(), + gateway: Url = MockDataFactory.randomUuid() +) : Config = Config( + home = home, + profile = profile, + gateway = gateway +) + +fun StubFeatureConfig( + enableDataView: Boolean? = MockDataFactory.randomBoolean(), + enableDebug: Boolean? = MockDataFactory.randomBoolean(), + enableChannelSwitch: Boolean? = MockDataFactory.randomBoolean(), + enableSpaces: Boolean? = MockDataFactory.randomBoolean() +) : FeaturesConfig = FeaturesConfig( + enableDataView = enableDataView, + enableDebug = enableDebug, + enableChannelSwitch = enableChannelSwitch, + enableSpaces = enableSpaces +) \ No newline at end of file