1#![warn(missing_docs)]
58#![warn(clippy::all)]
59#![deny(clippy::unwrap_used)]
60#![allow(clippy::module_name_repetitions)]
61
62mod algorithms;
63mod async_ops;
64mod buffer;
65mod error;
66mod raster;
67mod vector;
68
69use napi_derive::napi;
70
71#[napi]
73pub fn version() -> String {
74 oxigdal_core::VERSION.to_string()
75}
76
77#[napi]
79pub fn name() -> String {
80 "OxiGDAL Node.js Bindings".to_string()
81}
82
83#[napi(object)]
85pub struct ModuleInfo {
86 pub version: String,
88 pub name: String,
90 pub build_info: String,
92 pub formats: Vec<String>,
94}
95
96#[napi]
98pub fn get_info() -> ModuleInfo {
99 ModuleInfo {
100 version: oxigdal_core::VERSION.to_string(),
101 name: "OxiGDAL Node.js Bindings".to_string(),
102 build_info: format!(
103 "Built with Rust {} on {}",
104 env!("CARGO_PKG_RUST_VERSION"),
105 std::env::consts::OS
106 ),
107 formats: vec![
108 "GeoTIFF".to_string(),
109 "COG".to_string(),
110 "GeoJSON".to_string(),
111 ],
112 }
113}
114
115#[napi(object)]
117pub struct DataTypes {
118 pub uint8: String,
120 pub int16: String,
122 pub uint16: String,
124 pub int32: String,
126 pub uint32: String,
128 pub float32: String,
130 pub float64: String,
132}
133
134#[napi]
136pub fn get_data_types() -> DataTypes {
137 DataTypes {
138 uint8: "uint8".to_string(),
139 int16: "int16".to_string(),
140 uint16: "uint16".to_string(),
141 int32: "int32".to_string(),
142 uint32: "uint32".to_string(),
143 float32: "float32".to_string(),
144 float64: "float64".to_string(),
145 }
146}
147
148#[napi(object)]
150pub struct ResamplingMethods {
151 pub nearest_neighbor: String,
153 pub bilinear: String,
155 pub bicubic: String,
157 pub lanczos: String,
159}
160
161#[napi]
163pub fn get_resampling_methods() -> ResamplingMethods {
164 ResamplingMethods {
165 nearest_neighbor: "NearestNeighbor".to_string(),
166 bilinear: "Bilinear".to_string(),
167 bicubic: "Bicubic".to_string(),
168 lanczos: "Lanczos".to_string(),
169 }
170}
171
172#[cfg(test)]
173mod tests {
174 use super::*;
175
176 #[test]
177 fn test_version() {
178 let ver = version();
179 assert!(!ver.is_empty());
180 }
181
182 #[test]
183 fn test_info() {
184 let info = get_info();
185 assert!(!info.version.is_empty());
186 assert!(!info.formats.is_empty());
187 }
188
189 #[test]
190 fn test_data_types() {
191 let types = get_data_types();
192 assert_eq!(types.uint8, "uint8");
193 assert_eq!(types.float32, "float32");
194 }
195
196 #[test]
197 fn test_data_types_all_fields() {
198 let types = get_data_types();
199 assert_eq!(types.uint8, "uint8");
200 assert_eq!(types.int16, "int16");
201 assert_eq!(types.uint16, "uint16");
202 assert_eq!(types.int32, "int32");
203 assert_eq!(types.uint32, "uint32");
204 assert_eq!(types.float32, "float32");
205 assert_eq!(types.float64, "float64");
206 }
207
208 #[test]
209 fn test_resampling_methods() {
210 let methods = get_resampling_methods();
211 assert_eq!(methods.nearest_neighbor, "NearestNeighbor");
212 assert_eq!(methods.bilinear, "Bilinear");
213 assert_eq!(methods.bicubic, "Bicubic");
214 assert_eq!(methods.lanczos, "Lanczos");
215 }
216
217 #[test]
218 fn test_module_info_name() {
219 let info = get_info();
220 assert!(info.name.contains("OxiGDAL"));
221 }
222
223 #[test]
224 fn test_module_info_formats_contain_geotiff() {
225 let info = get_info();
226 assert!(
227 info.formats
228 .iter()
229 .any(|f| f.contains("GeoTIFF") || f.contains("tiff") || f.contains("TIFF"))
230 );
231 }
232
233 #[test]
234 fn test_module_info_build_info_not_empty() {
235 let info = get_info();
236 assert!(!info.build_info.is_empty());
237 }
238
239 #[test]
240 fn test_name_function() {
241 let n = name();
242 assert!(!n.is_empty());
243 assert!(n.contains("OxiGDAL") || n.contains("Node"));
244 }
245}