diff --git a/lib/client-options.js b/lib/client-options.js index 9391e8f5..074afa2e 100644 --- a/lib/client-options.js +++ b/lib/client-options.js @@ -46,10 +46,9 @@ const errors = require("./errors.js"); * * @property {String} [credentials.username] The username to use for plain-text authentication. * @property {String} [credentials.password] The password to use for plain-text authentication. - * @property {Uuid} [id] A unique identifier assigned to a {@link Client} object, that will be communicated to the - * server (DSE 6.0+) to identify the client instance created with this options. When not defined, the driver will + * @property {Uuid | string} [id] A unique identifier assigned to a {@link Client} object, that will be communicated to the + * server to identify the client instance created with this options. When not defined, the driver will * generate a random identifier. - * [TODO: Add support for this field] * @property {String} [applicationName] An optional setting identifying the name of the application using * the {@link Client} instance. * @@ -663,8 +662,14 @@ function setRustOptions(options) { rustOptions.connectPoints = options.contactPoints; rustOptions.applicationName = options.applicationName; rustOptions.applicationVersion = options.applicationVersion; + if (options.id instanceof types.Uuid) { + options.id = options.id.toString(); + } + rustOptions.clientId = options.id; rustOptions.keyspace = options.keyspace; - rustOptions.cacheSize = options.maxPrepared; + if (rustOptions.cacheSize) { + rustOptions.cacheSize = options.maxPrepared; + } if (options.credentials) { rustOptions.credentialsUsername = options.credentials.username; rustOptions.credentialsPassword = options.credentials.password; @@ -672,7 +677,7 @@ function setRustOptions(options) { if (options.authProvider instanceof auth.PlainTextAuthProvider) { rustOptions.credentialsUsername = options.authProvider.username; rustOptions.credentialsPassword = options.authProvider.password; - } else { + } else if (!(options.authProvider instanceof auth.NoAuthProvider)) { throw new errors.ArgumentError( // TODO: Add support for other auth providers "Unsupported auth provider: " + options.authProvider, diff --git a/lib/client.js b/lib/client.js index 42b62cae..2ee0c3db 100644 --- a/lib/client.js +++ b/lib/client.js @@ -49,13 +49,14 @@ class Client extends events.EventEmitter { */ constructor(options) { super(); - this.rustOptions = clientOptions.setRustOptions(options); - /** @type {clientOptions.ClientOptions} */ this.options = clientOptions.extend( { logEmitter: this.emit.bind(this), id: types.Uuid.random() }, options, ); + + this.rustOptions = clientOptions.setRustOptions(this.options); + Object.defineProperty(this, "profileManager", { value: new ProfileManager(this.options), }); diff --git a/src/session.rs b/src/session.rs index bb87a6c3..1bfc90ed 100644 --- a/src/session.rs +++ b/src/session.rs @@ -32,6 +32,7 @@ define_js_to_rust_convertible_object!(SessionOptions { keyspace, keyspace: String, application_name, applicationName: String, application_version, applicationVersion: String, + client_id, clientId: String, credentials_username, credentialsUsername: String, credentials_password, credentialsPassword: String, cache_size, cacheSize: u32, @@ -359,5 +360,8 @@ fn self_identity(options: &SessionOptions) -> SelfIdentity<'static> { if let Some(app_version) = &options.application_name { self_identity.set_application_version(app_version.clone()); } + if let Some(client_id) = &options.client_id { + self_identity.set_client_id(client_id.to_owned()); + } self_identity }