nacos-sdk-rust-binding-node 0.2.0 → 0.2.2

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
@@ -18,12 +18,14 @@ crate-type = ["cdylib"]
18
18
  napi = { version = "2", default-features = false, features = ["napi4", "async"] }
19
19
  napi-derive = "2"
20
20
 
21
- nacos-sdk = { version = "0.3.0-alpha", features = ["async"] }
22
- #nacos-sdk = { git = "https://github.com/nacos-group/nacos-sdk-rust.git", features = ["async"] }
21
+ #nacos-sdk = { version = "0.3.0-beta", features = ["async"] }
22
+ nacos-sdk = { git = "https://github.com/nacos-group/nacos-sdk-rust.git", features = ["async"] }
23
23
 
24
- tracing-subscriber = { version = "0.3", features = ["env-filter", "local-time"] }
24
+ tracing-subscriber = { version = "0.3", features = ["default"] }
25
+ #tracing-subscriber = { version = "0.3", features = ["env-filter", "local-time"] } # occur `<unknown time>`
25
26
  tracing-appender = "0.2"
26
27
  lazy_static = "1.4.0"
28
+ async-trait = "0.1"
27
29
 
28
30
  [build-dependencies]
29
31
  napi-build = "2"
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "binding",
8
8
  "ffi"
9
9
  ],
10
- "version": "0.2.0",
10
+ "version": "0.2.2",
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.2.0",
59
- "nacos-sdk-rust-binding-node-darwin-x64": "0.2.0",
60
- "nacos-sdk-rust-binding-node-linux-x64-gnu": "0.2.0",
61
- "nacos-sdk-rust-binding-node-darwin-arm64": "0.2.0",
62
- "nacos-sdk-rust-binding-node-android-arm64": "0.2.0",
63
- "nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.2.0",
64
- "nacos-sdk-rust-binding-node-linux-arm64-musl": "0.2.0",
65
- "nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.2.0",
66
- "nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.2.0",
67
- "nacos-sdk-rust-binding-node-linux-x64-musl": "0.2.0",
68
- "nacos-sdk-rust-binding-node-freebsd-x64": "0.2.0",
69
- "nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.2.0",
70
- "nacos-sdk-rust-binding-node-android-arm-eabi": "0.2.0",
71
- "nacos-sdk-rust-binding-node-darwin-universal": "0.2.0"
58
+ "nacos-sdk-rust-binding-node-win32-x64-msvc": "0.2.2",
59
+ "nacos-sdk-rust-binding-node-darwin-x64": "0.2.2",
60
+ "nacos-sdk-rust-binding-node-linux-x64-gnu": "0.2.2",
61
+ "nacos-sdk-rust-binding-node-darwin-arm64": "0.2.2",
62
+ "nacos-sdk-rust-binding-node-android-arm64": "0.2.2",
63
+ "nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.2.2",
64
+ "nacos-sdk-rust-binding-node-linux-arm64-musl": "0.2.2",
65
+ "nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.2.2",
66
+ "nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.2.2",
67
+ "nacos-sdk-rust-binding-node-linux-x64-musl": "0.2.2",
68
+ "nacos-sdk-rust-binding-node-freebsd-x64": "0.2.2",
69
+ "nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.2.2",
70
+ "nacos-sdk-rust-binding-node-android-arm-eabi": "0.2.2",
71
+ "nacos-sdk-rust-binding-node-darwin-universal": "0.2.2"
72
72
  }
73
73
  }
package/src/lib.rs CHANGED
@@ -10,6 +10,13 @@ pub fn sum(a: i32, b: i32) -> i32 {
10
10
 
11
11
  lazy_static::lazy_static! {
12
12
  static ref LOG_GUARD: tracing_appender::non_blocking::WorkerGuard = {
13
+ use std::str::FromStr;
14
+ use tracing_subscriber::filter::LevelFilter;
15
+ let log_level = match std::env::var("NACOS_CLIENT_LOGGER_LEVEL") {
16
+ Ok(level) => LevelFilter::from_str(&level).unwrap_or(LevelFilter::INFO),
17
+ Err(_) => LevelFilter::INFO,
18
+ };
19
+
13
20
  let home_dir = match std::env::var("HOME") {
14
21
  Ok(dir) => dir,
15
22
  Err(_) => "/tmp".to_string(),
@@ -19,10 +26,10 @@ lazy_static::lazy_static! {
19
26
 
20
27
  tracing_subscriber::fmt()
21
28
  .with_writer(non_blocking)
22
- .with_timer(tracing_subscriber::fmt::time::LocalTime::rfc_3339())
29
+ // .with_timer(tracing_subscriber::fmt::time::LocalTime::rfc_3339()) // occur `<unknown time>`
23
30
  .with_thread_names(true)
24
31
  .with_thread_ids(true)
25
- .with_max_level(tracing_subscriber::filter::LevelFilter::INFO)
32
+ .with_max_level(log_level)
26
33
  .init();
27
34
 
28
35
  guard
package/src/plugin.rs CHANGED
@@ -7,8 +7,9 @@ pub struct NacosConfigFilter {
7
7
  pub(crate) func: Arc<ThreadsafeFunction<(Option<NacosConfigReq>, Option<NacosConfigResp>)>>,
8
8
  }
9
9
 
10
+ #[async_trait::async_trait]
10
11
  impl nacos_sdk::api::plugin::ConfigFilter for NacosConfigFilter {
11
- fn filter(
12
+ async fn filter(
12
13
  &self,
13
14
  config_req: Option<&mut nacos_sdk::api::plugin::ConfigReq>,
14
15
  config_resp: Option<&mut nacos_sdk::api::plugin::ConfigResp>,
@@ -22,21 +23,13 @@ impl nacos_sdk::api::plugin::ConfigFilter for NacosConfigFilter {
22
23
  encrypted_data_key: config_req.encrypted_data_key.clone(),
23
24
  };
24
25
 
25
- let (tx, rx) = std::sync::mpsc::channel();
26
- self.func.clone().call_with_return_value(
27
- Ok((Some(js_config_req), None)),
28
- ThreadsafeFunctionCallMode::Blocking,
29
- move |(after_js_config_req, _after_js_config_resp): (
30
- Option<NacosConfigReq>,
31
- Option<NacosConfigResp>,
32
- )| {
33
- let after_js_config_req = after_js_config_req.unwrap();
34
- let _ = tx.send(after_js_config_req);
35
- Ok(())
36
- },
37
- );
26
+ let (after_js_config_req, _): (Option<NacosConfigReq>, Option<NacosConfigResp>) = self
27
+ .func
28
+ .call_async(Ok((Some(js_config_req), None)))
29
+ .await
30
+ .unwrap();
38
31
 
39
- let ret = rx.recv().unwrap();
32
+ let ret = after_js_config_req.unwrap();
40
33
  config_req.data_id = ret.data_id;
41
34
  config_req.group = ret.group;
42
35
  config_req.namespace = ret.namespace;
@@ -53,21 +46,13 @@ impl nacos_sdk::api::plugin::ConfigFilter for NacosConfigFilter {
53
46
  encrypted_data_key: config_resp.encrypted_data_key.clone(),
54
47
  };
55
48
 
56
- let (tx, rx) = std::sync::mpsc::channel();
57
- self.func.clone().call_with_return_value(
58
- Ok((None, Some(js_config_resp))),
59
- ThreadsafeFunctionCallMode::Blocking,
60
- move |(_after_js_config_req, after_js_config_resp): (
61
- Option<NacosConfigReq>,
62
- Option<NacosConfigResp>,
63
- )| {
64
- let after_js_config_resp = after_js_config_resp.unwrap();
65
- let _ = tx.send(after_js_config_resp);
66
- Ok(())
67
- },
68
- );
49
+ let (_, after_js_config_resp): (Option<NacosConfigReq>, Option<NacosConfigResp>) = self
50
+ .func
51
+ .call_async(Ok((None, Some(js_config_resp))))
52
+ .await
53
+ .unwrap();
69
54
 
70
- let ret = rx.recv().unwrap();
55
+ let ret = after_js_config_resp.unwrap();
71
56
  config_resp.data_id = ret.data_id;
72
57
  config_resp.group = ret.group;
73
58
  config_resp.namespace = ret.namespace;