Skip to main content

lb_rs/io/
server.rs

1use std::future::Future;
2
3use crate::io::network::ApiError;
4use crate::model::account::Account;
5use crate::model::api::*;
6
7/// What a request of type `T` resolves to.
8pub type ApiResult<T> = Result<<T as Request>::Response, ApiError<<T as Request>::Error>>;
9
10/// `Send` on native targets, where lb-rs spawns onto tokio's thread pool; nothing on wasm, whose
11/// HTTP futures are single-threaded.
12#[cfg(not(target_family = "wasm"))]
13pub trait MaybeSend: Send {}
14#[cfg(not(target_family = "wasm"))]
15impl<T: Send> MaybeSend for T {}
16
17#[cfg(target_family = "wasm")]
18pub trait MaybeSend {}
19#[cfg(target_family = "wasm")]
20impl<T> MaybeSend for T {}
21
22/// `Sync` where [MaybeSend] is `Send`.
23#[cfg(not(target_family = "wasm"))]
24pub trait MaybeSync: Sync {}
25#[cfg(not(target_family = "wasm"))]
26impl<T: Sync> MaybeSync for T {}
27
28#[cfg(target_family = "wasm")]
29pub trait MaybeSync {}
30#[cfg(target_family = "wasm")]
31impl<T> MaybeSync for T {}
32
33/// Lockbook's server as lb-rs reaches it: one method per [Request] in [crate::model::api].
34pub trait Server: Clone + MaybeSend + MaybeSync + 'static {
35    fn new_account_v2(
36        &self, account: &Account, request: NewAccountRequestV2,
37    ) -> impl Future<Output = ApiResult<NewAccountRequestV2>> + MaybeSend;
38
39    fn change_doc_v2(
40        &self, account: &Account, request: ChangeDocRequestV2,
41    ) -> impl Future<Output = ApiResult<ChangeDocRequestV2>> + MaybeSend;
42
43    fn upsert_file_metadata_v2(
44        &self, account: &Account, request: UpsertRequestV2,
45    ) -> impl Future<Output = ApiResult<UpsertRequestV2>> + MaybeSend;
46
47    fn get_document(
48        &self, account: &Account, request: GetDocRequest,
49    ) -> impl Future<Output = ApiResult<GetDocRequest>> + MaybeSend;
50
51    fn get_public_key(
52        &self, account: &Account, request: GetPublicKeyRequest,
53    ) -> impl Future<Output = ApiResult<GetPublicKeyRequest>> + MaybeSend;
54
55    fn get_username(
56        &self, account: &Account, request: GetUsernameRequest,
57    ) -> impl Future<Output = ApiResult<GetUsernameRequest>> + MaybeSend;
58
59    fn get_usage(
60        &self, account: &Account, request: GetUsageRequest,
61    ) -> impl Future<Output = ApiResult<GetUsageRequest>> + MaybeSend;
62
63    fn get_file_ids(
64        &self, account: &Account, request: GetFileIdsRequest,
65    ) -> impl Future<Output = ApiResult<GetFileIdsRequest>> + MaybeSend;
66
67    fn get_updates_v2(
68        &self, account: &Account, request: GetUpdatesRequestV2,
69    ) -> impl Future<Output = ApiResult<GetUpdatesRequestV2>> + MaybeSend;
70
71    fn get_build_info(
72        &self, account: &Account, request: GetBuildInfoRequest,
73    ) -> impl Future<Output = ApiResult<GetBuildInfoRequest>> + MaybeSend;
74
75    fn delete_account(
76        &self, account: &Account, request: DeleteAccountRequest,
77    ) -> impl Future<Output = ApiResult<DeleteAccountRequest>> + MaybeSend;
78
79    fn upgrade_account_stripe(
80        &self, account: &Account, request: UpgradeAccountStripeRequest,
81    ) -> impl Future<Output = ApiResult<UpgradeAccountStripeRequest>> + MaybeSend;
82
83    fn upgrade_account_google_play(
84        &self, account: &Account, request: UpgradeAccountGooglePlayRequest,
85    ) -> impl Future<Output = ApiResult<UpgradeAccountGooglePlayRequest>> + MaybeSend;
86
87    fn upgrade_account_app_store(
88        &self, account: &Account, request: UpgradeAccountAppStoreRequest,
89    ) -> impl Future<Output = ApiResult<UpgradeAccountAppStoreRequest>> + MaybeSend;
90
91    fn cancel_subscription(
92        &self, account: &Account, request: CancelSubscriptionRequest,
93    ) -> impl Future<Output = ApiResult<CancelSubscriptionRequest>> + MaybeSend;
94
95    fn get_subscription_info(
96        &self, account: &Account, request: GetSubscriptionInfoRequest,
97    ) -> impl Future<Output = ApiResult<GetSubscriptionInfoRequest>> + MaybeSend;
98
99    fn get_subscription_info_v2(
100        &self, account: &Account, request: GetSubscriptionInfoRequestV2,
101    ) -> impl Future<Output = ApiResult<GetSubscriptionInfoRequestV2>> + MaybeSend;
102
103    fn upsert_debug_info(
104        &self, account: &Account, request: UpsertDebugInfoRequest,
105    ) -> impl Future<Output = ApiResult<UpsertDebugInfoRequest>> + MaybeSend;
106
107    fn admin_disappear_account(
108        &self, account: &Account, request: AdminDisappearAccountRequest,
109    ) -> impl Future<Output = ApiResult<AdminDisappearAccountRequest>> + MaybeSend;
110
111    fn admin_disappear_file(
112        &self, account: &Account, request: AdminDisappearFileRequest,
113    ) -> impl Future<Output = ApiResult<AdminDisappearFileRequest>> + MaybeSend;
114
115    fn admin_validate_account(
116        &self, account: &Account, request: AdminValidateAccountRequest,
117    ) -> impl Future<Output = ApiResult<AdminValidateAccountRequest>> + MaybeSend;
118
119    fn admin_validate_server(
120        &self, account: &Account, request: AdminValidateServerRequest,
121    ) -> impl Future<Output = ApiResult<AdminValidateServerRequest>> + MaybeSend;
122
123    fn admin_list_users(
124        &self, account: &Account, request: AdminListUsersRequest,
125    ) -> impl Future<Output = ApiResult<AdminListUsersRequest>> + MaybeSend;
126
127    fn admin_get_account_info(
128        &self, account: &Account, request: AdminGetAccountInfoRequest,
129    ) -> impl Future<Output = ApiResult<AdminGetAccountInfoRequest>> + MaybeSend;
130
131    fn admin_file_info(
132        &self, account: &Account, request: AdminFileInfoRequest,
133    ) -> impl Future<Output = ApiResult<AdminFileInfoRequest>> + MaybeSend;
134
135    fn admin_set_user_tier(
136        &self, account: &Account, request: AdminSetUserTierRequest,
137    ) -> impl Future<Output = ApiResult<AdminSetUserTierRequest>> + MaybeSend;
138
139    fn admin_rebuild_index(
140        &self, account: &Account, request: AdminRebuildIndexRequest,
141    ) -> impl Future<Output = ApiResult<AdminRebuildIndexRequest>> + MaybeSend;
142}