From b37fc039c803f53dd6dc77aa7d6ce24eec520e3d Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Wed, 31 Aug 2022 18:42:06 +0800 Subject: [PATCH] new invalidate_query + add IOS sim to setup script --- .github/scripts/setup-system.sh | 3 ++- core/src/api/files.rs | 13 +----------- core/src/api/utils/invalidate.rs | 35 +++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/.github/scripts/setup-system.sh b/.github/scripts/setup-system.sh index 433f73112..2c8ace653 100755 --- a/.github/scripts/setup-system.sh +++ b/.github/scripts/setup-system.sh @@ -38,7 +38,8 @@ if [ "$1" == "mobile" ]; then exit 1 fi - rustup target add aarch64-apple-ios + rustup target add aarch64-apple-ios + rustup target add aarch64-apple-ios-sim fi # Android requires python diff --git a/core/src/api/files.rs b/core/src/api/files.rs index e8329c6ac..9b08c27fc 100644 --- a/core/src/api/files.rs +++ b/core/src/api/files.rs @@ -30,18 +30,7 @@ pub(crate) fn mount() -> RouterBuilder { .exec() .await?; - invalidate_query!( - library, - "locations.getExplorerDir": LibraryArgs, - LibraryArgs { - library_id: library.id, - arg: GetExplorerDirArgs { - location_id: 0, // TODO: This should be the correct location_id - path: "".into(), - limit: 0, - } - } - ); + invalidate_query!(library, "locations.getExplorerDir"); Ok(()) }) diff --git a/core/src/api/utils/invalidate.rs b/core/src/api/utils/invalidate.rs index df397577d..9eff8d147 100644 --- a/core/src/api/utils/invalidate.rs +++ b/core/src/api/utils/invalidate.rs @@ -34,7 +34,7 @@ impl InvalidateOperationEvent { #[allow(dead_code)] pub(crate) struct InvalidationRequest { pub key: &'static str, - pub arg_ty: DataType, + pub arg_ty: Option, pub macro_src: &'static str, } @@ -58,11 +58,13 @@ impl InvalidRequests { let queries = r.queries(); for req in &invalidate_requests.queries { if let Some(query_ty) = queries.get(req.key) { - if query_ty.ty.arg_ty != req.arg_ty { - panic!( + if let Some(arg) = &req.arg_ty { + if &query_ty.ty.arg_ty != arg { + panic!( "Error at '{}': Attempted to invalid query '{}' but the argument type does not match the type defined on the router.", req.macro_src, req.key ); + } } } else { panic!( @@ -87,6 +89,29 @@ impl InvalidRequests { #[macro_export] #[allow(clippy::crate_in_macro_def)] macro_rules! invalidate_query { + ($ctx:expr, $key:literal) => {{ + let _: &crate::library::LibraryContext = &$ctx; // Assert the context is the correct type + + #[cfg(debug_assertions)] + { + #[ctor::ctor] + fn invalidate() { + crate::api::utils::INVALIDATION_REQUESTS + .get_or_init(|| Default::default()) + .lock() + .unwrap() + .queries + .push(crate::api::utils::InvalidationRequest { + key: $key, + arg_ty: None, + macro_src: concat!(file!(), ":", line!()), + }) + } + } + + // The error are ignored here because they aren't mission critical. If they fail the UI might be outdated for a bit. + crate::api::utils::InvalidateOperationEvent::dangerously_create($key, serde_json::Value::Null) + }}; ($ctx:expr, $key:literal: $arg_ty:ty, $arg:expr) => {{ let _: $arg_ty = $arg; // Assert the type the user provided is correct let ctx: &crate::library::LibraryContext = &$ctx; // Assert the context is the correct type @@ -102,10 +127,10 @@ macro_rules! invalidate_query { .queries .push(crate::api::utils::InvalidationRequest { key: $key, - arg_ty: <$arg_ty as rspc::internal::specta::Type>::reference(rspc::internal::specta::DefOpts { + arg_ty: Some(<$arg_ty as rspc::internal::specta::Type>::reference(rspc::internal::specta::DefOpts { parent_inline: false, type_map: &mut rspc::internal::specta::TypeDefs::new(), - }, &[]), + }, &[])), macro_src: concat!(file!(), ":", line!()), }) }