@@ -32,6 +32,7 @@ use std::sync::Arc;
3232use tokio:: sync:: Mutex ;
3333
3434use databricks_sql_kernel:: { Error as KernelError , Session , TypedValue } ;
35+ use napi:: bindgen_prelude:: BigInt ;
3536
3637use crate :: async_statement:: AsyncStatement ;
3738use crate :: error:: napi_err_from_kernel;
@@ -273,6 +274,59 @@ impl Connection {
273274 & self . session_id
274275 }
275276
277+ /// Read and validate a Boolean feature flag. Missing, malformed, and
278+ /// unavailable flags return `null`.
279+ #[ napi]
280+ pub async fn feature_flag_bool ( & self , name : String ) -> napi:: Result < Option < bool > > {
281+ let guard = self . inner . lock ( ) . await ;
282+ let session = guard. as_ref ( ) . ok_or_else ( connection_closed_err) ?;
283+ Ok ( session. feature_flag_bool ( & name) . await )
284+ }
285+
286+ /// Read and validate a signed 32-bit integer feature flag.
287+ #[ napi]
288+ pub async fn feature_flag_int32 ( & self , name : String ) -> napi:: Result < Option < i32 > > {
289+ let guard = self . inner . lock ( ) . await ;
290+ let session = guard. as_ref ( ) . ok_or_else ( connection_closed_err) ?;
291+ Ok ( session. feature_flag_int32 ( & name) . await )
292+ }
293+
294+ /// Read and validate a signed 64-bit integer feature flag as a JavaScript
295+ /// `bigint`, preserving the full SAFE int64 range.
296+ #[ napi]
297+ pub async fn feature_flag_int64 ( & self , name : String ) -> napi:: Result < Option < BigInt > > {
298+ let guard = self . inner . lock ( ) . await ;
299+ let session = guard. as_ref ( ) . ok_or_else ( connection_closed_err) ?;
300+ Ok ( session. feature_flag_int64 ( & name) . await . map ( BigInt :: from) )
301+ }
302+
303+ /// Read and validate a double-precision feature flag.
304+ #[ napi]
305+ pub async fn feature_flag_double ( & self , name : String ) -> napi:: Result < Option < f64 > > {
306+ let guard = self . inner . lock ( ) . await ;
307+ let session = guard. as_ref ( ) . ok_or_else ( connection_closed_err) ?;
308+ Ok ( session. feature_flag_double ( & name) . await )
309+ }
310+
311+ /// Read and validate a string feature flag.
312+ #[ napi]
313+ pub async fn feature_flag_string ( & self , name : String ) -> napi:: Result < Option < String > > {
314+ let guard = self . inner . lock ( ) . await ;
315+ let session = guard. as_ref ( ) . ok_or_else ( connection_closed_err) ?;
316+ Ok ( session. feature_flag_string ( & name) . await )
317+ }
318+
319+ /// Read and validate a string-list feature flag.
320+ #[ napi]
321+ pub async fn feature_flag_string_list (
322+ & self ,
323+ name : String ,
324+ ) -> napi:: Result < Option < Vec < String > > > {
325+ let guard = self . inner . lock ( ) . await ;
326+ let session = guard. as_ref ( ) . ok_or_else ( connection_closed_err) ?;
327+ Ok ( session. feature_flag_string_list ( & name) . await )
328+ }
329+
276330 /// Execute a SQL statement and return a Statement handle that
277331 /// streams batches via `fetchNextBatch()`.
278332 ///
@@ -651,7 +705,9 @@ impl Drop for Connection {
651705#[ cfg( test) ]
652706mod tests {
653707 use super :: * ;
654- use databricks_sql_kernel:: { AuthConfig , ConnectionConfig , ErrorCode } ;
708+ use databricks_sql_kernel:: {
709+ AuthConfig , ClientIdentity , ClientType , ConnectionConfig , ErrorCode ,
710+ } ;
655711 use serde_json:: json;
656712 use wiremock:: matchers:: { method, path} ;
657713 use wiremock:: { Mock , MockServer , ResponseTemplate } ;
@@ -702,6 +758,84 @@ mod tests {
702758 assert_eq ! ( conn. session_id( ) , "session-survives-close" ) ;
703759 }
704760
761+ #[ tokio:: test]
762+ async fn typed_feature_flags_use_shared_cache_and_reject_closed_connection ( ) {
763+ let server = MockServer :: start ( ) . await ;
764+ Mock :: given ( method ( "GET" ) )
765+ . and ( path (
766+ "/api/2.0/connector-service/feature-flags/NODEJS/napi-test" ,
767+ ) )
768+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_string (
769+ r#"{"flags":[{"name":"example.list","value":"[\"a\",\"b\"]"},{"name":"example.int64","value":"9223372036854775807"}],"ttl_seconds":300}"# ,
770+ ) )
771+ . expect ( 1 )
772+ . mount ( & server)
773+ . await ;
774+ Mock :: given ( method ( "POST" ) )
775+ . and ( path ( "/api/2.0/sql/sessions" ) )
776+ . respond_with (
777+ ResponseTemplate :: new ( 200 ) . set_body_string (
778+ r#"{"session_id":"sess-napi-flags","warehouse_id":"test_wh"}"# ,
779+ ) ,
780+ )
781+ . expect ( 1 )
782+ . mount ( & server)
783+ . await ;
784+ Mock :: given ( method ( "DELETE" ) )
785+ . and ( path ( "/api/2.0/sql/sessions/sess-napi-flags" ) )
786+ . respond_with ( ResponseTemplate :: new ( 200 ) )
787+ . expect ( 1 )
788+ . mount ( & server)
789+ . await ;
790+
791+ let session = Session :: builder ( )
792+ . connection (
793+ ConnectionConfig :: from_http_path ( server. uri ( ) , "/sql/1.0/warehouses/test_wh" )
794+ . expect ( "valid HTTP path" ) ,
795+ )
796+ . auth ( AuthConfig :: Pat {
797+ token : "dapi_test_token" . into ( ) ,
798+ identity_federation_client_id : None ,
799+ } )
800+ . client_identity ( ClientIdentity :: new ( ClientType :: NodeJs , "napi-test" ) )
801+ . open ( )
802+ . await
803+ . expect ( "session opens against mock server" ) ;
804+ let connection = Connection {
805+ session_id : session. session_id ( ) . to_owned ( ) ,
806+ inner : Arc :: new ( Mutex :: new ( Some ( session) ) ) ,
807+ } ;
808+
809+ assert_eq ! (
810+ connection
811+ . feature_flag_string_list( "example.list" . to_owned( ) )
812+ . await
813+ . unwrap( ) ,
814+ Some ( vec![ "a" . to_string( ) , "b" . to_string( ) ] )
815+ ) ;
816+ let int64 = connection
817+ . feature_flag_int64 ( "example.int64" . to_owned ( ) )
818+ . await
819+ . unwrap ( )
820+ . expect ( "int64 flag" ) ;
821+ assert_eq ! ( int64. get_i64( ) , ( i64 :: MAX , true ) ) ;
822+ assert_eq ! (
823+ connection
824+ . feature_flag_bool( "missing.flag" . to_owned( ) )
825+ . await
826+ . unwrap( ) ,
827+ None
828+ ) ;
829+
830+ connection. close ( ) . await . unwrap ( ) ;
831+ let error = connection
832+ . feature_flag_bool ( "example.flag" . to_owned ( ) )
833+ . await
834+ . unwrap_err ( ) ;
835+ assert_invalid_statement_handle_envelope ( & error) ;
836+ server. verify ( ) . await ;
837+ }
838+
705839 #[ tokio:: test]
706840 async fn build_statement_forwards_raw_params_and_rejects_mixed_binding ( ) {
707841 let server = MockServer :: start ( ) . await ;
0 commit comments