diff --git a/lib/src/client_options.dart b/lib/src/client_options.dart index 744c92f..842e7c7 100644 --- a/lib/src/client_options.dart +++ b/lib/src/client_options.dart @@ -44,14 +44,7 @@ class ClientOptions { return jsify( { if (applicationName != null) 'applicationName': applicationName, - if (connection != null) - 'connection': jsify({ - if (connection.attempts != null) 'attempts': connection.attempts, - if (connection.nextInterval != null) - 'interval': connection.nextInterval - else if (connection.interval != null) - 'interval': connection.interval, - }), + if (connection != null) 'connection': jsify(connection.asMap()), if (database != null) 'database': database, if (hostname != null) 'hostname': hostname, if (hostType != null) 'host_type': hostType.name, @@ -64,13 +57,7 @@ class ClientOptions { 'port': portString else if (port != null) 'port': port, - if (tls != null) - 'tls': jsify({ - if (tls.isEnabled != null) 'enabled': tls.isEnabled, - if (tls.isEnforced != null) 'enforce': tls.isEnforced, - if (tls.caCertificates != null) - 'caCertificates': tls.caCertificates, - }), + if (tls != null) 'tls': jsify(tls.asMap()), if (user != null) 'user': user, }, ) as ClientOptions; diff --git a/lib/src/partial/partial_connection_options.dart b/lib/src/partial/partial_connection_options.dart index 3a939b4..6d0e7ec 100644 --- a/lib/src/partial/partial_connection_options.dart +++ b/lib/src/partial/partial_connection_options.dart @@ -19,4 +19,15 @@ class PartialConnectionOptions { required this.nextInterval, required this.interval, }) : assert(interval == null || nextInterval == null); + + /// used for jsify. + Map asMap() { + return { + if (attempts != null) 'attempts': attempts, + if (nextInterval != null) + 'interval': nextInterval + else if (interval != null) + 'interval': interval, + }; + } } diff --git a/lib/src/partial/partial_tls_options.dart b/lib/src/partial/partial_tls_options.dart index c5bc0fc..fb68773 100644 --- a/lib/src/partial/partial_tls_options.dart +++ b/lib/src/partial/partial_tls_options.dart @@ -15,4 +15,13 @@ class PartialTLSOptions { required this.isEnforced, required this.caCertificates, }); + + /// used for jsify. + Map asMap() { + return { + if (isEnabled != null) 'enabled': isEnabled, + if (isEnforced != null) 'enforce': isEnforced, + if (caCertificates != null) 'caCertificates': caCertificates, + }; + } }