Initial public release of Warp.
Repo-Sync-Origin: warpdotdev/warp-internal@12af1d983b
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
use warpui::{async_assert, integration::AssertionCallback};
|
||||
|
||||
use crate::{
|
||||
cloud_object::{model::persistence::CloudModel, CloudModelType, GenericCloudObject, Revision},
|
||||
server::ids::{HashableId, ServerId, SyncId, ToServerId},
|
||||
};
|
||||
|
||||
/// Asserts metadata exists for the object with the given key and that the revision in that
|
||||
/// metadata matches the given expected revision.
|
||||
pub fn assert_metadata_revision<K, M>(id: &str, expected_revision: i64) -> AssertionCallback
|
||||
where
|
||||
K: HashableId + ToServerId + std::fmt::Debug + Into<String> + Clone + 'static,
|
||||
M: CloudModelType<IdType = K, CloudObjectType = GenericCloudObject<K, M>> + 'static,
|
||||
{
|
||||
let id = SyncId::ServerId(ServerId::try_from(id).expect("ID is invalid"));
|
||||
Box::new(move |app, _window_id| {
|
||||
let revision =
|
||||
app.get_singleton_model_handle::<CloudModel>()
|
||||
.read(app, |cloud_model, _| {
|
||||
let object = cloud_model
|
||||
.get_object_of_type::<K, M>(&id)
|
||||
.expect("object should exist");
|
||||
object
|
||||
.metadata
|
||||
.revision
|
||||
.clone()
|
||||
.expect("revision should exist")
|
||||
});
|
||||
async_assert!(
|
||||
revision
|
||||
== Revision::from_unix_timestamp_micros(expected_revision)
|
||||
.expect("revison should parse"),
|
||||
"Expected revision to be:{expected_revision:?}\nBut got:\n{revision:?}"
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
mod assertion;
|
||||
|
||||
pub use assertion::*;
|
||||
use futures::{future::join_all, FutureExt};
|
||||
use itertools::Itertools;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use warpui::{App, SingletonEntity};
|
||||
|
||||
use crate::{
|
||||
cloud_object::{model::persistence::CloudModel, Space},
|
||||
server::cloud_objects::update_manager::UpdateManager,
|
||||
};
|
||||
|
||||
/// Clears the cloud model of all non-welcome objects in the user's personal space.
|
||||
/// Returns a future that resolves when the cloud model is cleared.
|
||||
pub fn clear_cloud_model(app: &mut App) -> Pin<Box<dyn Future<Output = ()> + Send>> {
|
||||
let object_ids_to_delete = CloudModel::handle(app).read(app, |cloud_model, ctx| {
|
||||
cloud_model
|
||||
.active_non_welcome_cloud_objects_in_space(Space::Personal, ctx)
|
||||
.map(|object| object.cloud_object_type_and_id())
|
||||
.collect_vec()
|
||||
});
|
||||
|
||||
let mut futures = Vec::new();
|
||||
for object_id in object_ids_to_delete {
|
||||
UpdateManager::handle(app).update(app, |update_manager, ctx| {
|
||||
update_manager.delete_object_by_user(object_id, ctx);
|
||||
if let Some(future_id) = update_manager.spawned_futures().last() {
|
||||
let future = ctx.await_spawned_future(*future_id);
|
||||
futures.push(future);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Box::pin(join_all(futures).map(|_| ()))
|
||||
}
|
||||
Reference in New Issue
Block a user