nacos-sdk-rust-binding-node 0.0.1 → 0.0.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 +2 -3
- package/package.json +28 -16
- package/src/config.rs +15 -11
- package/src/naming.rs +26 -19
package/Cargo.toml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
edition = "2021"
|
|
3
3
|
name = "nacos-sdk-rust-binding-node"
|
|
4
|
-
version = "0.0.
|
|
4
|
+
version = "0.0.2"
|
|
5
5
|
authors = ["CheirshCai <785427346@qq.com>"]
|
|
6
6
|
license = "Apache-2.0"
|
|
7
7
|
readme = "README.md"
|
|
@@ -18,8 +18,7 @@ crate-type = ["cdylib"]
|
|
|
18
18
|
napi = { version = "2", default-features = false, features = ["napi4", "async"] }
|
|
19
19
|
napi-derive = "2"
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
nacos-sdk = { git = "https://github.com/nacos-group/nacos-sdk-rust.git"}
|
|
21
|
+
nacos-sdk = { version = "0.2.3", features = ["async"] }
|
|
23
22
|
tracing-subscriber = "0.3"
|
|
24
23
|
tracing-appender = "0.2"
|
|
25
24
|
lazy_static = "1.4.0"
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nacos-sdk-rust-binding-node",
|
|
3
|
-
"
|
|
3
|
+
"description": "nacos-sdk-rust binding for NodeJs with napi.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"nacos",
|
|
6
|
+
"napi",
|
|
7
|
+
"binding",
|
|
8
|
+
"ffi"
|
|
9
|
+
],
|
|
10
|
+
"version": "0.0.2",
|
|
11
|
+
"bugs": "https://github.com/opc-source/nacos-sdk-rust-binding-node/issues",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/opc-source/nacos-sdk-rust-binding-node.git"
|
|
16
|
+
},
|
|
4
17
|
"main": "index.js",
|
|
5
18
|
"types": "index.d.ts",
|
|
6
19
|
"napi": {
|
|
@@ -21,7 +34,6 @@
|
|
|
21
34
|
]
|
|
22
35
|
}
|
|
23
36
|
},
|
|
24
|
-
"license": "MIT",
|
|
25
37
|
"devDependencies": {
|
|
26
38
|
"@napi-rs/cli": "^2.14.6",
|
|
27
39
|
"ava": "^5.1.1"
|
|
@@ -43,19 +55,19 @@
|
|
|
43
55
|
},
|
|
44
56
|
"packageManager": "yarn@3.4.1",
|
|
45
57
|
"optionalDependencies": {
|
|
46
|
-
"nacos-sdk-rust-binding-node-win32-x64-msvc": "0.0.
|
|
47
|
-
"nacos-sdk-rust-binding-node-darwin-x64": "0.0.
|
|
48
|
-
"nacos-sdk-rust-binding-node-linux-x64-gnu": "0.0.
|
|
49
|
-
"nacos-sdk-rust-binding-node-darwin-arm64": "0.0.
|
|
50
|
-
"nacos-sdk-rust-binding-node-android-arm64": "0.0.
|
|
51
|
-
"nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.0.
|
|
52
|
-
"nacos-sdk-rust-binding-node-linux-arm64-musl": "0.0.
|
|
53
|
-
"nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.0.
|
|
54
|
-
"nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.0.
|
|
55
|
-
"nacos-sdk-rust-binding-node-linux-x64-musl": "0.0.
|
|
56
|
-
"nacos-sdk-rust-binding-node-freebsd-x64": "0.0.
|
|
57
|
-
"nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.0.
|
|
58
|
-
"nacos-sdk-rust-binding-node-android-arm-eabi": "0.0.
|
|
59
|
-
"nacos-sdk-rust-binding-node-darwin-universal": "0.0.
|
|
58
|
+
"nacos-sdk-rust-binding-node-win32-x64-msvc": "0.0.2",
|
|
59
|
+
"nacos-sdk-rust-binding-node-darwin-x64": "0.0.2",
|
|
60
|
+
"nacos-sdk-rust-binding-node-linux-x64-gnu": "0.0.2",
|
|
61
|
+
"nacos-sdk-rust-binding-node-darwin-arm64": "0.0.2",
|
|
62
|
+
"nacos-sdk-rust-binding-node-android-arm64": "0.0.2",
|
|
63
|
+
"nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.0.2",
|
|
64
|
+
"nacos-sdk-rust-binding-node-linux-arm64-musl": "0.0.2",
|
|
65
|
+
"nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.0.2",
|
|
66
|
+
"nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.0.2",
|
|
67
|
+
"nacos-sdk-rust-binding-node-linux-x64-musl": "0.0.2",
|
|
68
|
+
"nacos-sdk-rust-binding-node-freebsd-x64": "0.0.2",
|
|
69
|
+
"nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.0.2",
|
|
70
|
+
"nacos-sdk-rust-binding-node-android-arm-eabi": "0.0.2",
|
|
71
|
+
"nacos-sdk-rust-binding-node-darwin-universal": "0.0.2"
|
|
60
72
|
}
|
|
61
73
|
}
|
package/src/config.rs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#![deny(clippy::all)]
|
|
2
2
|
|
|
3
|
-
use napi::{bindgen_prelude::*, threadsafe_function
|
|
3
|
+
use napi::{bindgen_prelude::*, threadsafe_function::*};
|
|
4
4
|
use std::sync::Arc;
|
|
5
5
|
|
|
6
6
|
/// Client api of Nacos Config.
|
|
7
7
|
#[napi]
|
|
8
8
|
pub struct NacosConfigClient {
|
|
9
|
-
inner: Arc<
|
|
9
|
+
inner: Arc<dyn nacos_sdk::api::config::ConfigService + Send + Sync + 'static>,
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
#[napi]
|
|
@@ -64,7 +64,7 @@ impl NacosConfigClient {
|
|
|
64
64
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
65
65
|
|
|
66
66
|
Ok(NacosConfigClient {
|
|
67
|
-
inner: Arc::new(
|
|
67
|
+
inner: Arc::new(config_service),
|
|
68
68
|
})
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -84,9 +84,10 @@ impl NacosConfigClient {
|
|
|
84
84
|
data_id: String,
|
|
85
85
|
group: String,
|
|
86
86
|
) -> Result<NacosConfigResponse> {
|
|
87
|
-
let
|
|
88
|
-
|
|
87
|
+
let config_resp = self
|
|
88
|
+
.inner
|
|
89
89
|
.get_config(data_id, group)
|
|
90
|
+
.await
|
|
90
91
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
91
92
|
Ok(transfer_conf_resp(config_resp))
|
|
92
93
|
}
|
|
@@ -100,9 +101,10 @@ impl NacosConfigClient {
|
|
|
100
101
|
group: String,
|
|
101
102
|
content: String,
|
|
102
103
|
) -> Result<bool> {
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
self
|
|
105
|
+
.inner
|
|
105
106
|
.publish_config(data_id, group, content, None)
|
|
107
|
+
.await
|
|
106
108
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))
|
|
107
109
|
}
|
|
108
110
|
|
|
@@ -110,9 +112,10 @@ impl NacosConfigClient {
|
|
|
110
112
|
/// If it fails, pay attention to err
|
|
111
113
|
#[napi]
|
|
112
114
|
pub async fn remove_config(&self, data_id: String, group: String) -> Result<bool> {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
self
|
|
116
|
+
.inner
|
|
115
117
|
.remove_config(data_id, group)
|
|
118
|
+
.await
|
|
116
119
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))
|
|
117
120
|
}
|
|
118
121
|
|
|
@@ -125,8 +128,8 @@ impl NacosConfigClient {
|
|
|
125
128
|
group: String,
|
|
126
129
|
listener: ThreadsafeFunction<NacosConfigResponse>,
|
|
127
130
|
) -> Result<()> {
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
self
|
|
132
|
+
.inner
|
|
130
133
|
.add_listener(
|
|
131
134
|
data_id,
|
|
132
135
|
group,
|
|
@@ -134,6 +137,7 @@ impl NacosConfigClient {
|
|
|
134
137
|
func: Arc::new(listener),
|
|
135
138
|
}),
|
|
136
139
|
)
|
|
140
|
+
.await
|
|
137
141
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
138
142
|
Ok(())
|
|
139
143
|
}
|
package/src/naming.rs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#![deny(clippy::all)]
|
|
2
2
|
|
|
3
|
-
use napi::{bindgen_prelude::*, threadsafe_function
|
|
3
|
+
use napi::{bindgen_prelude::*, threadsafe_function::*};
|
|
4
4
|
use std::sync::Arc;
|
|
5
5
|
|
|
6
6
|
/// Client api of Nacos Naming.
|
|
7
7
|
#[napi]
|
|
8
8
|
pub struct NacosNamingClient {
|
|
9
|
-
inner: Arc<
|
|
9
|
+
inner: Arc<dyn nacos_sdk::api::naming::NamingService + Send + Sync + 'static>,
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
#[napi]
|
|
@@ -48,7 +48,7 @@ impl NacosNamingClient {
|
|
|
48
48
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
49
49
|
|
|
50
50
|
Ok(NacosNamingClient {
|
|
51
|
-
inner: Arc::new(
|
|
51
|
+
inner: Arc::new(naming_service),
|
|
52
52
|
})
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -61,13 +61,14 @@ impl NacosNamingClient {
|
|
|
61
61
|
group: String,
|
|
62
62
|
service_instance: NacosServiceInstance,
|
|
63
63
|
) -> Result<()> {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
64
|
+
self
|
|
65
|
+
.inner
|
|
66
|
+
.register_instance(
|
|
67
67
|
service_name,
|
|
68
68
|
Some(group),
|
|
69
69
|
transfer_js_instance_to_rust(&service_instance),
|
|
70
70
|
)
|
|
71
|
+
.await
|
|
71
72
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -80,13 +81,14 @@ impl NacosNamingClient {
|
|
|
80
81
|
group: String,
|
|
81
82
|
service_instance: NacosServiceInstance,
|
|
82
83
|
) -> Result<()> {
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
self
|
|
85
|
+
.inner
|
|
85
86
|
.deregister_instance(
|
|
86
87
|
service_name,
|
|
87
88
|
Some(group),
|
|
88
89
|
transfer_js_instance_to_rust(&service_instance),
|
|
89
90
|
)
|
|
91
|
+
.await
|
|
90
92
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -104,9 +106,10 @@ impl NacosNamingClient {
|
|
|
104
106
|
.map(transfer_js_instance_to_rust)
|
|
105
107
|
.collect();
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
self
|
|
110
|
+
.inner
|
|
109
111
|
.batch_register_instance(service_name, Some(group), rust_instances)
|
|
112
|
+
.await
|
|
110
113
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))
|
|
111
114
|
}
|
|
112
115
|
|
|
@@ -120,14 +123,15 @@ impl NacosNamingClient {
|
|
|
120
123
|
clusters: Option<Vec<String>>,
|
|
121
124
|
#[napi(ts_arg_type = "boolean = true")] subscribe: Option<bool>,
|
|
122
125
|
) -> Result<Vec<NacosServiceInstance>> {
|
|
123
|
-
let
|
|
124
|
-
|
|
126
|
+
let rust_instances = self
|
|
127
|
+
.inner
|
|
125
128
|
.get_all_instances(
|
|
126
129
|
service_name,
|
|
127
130
|
Some(group),
|
|
128
131
|
clusters.unwrap_or_default(),
|
|
129
132
|
subscribe.unwrap_or(true),
|
|
130
133
|
)
|
|
134
|
+
.await
|
|
131
135
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
132
136
|
|
|
133
137
|
Ok(
|
|
@@ -149,15 +153,16 @@ impl NacosNamingClient {
|
|
|
149
153
|
#[napi(ts_arg_type = "boolean = true")] subscribe: Option<bool>,
|
|
150
154
|
#[napi(ts_arg_type = "boolean = true")] healthy: Option<bool>,
|
|
151
155
|
) -> Result<Vec<NacosServiceInstance>> {
|
|
152
|
-
let
|
|
153
|
-
|
|
154
|
-
.
|
|
156
|
+
let rust_instances = self
|
|
157
|
+
.inner
|
|
158
|
+
.select_instances(
|
|
155
159
|
service_name,
|
|
156
160
|
Some(group),
|
|
157
161
|
clusters.unwrap_or_default(),
|
|
158
162
|
subscribe.unwrap_or(true),
|
|
159
163
|
healthy.unwrap_or(true),
|
|
160
164
|
)
|
|
165
|
+
.await
|
|
161
166
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
162
167
|
|
|
163
168
|
Ok(
|
|
@@ -178,14 +183,15 @@ impl NacosNamingClient {
|
|
|
178
183
|
clusters: Option<Vec<String>>,
|
|
179
184
|
#[napi(ts_arg_type = "boolean = true")] subscribe: Option<bool>,
|
|
180
185
|
) -> Result<NacosServiceInstance> {
|
|
181
|
-
let
|
|
182
|
-
|
|
186
|
+
let rust_instance = self
|
|
187
|
+
.inner
|
|
183
188
|
.select_one_healthy_instance(
|
|
184
189
|
service_name,
|
|
185
190
|
Some(group),
|
|
186
191
|
clusters.unwrap_or_default(),
|
|
187
192
|
subscribe.unwrap_or(true),
|
|
188
193
|
)
|
|
194
|
+
.await
|
|
189
195
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
190
196
|
|
|
191
197
|
Ok(transfer_rust_instance_to_js(&rust_instance))
|
|
@@ -201,8 +207,8 @@ impl NacosNamingClient {
|
|
|
201
207
|
clusters: Option<Vec<String>>,
|
|
202
208
|
listener: ThreadsafeFunction<Vec<NacosServiceInstance>>,
|
|
203
209
|
) -> Result<()> {
|
|
204
|
-
|
|
205
|
-
|
|
210
|
+
self
|
|
211
|
+
.inner
|
|
206
212
|
.subscribe(
|
|
207
213
|
service_name,
|
|
208
214
|
Some(group),
|
|
@@ -211,6 +217,7 @@ impl NacosNamingClient {
|
|
|
211
217
|
func: Arc::new(listener),
|
|
212
218
|
}),
|
|
213
219
|
)
|
|
220
|
+
.await
|
|
214
221
|
.map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
|
|
215
222
|
Ok(())
|
|
216
223
|
}
|