Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 2d48930

Browse files
author
Filip Kieres
authored
chore: update dependencies (#39)
1 parent 03973a1 commit 2d48930

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

Diff for: Cargo.toml

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ edition = "2018"
1313
crate-type = ["cdylib", "rlib"]
1414

1515
[dependencies]
16-
failure = "0.1.2"
17-
serde = "1.0.101"
18-
serde_json = "1.0.40"
19-
serde_derive = "1.0.101"
20-
bson = { git = "https://github.com/lrlna/bson-rs", branch = "wasm-dec128" }
21-
wee_alloc = "0.4.2"
22-
console_error_panic_hook = "0.1.6"
23-
js-sys = "0.3.25"
24-
web-sys = { version = "0.3.16", features = ['console'] }
25-
wasm-bindgen-test = "0.3.8"
16+
failure = "0.1.8"
17+
serde = "1.0.137"
18+
serde_json = "1.0.81"
19+
serde_derive = "1.0.137"
20+
bson = "2.2"
21+
wee_alloc = "0.4.5"
22+
console_error_panic_hook = "0.1.7"
23+
js-sys = "0.3.57"
24+
web-sys = { version = "0.3.57", features = ['console'] }
25+
wasm-bindgen-test = "0.3.30"
2626

2727
[dependencies.wasm-bindgen]
28-
version = "^0.2.37"
28+
version = "^0.2.80"
2929
features = ["serde-serialize"]

Diff for: src/field_type.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub static ARRAY: &str = "Array";
3939
pub static I32: &str = "Int32";
4040
pub static I64: &str = "Long";
4141
pub static NULL: &str = "Null";
42+
pub static DB_POINTER: &str = "DbPointer";
43+
pub static MAX_KEY: &str = "MaxKey";
44+
pub static MIN_KEY: &str = "MinKey";
45+
pub static UNDEFINED: &str = "Undefined";
4246

4347
impl FieldType {
4448
pub fn new<T, U>(path: T, bson_type: U) -> Self
@@ -157,19 +161,20 @@ impl FieldType {
157161

158162
pub fn get_value(value: &Bson) -> Option<ValueType> {
159163
match value {
160-
Bson::RegExp(val, _)
161-
| Bson::JavaScriptCode(val)
162-
| Bson::JavaScriptCodeWithScope(val, _)
164+
Bson::JavaScriptCode(val)
163165
| Bson::Symbol(val) => Some(ValueType::Str(val.to_string())),
164-
Bson::I64(num) | Bson::TimeStamp(num) => Some(ValueType::I64(*num)),
165-
Bson::FloatingPoint(num) => Some(ValueType::FloatingPoint(*num)),
166-
Bson::UtcDatetime(date) => Some(ValueType::Str(date.clone().to_string())),
166+
Bson::JavaScriptCodeWithScope(val) => Some(ValueType::Str(val.to_string())),
167+
Bson::Int32(num) => Some(ValueType::I32(*num)),
168+
Bson::Int64(num) => Some(ValueType::I64(*num)),
169+
Bson::Timestamp(num) => Some(ValueType::I32(num.time as i32)),
170+
Bson::Double(num) => Some(ValueType::FloatingPoint(*num)),
171+
Bson::DateTime(date) => Some(ValueType::Str(date.clone().to_string())),
167172
Bson::Decimal128(d128) => Some(ValueType::Decimal128(d128.to_string())),
168173
Bson::Boolean(boolean) => Some(ValueType::Boolean(*boolean)),
174+
Bson::RegularExpression(val) => Some(ValueType::Str(val.to_string())),
169175
Bson::String(string) => Some(ValueType::Str(string.to_string())),
170-
Bson::Binary(_, vec) => Some(ValueType::Binary(vec.clone())),
176+
Bson::Binary(vec) => Some(ValueType::Binary(vec.bytes.clone())),
171177
Bson::ObjectId(id) => Some(ValueType::Str(id.to_string())),
172-
Bson::I32(num) => Some(ValueType::I32(*num)),
173178
Bson::Null => Some(ValueType::Null("Null".to_string())),
174179
// Array and Document get handeled separately
175180
_ => None,
@@ -196,25 +201,29 @@ impl FieldType {
196201

197202
pub fn get_type(value: &Bson) -> String {
198203
match value {
199-
Bson::JavaScriptCodeWithScope(_, _) => {
204+
Bson::JavaScriptCodeWithScope(_) => {
200205
JAVASCRIPT_CODE_WITH_SCOPE.to_string()
201206
}
202207
Bson::JavaScriptCode(_) => JAVASCRIPT_CODE.to_string(),
203-
Bson::FloatingPoint(_) => FLOATING_POINT.to_string(),
204-
Bson::UtcDatetime(_) => UTCDATE_TIME.to_string(),
208+
Bson::Double(_) => FLOATING_POINT.to_string(),
209+
Bson::DateTime(_) => UTCDATE_TIME.to_string(),
205210
Bson::Decimal128(_) => DECIMAL_128.to_string(),
206-
Bson::TimeStamp(_) => TIMESTAMP.to_string(),
207-
Bson::Binary(_, _) => BINARY.to_string(),
208-
Bson::RegExp(_, _) => REGEXP.to_string(),
211+
Bson::Timestamp(_) => TIMESTAMP.to_string(),
212+
Bson::Binary(_) => BINARY.to_string(),
213+
Bson::RegularExpression(_) => REGEXP.to_string(),
209214
Bson::Document(_) => DOCUMENT.to_string(),
210215
Bson::ObjectId(_) => OBJECTID.to_string(),
211216
Bson::Boolean(_) => BOOLEAN.to_string(),
212217
Bson::Symbol(_) => SYMBOL.to_string(),
213218
Bson::String(_) => STRING.to_string(),
214219
Bson::Array(_) => ARRAY.to_string(),
215-
Bson::I32(_) => I32.to_string(),
216-
Bson::I64(_) => I64.to_string(),
220+
Bson::Int32(_) => I32.to_string(),
221+
Bson::Int64(_) => I64.to_string(),
217222
Bson::Null => NULL.to_string(),
223+
Bson::DbPointer(_) => DB_POINTER.to_string(),
224+
Bson::MaxKey => MAX_KEY.to_string(),
225+
Bson::MinKey => MIN_KEY.to_string(),
226+
Bson::Undefined => UNDEFINED.to_string(),
218227
}
219228
}
220229

@@ -286,21 +295,21 @@ mod tests {
286295

287296
#[test]
288297
fn it_gets_value_i32() {
289-
let bson_value = Bson::I32(1234);
298+
let bson_value = Bson::Int32(1234);
290299
let value = FieldType::get_value(&bson_value);
291300
assert_eq!(value, Some(ValueType::I32(1234)));
292301
}
293302

294303
#[test]
295304
fn it_gets_value_i64() {
296-
let bson_value = Bson::I64(1234);
305+
let bson_value = Bson::Int64(1234);
297306
let value = FieldType::get_value(&bson_value);
298307
assert_eq!(value, Some(ValueType::I64(1234)));
299308
}
300309

301310
#[test]
302311
fn it_gets_value_floating_point() {
303-
let bson_value = Bson::FloatingPoint(1.2);
312+
let bson_value = Bson::Double(1.2);
304313
let value = FieldType::get_value(&bson_value);
305314
assert_eq!(value, Some(ValueType::FloatingPoint(1.2)));
306315
}
@@ -450,7 +459,7 @@ mod tests {
450459

451460
#[test]
452461
fn it_updates_value_some() {
453-
let bson_value = Bson::I32(1234);
462+
let bson_value = Bson::Int32(1234);
454463
let mut field_type =
455464
FieldType::new("address", "Oranienstr. 123");
456465
field_type.update_value(&bson_value);
@@ -459,7 +468,7 @@ mod tests {
459468

460469
// #[bench]
461470
// fn bench_it_updates_value_some(bench: &mut Bencher) {
462-
// let bson_value = Bson::I32(1234);
471+
// let bson_value = Bson::Int32(1234);
463472
// let mut field_type =
464473
// FieldType::new("address", &Bson::String("Oranienstr. 123".to_string()));
465474
// bench.iter(|| field_type.update_value(&bson_value));

Diff for: src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! given a WASM compilation.
55
//!
66
//! ## Usage: in Rust
7-
//! ```rust
7+
//! ```no_run
88
//! extern crate mongodb_schema_parser;
99
//! use mongodb_schema_parser::SchemaParser;
1010
//! use std::fs;
@@ -55,7 +55,7 @@
5555
use failure::format_err;
5656
// extern crate test;
5757

58-
use bson::{bson, decode_document, doc, Bson, Document};
58+
use bson::{bson, doc, to_bson, Bson, Document};
5959

6060
#[macro_use]
6161
extern crate serde_derive;
@@ -128,7 +128,7 @@ impl SchemaParser {
128128
#[inline]
129129
pub fn write_json(&mut self, json: &str) -> Result<(), failure::Error> {
130130
let val: Value = serde_json::from_str(json)?;
131-
let bson = Bson::from(val);
131+
let bson = to_bson(&val)?;
132132
// should do a match for NoneError
133133
let doc = bson
134134
.as_document()
@@ -161,7 +161,7 @@ impl SchemaParser {
161161
// byte stream that implements a reader and u8 slice does this.
162162
uint8.copy_to(&mut decoded_vec);
163163
let mut slice: &[u8] = &decoded_vec;
164-
let doc = decode_document(&mut slice)?.to_owned();
164+
let doc = Document::from_reader(&mut slice)?.to_owned();
165165
// write bson internally
166166
self.update_count();
167167
self.generate_field(doc, None, None);

0 commit comments

Comments
 (0)