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 new_sub_account(
40        &self, account: &Account, request: NewSubAccountRequest,
41    ) -> impl Future<Output = ApiResult<NewSubAccountRequest>> + MaybeSend;
42
43    fn list_sub_accounts(
44        &self, account: &Account, request: ListSubAccountsRequest,
45    ) -> impl Future<Output = ApiResult<ListSubAccountsRequest>> + MaybeSend;
46
47    fn delete_sub_account(
48        &self, account: &Account, request: DeleteSubAccountRequest,
49    ) -> impl Future<Output = ApiResult<DeleteSubAccountRequest>> + MaybeSend;
50
51    fn change_doc_v2(
52        &self, account: &Account, request: ChangeDocRequestV2,
53    ) -> impl Future<Output = ApiResult<ChangeDocRequestV2>> + MaybeSend;
54
55    fn upsert_file_metadata_v2(
56        &self, account: &Account, request: UpsertRequestV2,
57    ) -> impl Future<Output = ApiResult<UpsertRequestV2>> + MaybeSend;
58
59    fn get_document(
60        &self, account: &Account, request: GetDocRequest,
61    ) -> impl Future<Output = ApiResult<GetDocRequest>> + MaybeSend;
62
63    fn get_public_key(
64        &self, account: &Account, request: GetPublicKeyRequest,
65    ) -> impl Future<Output = ApiResult<GetPublicKeyRequest>> + MaybeSend;
66
67    fn get_username(
68        &self, account: &Account, request: GetUsernameRequest,
69    ) -> impl Future<Output = ApiResult<GetUsernameRequest>> + MaybeSend;
70
71    fn get_usage(
72        &self, account: &Account, request: GetUsageRequest,
73    ) -> impl Future<Output = ApiResult<GetUsageRequest>> + MaybeSend;
74
75    fn get_file_ids(
76        &self, account: &Account, request: GetFileIdsRequest,
77    ) -> impl Future<Output = ApiResult<GetFileIdsRequest>> + MaybeSend;
78
79    fn get_updates_v2(
80        &self, account: &Account, request: GetUpdatesRequestV2,
81    ) -> impl Future<Output = ApiResult<GetUpdatesRequestV2>> + MaybeSend;
82
83    fn get_build_info(
84        &self, account: &Account, request: GetBuildInfoRequest,
85    ) -> impl Future<Output = ApiResult<GetBuildInfoRequest>> + MaybeSend;
86
87    fn delete_account(
88        &self, account: &Account, request: DeleteAccountRequest,
89    ) -> impl Future<Output = ApiResult<DeleteAccountRequest>> + MaybeSend;
90
91    fn stripe_checkout(
92        &self, account: &Account, request: StripeCheckoutRequest,
93    ) -> impl Future<Output = ApiResult<StripeCheckoutRequest>> + MaybeSend;
94
95    fn stripe_billing_portal(
96        &self, account: &Account, request: StripeBillingPortalRequest,
97    ) -> impl Future<Output = ApiResult<StripeBillingPortalRequest>> + MaybeSend;
98
99    fn upgrade_account_google_play(
100        &self, account: &Account, request: UpgradeAccountGooglePlayRequest,
101    ) -> impl Future<Output = ApiResult<UpgradeAccountGooglePlayRequest>> + MaybeSend;
102
103    fn upgrade_account_app_store(
104        &self, account: &Account, request: UpgradeAccountAppStoreRequest,
105    ) -> impl Future<Output = ApiResult<UpgradeAccountAppStoreRequest>> + MaybeSend;
106
107    fn cancel_subscription(
108        &self, account: &Account, request: CancelSubscriptionRequest,
109    ) -> impl Future<Output = ApiResult<CancelSubscriptionRequest>> + MaybeSend;
110
111    fn get_subscription_info(
112        &self, account: &Account, request: GetSubscriptionInfoRequest,
113    ) -> impl Future<Output = ApiResult<GetSubscriptionInfoRequest>> + MaybeSend;
114
115    fn get_subscription_info_v2(
116        &self, account: &Account, request: GetSubscriptionInfoRequestV2,
117    ) -> impl Future<Output = ApiResult<GetSubscriptionInfoRequestV2>> + MaybeSend;
118
119    fn upsert_debug_info(
120        &self, account: &Account, request: UpsertDebugInfoRequest,
121    ) -> impl Future<Output = ApiResult<UpsertDebugInfoRequest>> + MaybeSend;
122
123    fn admin_disappear_account(
124        &self, account: &Account, request: AdminDisappearAccountRequest,
125    ) -> impl Future<Output = ApiResult<AdminDisappearAccountRequest>> + MaybeSend;
126
127    fn admin_disappear_file(
128        &self, account: &Account, request: AdminDisappearFileRequest,
129    ) -> impl Future<Output = ApiResult<AdminDisappearFileRequest>> + MaybeSend;
130
131    fn admin_validate_account(
132        &self, account: &Account, request: AdminValidateAccountRequest,
133    ) -> impl Future<Output = ApiResult<AdminValidateAccountRequest>> + MaybeSend;
134
135    fn admin_validate_server(
136        &self, account: &Account, request: AdminValidateServerRequest,
137    ) -> impl Future<Output = ApiResult<AdminValidateServerRequest>> + MaybeSend;
138
139    fn admin_list_users(
140        &self, account: &Account, request: AdminListUsersRequest,
141    ) -> impl Future<Output = ApiResult<AdminListUsersRequest>> + MaybeSend;
142
143    fn admin_get_account_info(
144        &self, account: &Account, request: AdminGetAccountInfoRequest,
145    ) -> impl Future<Output = ApiResult<AdminGetAccountInfoRequest>> + MaybeSend;
146
147    fn admin_file_info(
148        &self, account: &Account, request: AdminFileInfoRequest,
149    ) -> impl Future<Output = ApiResult<AdminFileInfoRequest>> + MaybeSend;
150
151    fn admin_set_user_tier(
152        &self, account: &Account, request: AdminSetUserTierRequest,
153    ) -> impl Future<Output = ApiResult<AdminSetUserTierRequest>> + MaybeSend;
154
155    fn admin_sync_stripe(
156        &self, account: &Account, request: AdminSyncStripeRequest,
157    ) -> impl Future<Output = ApiResult<AdminSyncStripeRequest>> + MaybeSend;
158
159    fn admin_rebuild_index(
160        &self, account: &Account, request: AdminRebuildIndexRequest,
161    ) -> impl Future<Output = ApiResult<AdminRebuildIndexRequest>> + MaybeSend;
162}