nacos-sdk-rust-binding-node 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "nacos-sdk-rust-binding-node"
3
- version = "0.6.0"
3
+ version = "0.8.0"
4
4
  edition = "2024"
5
5
  license = "Apache-2.0"
6
6
  publish = false
@@ -19,7 +19,7 @@ crate-type = ["cdylib"]
19
19
  napi = { version = "2", default-features = false, features = ["napi4", "async"] }
20
20
  napi-derive = "2"
21
21
 
22
- nacos-sdk = { version = "0.6.0", features = ["default", "auth-by-aliyun", "tracing-log"] }
22
+ nacos-sdk = { version = "0.8.0", features = ["default", "auth-by-aliyun", "tracing-log"] }
23
23
  #nacos-sdk = { git = "https://github.com/nacos-group/nacos-sdk-rust.git", branch = "main", features = ["default", "auth-by-aliyun", "tracing-log"] }
24
24
 
25
25
  async-trait = "0.1"
package/example/config.js CHANGED
@@ -11,17 +11,29 @@ const nacos_config_client = new NacosConfigClient({
11
11
  appName: "binding-node-example-app"
12
12
  });
13
13
 
14
- try {
15
- // If it fails, pay attention to err
16
- nacos_config_client.getConfig('todo-dataid', 'LOVE').then(data => {
14
+ // getConfig - config may not exist, handle error gracefully
15
+ nacos_config_client.getConfig('todo-dataid', 'LOVE')
16
+ .then(data => {
17
17
  console.log('getConfig => ' + data);
18
+ })
19
+ .catch(err => {
20
+ console.log('getConfig error: ' + err.message);
18
21
  });
19
22
 
20
- nacos_config_client.getConfigResp('todo-dataid', 'LOVE').then(data => {
23
+ // getConfigResp - config may not exist, handle error gracefully
24
+ nacos_config_client.getConfigResp('todo-dataid', 'LOVE')
25
+ .then(data => {
21
26
  console.log('getConfigResp => ' + JSON.stringify(data));
27
+ })
28
+ .catch(err => {
29
+ console.log('getConfigResp error: ' + err.message);
22
30
  });
23
- } catch(e) {
24
- console.log(e);
25
- }
26
31
 
27
- nacos_config_client.addListener('todo-dataid', 'LOVE', (err, config_resp) => { console.log(config_resp) });
32
+ // addListener - listener will be called when config is created/changed
33
+ nacos_config_client.addListener('todo-dataid', 'LOVE', (err, config_resp) => {
34
+ if (err) {
35
+ console.log('addListener error: ' + err.message);
36
+ } else {
37
+ console.log('config changed => ' + JSON.stringify(config_resp));
38
+ }
39
+ });
@@ -27,17 +27,29 @@ const nacos_config_client = new NacosConfigClient(
27
27
  }
28
28
  );
29
29
 
30
- try {
31
- // If it fails, pay attention to err
32
- nacos_config_client.getConfig('todo-dataid', 'LOVE').then(data => {
30
+ // getConfig - config may not exist, handle error gracefully
31
+ nacos_config_client.getConfig('todo-dataid', 'LOVE')
32
+ .then(data => {
33
33
  console.log('getConfig => ' + data);
34
+ })
35
+ .catch(err => {
36
+ console.log('getConfig error (config may not exist): ' + err.message);
34
37
  });
35
-
36
- nacos_config_client.getConfigResp('todo-dataid', 'LOVE').then((data) => {
38
+
39
+ // getConfigResp - config may not exist, handle error gracefully
40
+ nacos_config_client.getConfigResp('todo-dataid', 'LOVE')
41
+ .then(data => {
37
42
  console.log('getConfigResp => ' + JSON.stringify(data));
43
+ })
44
+ .catch(err => {
45
+ console.log('getConfigResp error (config may not exist): ' + err.message);
38
46
  });
39
- } catch(e) {
40
- console.log(e);
41
- }
42
47
 
43
- nacos_config_client.addListener('todo-dataid', 'LOVE', (err, config_resp) => { console.log(config_resp) });
48
+ // addListener - listener will be called when config is created/changed
49
+ nacos_config_client.addListener('todo-dataid', 'LOVE', (err, config_resp) => {
50
+ if (err) {
51
+ console.log('addListener error: ' + err.message);
52
+ } else {
53
+ console.log('config changed => ' + JSON.stringify(config_resp));
54
+ }
55
+ });
package/index.d.ts CHANGED
@@ -5,8 +5,18 @@
5
5
 
6
6
  export declare function sum(a: number, b: number): number
7
7
  export interface ClientOptions {
8
- /** Server Addr, e.g. address:port[,address:port],...] */
8
+ /**
9
+ * Server Addr, e.g. address:port[,address:port],...
10
+ * Note: endpoint takes priority over server_addr when both are provided.
11
+ */
9
12
  serverAddr: string
13
+ /**
14
+ * Endpoint is used to resolve server addresses dynamically.
15
+ * - Full URL (e.g. http://addr:8080/nacos/serverlist): used as-is, appends namespace if missing in query string.
16
+ * - Bare hostname (e.g. addr or addr:9090): uses default path /nacos/serverlist and default port 8080.
17
+ * Note: endpoint takes priority over server_addr when both are provided.
18
+ */
19
+ endpoint?: string
10
20
  /** Namespace/Tenant */
11
21
  namespace: string
12
22
  /** AppName */
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "binding",
8
8
  "ffi"
9
9
  ],
10
- "version": "0.6.0",
10
+ "version": "0.8.0",
11
11
  "bugs": "https://github.com/opc-source/nacos-sdk-rust-binding-node/issues",
12
12
  "license": "MIT",
13
13
  "repository": {
@@ -55,19 +55,19 @@
55
55
  },
56
56
  "packageManager": "yarn@3.4.1",
57
57
  "optionalDependencies": {
58
- "nacos-sdk-rust-binding-node-win32-x64-msvc": "0.6.0",
59
- "nacos-sdk-rust-binding-node-darwin-x64": "0.6.0",
60
- "nacos-sdk-rust-binding-node-linux-x64-gnu": "0.6.0",
61
- "nacos-sdk-rust-binding-node-darwin-arm64": "0.6.0",
62
- "nacos-sdk-rust-binding-node-android-arm64": "0.6.0",
63
- "nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.6.0",
64
- "nacos-sdk-rust-binding-node-linux-arm64-musl": "0.6.0",
65
- "nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.6.0",
66
- "nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.6.0",
67
- "nacos-sdk-rust-binding-node-linux-x64-musl": "0.6.0",
68
- "nacos-sdk-rust-binding-node-freebsd-x64": "0.6.0",
69
- "nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.6.0",
70
- "nacos-sdk-rust-binding-node-android-arm-eabi": "0.6.0",
71
- "nacos-sdk-rust-binding-node-darwin-universal": "0.6.0"
58
+ "nacos-sdk-rust-binding-node-win32-x64-msvc": "0.8.0",
59
+ "nacos-sdk-rust-binding-node-darwin-x64": "0.8.0",
60
+ "nacos-sdk-rust-binding-node-linux-x64-gnu": "0.8.0",
61
+ "nacos-sdk-rust-binding-node-darwin-arm64": "0.8.0",
62
+ "nacos-sdk-rust-binding-node-android-arm64": "0.8.0",
63
+ "nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.8.0",
64
+ "nacos-sdk-rust-binding-node-linux-arm64-musl": "0.8.0",
65
+ "nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.8.0",
66
+ "nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.8.0",
67
+ "nacos-sdk-rust-binding-node-linux-x64-musl": "0.8.0",
68
+ "nacos-sdk-rust-binding-node-freebsd-x64": "0.8.0",
69
+ "nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.8.0",
70
+ "nacos-sdk-rust-binding-node-android-arm-eabi": "0.8.0",
71
+ "nacos-sdk-rust-binding-node-darwin-universal": "0.8.0"
72
72
  }
73
73
  }
package/src/config.rs CHANGED
@@ -22,7 +22,7 @@ impl NacosConfigClient {
22
22
  )>,
23
23
  >,
24
24
  ) -> Result<NacosConfigClient> {
25
- let props = nacos_sdk::api::props::ClientProps::new()
25
+ let mut props = nacos_sdk::api::props::ClientProps::new()
26
26
  .server_addr(client_options.server_addr)
27
27
  .namespace(client_options.namespace)
28
28
  .app_name(
@@ -32,6 +32,11 @@ impl NacosConfigClient {
32
32
  )
33
33
  .config_load_cache_at_start(client_options.config_load_cache_at_start.unwrap_or(false));
34
34
 
35
+ // endpoint takes priority over server_addr when both are provided
36
+ if let Some(endpoint) = client_options.endpoint {
37
+ props = props.endpoint(endpoint);
38
+ }
39
+
35
40
  // need enable_auth_plugin_http with username & password
36
41
  let is_enable_auth_http =
37
42
  client_options.username.is_some() && client_options.password.is_some();
package/src/lib.rs CHANGED
@@ -8,22 +8,28 @@ pub fn sum(a: i32, b: i32) -> i32 {
8
8
  a + b
9
9
  }
10
10
 
11
- /// Global Tokio runtime for async operations in constructors
12
- static RT: std::sync::OnceLock<tokio::runtime::Runtime> = std::sync::OnceLock::new();
13
-
14
- pub fn get_runtime() -> &'static tokio::runtime::Runtime {
15
- RT.get_or_init(|| {
16
- tokio::runtime::Builder::new_current_thread()
17
- .enable_all()
18
- .build()
19
- .expect("Failed to create Tokio runtime")
20
- })
11
+ // Global Tokio runtime for async operations in constructors
12
+ // static RT: std::sync::OnceLock<tokio::runtime::Runtime> = std::sync::OnceLock::new();
13
+
14
+ pub fn get_runtime() -> tokio::runtime::Runtime {
15
+ // RT.get_or_init(|| {
16
+ tokio::runtime::Builder::new_current_thread()
17
+ .enable_all()
18
+ .build()
19
+ .expect("Failed to create Tokio runtime")
20
+ // })
21
21
  }
22
22
 
23
23
  #[napi(object)]
24
24
  pub struct ClientOptions {
25
- /// Server Addr, e.g. address:port[,address:port],...]
25
+ /// Server Addr, e.g. address:port[,address:port],...
26
+ /// Note: endpoint takes priority over server_addr when both are provided.
26
27
  pub server_addr: String,
28
+ /// Endpoint is used to resolve server addresses dynamically.
29
+ /// - Full URL (e.g. http://addr:8080/nacos/serverlist): used as-is, appends namespace if missing in query string.
30
+ /// - Bare hostname (e.g. addr or addr:9090): uses default path /nacos/serverlist and default port 8080.
31
+ /// Note: endpoint takes priority over server_addr when both are provided.
32
+ pub endpoint: Option<String>,
27
33
  /// Namespace/Tenant
28
34
  pub namespace: String,
29
35
  /// AppName
package/src/naming.rs CHANGED
@@ -14,7 +14,7 @@ impl NacosNamingClient {
14
14
  /// Build a Naming Client.
15
15
  #[napi(constructor)]
16
16
  pub fn new(client_options: crate::ClientOptions) -> Result<NacosNamingClient> {
17
- let props = nacos_sdk::api::props::ClientProps::new()
17
+ let mut props = nacos_sdk::api::props::ClientProps::new()
18
18
  .server_addr(client_options.server_addr)
19
19
  .namespace(client_options.namespace)
20
20
  .app_name(
@@ -25,6 +25,11 @@ impl NacosNamingClient {
25
25
  .naming_push_empty_protection(client_options.naming_push_empty_protection.unwrap_or(true))
26
26
  .naming_load_cache_at_start(client_options.naming_load_cache_at_start.unwrap_or(false));
27
27
 
28
+ // endpoint takes priority over server_addr when both are provided
29
+ if let Some(endpoint) = client_options.endpoint {
30
+ props = props.endpoint(endpoint);
31
+ }
32
+
28
33
  // need enable_auth_plugin_http with username & password
29
34
  let is_enable_auth_http =
30
35
  client_options.username.is_some() && client_options.password.is_some();
package/tea.yaml DELETED
@@ -1,7 +0,0 @@
1
- # https://tea.xyz/what-is-this-file
2
- ---
3
- version: 1.0.0
4
- codeOwners:
5
- - '0x43814eC189dF422BfE409cC4391d270d2401fe53'
6
- - '0xcdd8B009EAc6179EDF1c0A0eA4A3fe413914f12c'
7
- quorum: 1