44
55use crate :: config:: RemoteSettingsConfig ;
66use crate :: error:: { Error , Result } ;
7+ #[ cfg( feature = "jexl" ) ]
78use crate :: jexl_filter:: JexlFilter ;
89use crate :: storage:: Storage ;
9- use crate :: { RemoteSettingsContext , RemoteSettingsServer , UniffiCustomTypeConverter } ;
10+ #[ cfg( feature = "jexl" ) ]
11+ use crate :: RemoteSettingsContext ;
12+ use crate :: { RemoteSettingsServer , UniffiCustomTypeConverter } ;
1013use parking_lot:: Mutex ;
1114use serde:: { Deserialize , Serialize } ;
1215use std:: {
@@ -27,6 +30,7 @@ const HEADER_RETRY_AFTER: &str = "Retry-After";
2730pub struct RemoteSettingsClient < C = ViaductApiClient > {
2831 // This is immutable, so it can be outside the mutex
2932 collection_name : String ,
33+ #[ cfg( feature = "jexl" ) ]
3034 jexl_filter : JexlFilter ,
3135 inner : Mutex < RemoteSettingsClientInner < C > > ,
3236}
@@ -40,11 +44,12 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
4044 pub fn new_from_parts (
4145 collection_name : String ,
4246 storage : Storage ,
43- jexl_filter : JexlFilter ,
47+ # [ cfg ( feature = "jexl" ) ] jexl_filter : JexlFilter ,
4448 api_client : C ,
4549 ) -> Self {
4650 Self {
4751 collection_name,
52+ #[ cfg( feature = "jexl" ) ]
4853 jexl_filter,
4954 inner : Mutex :: new ( RemoteSettingsClientInner {
5055 storage,
@@ -57,6 +62,7 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
5762 }
5863
5964 /// Filters records based on the presence and evaluation of `filter_expression`.
65+ #[ cfg( feature = "jexl" ) ]
6066 fn filter_records ( & self , records : Vec < RemoteSettingsRecord > ) -> Vec < RemoteSettingsRecord > {
6167 records
6268 . into_iter ( )
@@ -69,6 +75,11 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
6975 . collect ( )
7076 }
7177
78+ #[ cfg( not( feature = "jexl" ) ) ]
79+ fn filter_records ( & self , records : Vec < RemoteSettingsRecord > ) -> Vec < RemoteSettingsRecord > {
80+ records
81+ }
82+
7283 /// Get the current set of records.
7384 ///
7485 /// If records are not present in storage this will normally return None. Use `sync_if_empty =
@@ -125,15 +136,17 @@ impl RemoteSettingsClient<ViaductApiClient> {
125136 server_url : Url ,
126137 bucket_name : String ,
127138 collection_name : String ,
128- context : Option < RemoteSettingsContext > ,
139+ # [ cfg ( feature = "jexl" ) ] context : Option < RemoteSettingsContext > ,
129140 storage : Storage ,
130141 ) -> Result < Self > {
131142 let api_client = ViaductApiClient :: new ( server_url, & bucket_name, & collection_name) ?;
143+ #[ cfg( feature = "jexl" ) ]
132144 let jexl_filter = JexlFilter :: new ( context) ;
133145
134146 Ok ( Self :: new_from_parts (
135147 collection_name,
136148 storage,
149+ #[ cfg( feature = "jexl" ) ]
137150 jexl_filter,
138151 api_client,
139152 ) )
@@ -1510,6 +1523,7 @@ mod test {
15101523mod test_new_client {
15111524 use super :: * ;
15121525
1526+ #[ cfg( not( feature = "jexl" ) ) ]
15131527 use serde_json:: json;
15141528
15151529 #[ test]
@@ -1536,6 +1550,7 @@ mod test_new_client {
15361550 }
15371551
15381552 #[ test]
1553+ #[ cfg( not( feature = "jexl" ) ) ]
15391554 fn test_get_records_none_cached ( ) {
15401555 let mut api_client = MockApiClient :: new ( ) ;
15411556 api_client. expect_collection_url ( ) . returning ( || {
@@ -1544,19 +1559,16 @@ mod test_new_client {
15441559 // Note, don't make any api_client.expect_*() calls, the RemoteSettingsClient should not
15451560 // attempt to make any requests for this scenario
15461561 let storage = Storage :: new ( ":memory:" . into ( ) ) . expect ( "Error creating storage" ) ;
1547- let rs_client = RemoteSettingsClient :: new_from_parts (
1548- "test-collection" . into ( ) ,
1549- storage,
1550- JexlFilter :: new ( None ) ,
1551- api_client,
1552- ) ;
1562+ let rs_client =
1563+ RemoteSettingsClient :: new_from_parts ( "test-collection" . into ( ) , storage, api_client) ;
15531564 assert_eq ! (
15541565 rs_client. get_records( false ) . expect( "Error getting records" ) ,
15551566 None
15561567 ) ;
15571568 }
15581569
15591570 #[ test]
1571+ #[ cfg( not( feature = "jexl" ) ) ]
15601572 fn test_get_records_none_cached_sync_with_empty ( ) {
15611573 let mut api_client = MockApiClient :: new ( ) ;
15621574 let records = vec ! [ RemoteSettingsRecord {
@@ -1577,23 +1589,19 @@ mod test_new_client {
15771589 }
15781590 } ) ;
15791591 let storage = Storage :: new ( ":memory:" . into ( ) ) . expect ( "Error creating storage" ) ;
1580- let rs_client = RemoteSettingsClient :: new_from_parts (
1581- "test-collection" . into ( ) ,
1582- storage,
1583- JexlFilter :: new ( None ) ,
1584- api_client,
1585- ) ;
1592+ let rs_client =
1593+ RemoteSettingsClient :: new_from_parts ( "test-collection" . into ( ) , storage, api_client) ;
15861594 assert_eq ! (
15871595 rs_client. get_records( true ) . expect( "Error getting records" ) ,
15881596 Some ( records)
15891597 ) ;
15901598 }
15911599}
15921600
1601+ #[ cfg( feature = "jexl" ) ]
15931602#[ cfg( test) ]
1594- mod test_filtering_records {
1603+ mod jexl_tests {
15951604 use super :: * ;
1596- use serde_json:: json;
15971605
15981606 #[ test]
15991607 fn test_get_records_filtered_app_version_pass ( ) {
@@ -1603,7 +1611,7 @@ mod test_filtering_records {
16031611 last_modified: 100 ,
16041612 deleted: false ,
16051613 attachment: None ,
1606- fields: json!( {
1614+ fields: serde_json :: json!( {
16071615 "filter_expression" : "env.version|versionCompare(\" 128.0a1\" ) > 0"
16081616 } )
16091617 . as_object( )
@@ -1652,7 +1660,7 @@ mod test_filtering_records {
16521660 last_modified: 100 ,
16531661 deleted: false ,
16541662 attachment: None ,
1655- fields: json!( {
1663+ fields: serde_json :: json!( {
16561664 "filter_expression" : "env.version|versionCompare(\" 128.0a1\" ) > 0"
16571665 } )
16581666 . as_object( )
0 commit comments