Skip to content

Commit 2675fa9

Browse files
nichmorganmorgan1371EduardoRSOlucabarcelosViniciusBrisotti
authored
DocumentDB support (#706)
* insert event draft * abstract change event * Added documentdb delete event * Added support to change event drop * Added support to dropDatabase Event * - MongoDB v6.0 Change Event Fields removed - ChangeEvent enum tagged - AnyDocument common type created * replace event support * added support to invalidate event in documentdb * Adding DocumentDB Rename event. * run cargo fmt * Excluding 'to' parameter * Add DocumentDB Update event * fixed 'to' parameter and run cargo fmt * Refactoring 'Rename' event declaration as a single type not a commum type * InsertNs renamed to DatabaseCollection for code reuse * unused field removed * cfg fix * fix lines * fmt and makefile fixed * makefile reord --------- Co-authored-by: nich.morgan <morgannicholson1371@gmail.com> Co-authored-by: erso <edusillva784@gmail.com> Co-authored-by: Luca Barcelos <lucalopesbarcelos@hotmail.com> Co-authored-by: Vinicius Brisotti <vinicius.brisotti@hotmail.com> Co-authored-by: Pedro Rabello Sato <kamorst@usp.br> Co-authored-by: darwish <darwish@ime.usp.br>
1 parent bcd3f97 commit 2675fa9

23 files changed

+533
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ check-event-features:
8181
cargo test --package aws_lambda_events --no-default-features --features cognito
8282
cargo test --package aws_lambda_events --no-default-features --features config
8383
cargo test --package aws_lambda_events --no-default-features --features connect
84+
cargo test --package aws_lambda_events --no-default-features --features documentdb
8485
cargo test --package aws_lambda_events --no-default-features --features dynamodb
8586
cargo test --package aws_lambda_events --no-default-features --features ecr_scan
87+
cargo test --package aws_lambda_events --no-default-features --features eventbridge
8688
cargo test --package aws_lambda_events --no-default-features --features firehose
8789
cargo test --package aws_lambda_events --no-default-features --features iam
8890
cargo test --package aws_lambda_events --no-default-features --features iot
@@ -101,7 +103,6 @@ check-event-features:
101103
cargo test --package aws_lambda_events --no-default-features --features sns
102104
cargo test --package aws_lambda_events --no-default-features --features sqs
103105
cargo test --package aws_lambda_events --no-default-features --features streams
104-
cargo test --package aws_lambda_events --no-default-features --features eventbridge
105106

106107
fmt:
107108
cargo +nightly fmt --all

lambda-events/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ default = [
7676
"sns",
7777
"sqs",
7878
"streams",
79+
"documentdb",
7980
"eventbridge",
8081
]
8182

@@ -118,4 +119,5 @@ ses = ["chrono"]
118119
sns = ["chrono", "serde_with"]
119120
sqs = ["serde_with"]
120121
streams = []
122+
documentdb = []
121123
eventbridge = ["chrono", "serde_with"]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use std::collections::HashMap;
2+
3+
use serde::{Deserialize, Serialize};
4+
use serde_json::Value;
5+
6+
pub type AnyDocument = HashMap<String, Value>;
7+
8+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
9+
#[serde(rename_all = "camelCase")]
10+
pub struct DatabaseCollection {
11+
db: String,
12+
#[serde(default)]
13+
coll: Option<String>,
14+
}
15+
16+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
17+
pub struct DocumentId {
18+
#[serde(rename = "_data")]
19+
pub data: String,
20+
}
21+
22+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
23+
pub struct DocumentKeyIdOid {
24+
#[serde(rename = "$oid")]
25+
pub oid: String,
26+
}
27+
28+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
29+
pub struct DocumentKeyId {
30+
#[serde(rename = "_id")]
31+
pub id: DocumentKeyIdOid,
32+
}
33+
34+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
35+
pub struct InnerTimestamp {
36+
t: usize,
37+
i: usize,
38+
}
39+
40+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
41+
pub struct Timestamp {
42+
#[serde(rename = "$timestamp")]
43+
pub timestamp: InnerTimestamp,
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::commom_types::{AnyDocument, DatabaseCollection, DocumentId, DocumentKeyId, Timestamp};
4+
5+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
6+
#[serde(rename_all = "camelCase")]
7+
pub struct ChangeDeleteEvent {
8+
#[serde(rename = "_id")]
9+
id: DocumentId,
10+
#[serde(default)]
11+
cluster_time: Option<Timestamp>,
12+
document_key: DocumentKeyId,
13+
#[serde(default)]
14+
#[serde(rename = "lsid")]
15+
ls_id: Option<AnyDocument>,
16+
ns: DatabaseCollection,
17+
// operation_type: String,
18+
#[serde(default)]
19+
txn_number: Option<String>,
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::commom_types::{AnyDocument, DatabaseCollection, DocumentId, Timestamp};
4+
5+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
6+
#[serde(rename_all = "camelCase")]
7+
pub struct ChangeDropDatabaseEvent {
8+
#[serde(rename = "_id")]
9+
id: DocumentId,
10+
cluster_time: Timestamp,
11+
#[serde(rename = "lsid")]
12+
ls_id: Option<AnyDocument>,
13+
ns: DatabaseCollection,
14+
// operation_type: String,
15+
#[serde(default)]
16+
txn_number: Option<String>,
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use super::commom_types::{AnyDocument, DatabaseCollection, DocumentId, Timestamp};
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
5+
#[serde(rename_all = "camelCase")]
6+
pub struct ChangeDropEvent {
7+
#[serde(rename = "_id")]
8+
id: DocumentId,
9+
cluster_time: Timestamp,
10+
#[serde(default)]
11+
#[serde(rename = "lsid")]
12+
ls_id: Option<AnyDocument>,
13+
ns: DatabaseCollection,
14+
// operation_type: String,
15+
#[serde(default)]
16+
txn_number: Option<String>,
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::commom_types::{AnyDocument, DatabaseCollection, DocumentId, DocumentKeyId, Timestamp};
4+
5+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
6+
#[serde(rename_all = "camelCase")]
7+
8+
pub struct ChangeInsertEvent {
9+
#[serde(rename = "_id")]
10+
id: DocumentId,
11+
#[serde(default)]
12+
cluster_time: Option<Timestamp>,
13+
document_key: DocumentKeyId,
14+
#[serde(default)]
15+
#[serde(rename = "lsid")]
16+
ls_id: Option<String>,
17+
ns: DatabaseCollection,
18+
//operation_type: String,
19+
#[serde(default)]
20+
txn_number: Option<AnyDocument>,
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::commom_types::{DocumentId, Timestamp};
4+
5+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
6+
#[serde(rename_all = "camelCase")]
7+
pub struct ChangeInvalidateEvent {
8+
#[serde(rename = "_id")]
9+
id: DocumentId,
10+
#[serde(default)]
11+
cluster_time: Option<Timestamp>,
12+
// operation_type: String,
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub mod commom_types;
2+
pub mod delete_event;
3+
pub mod drop_database_event;
4+
pub mod drop_event;
5+
pub mod insert_event;
6+
pub mod invalidate_event;
7+
pub mod rename_event;
8+
pub mod replace_event;
9+
pub mod update_event;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::commom_types::{AnyDocument, DatabaseCollection, DocumentId, Timestamp};
4+
5+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
6+
#[serde(rename_all = "camelCase")]
7+
pub struct ChangeRenameEvent {
8+
#[serde(rename = "_id")]
9+
id: DocumentId,
10+
#[serde(default)]
11+
cluster_time: Option<Timestamp>,
12+
13+
#[serde(default)]
14+
#[serde(rename = "lsid")]
15+
ls_id: Option<AnyDocument>,
16+
ns: DatabaseCollection,
17+
//operation_type: String,
18+
#[serde(default)]
19+
txn_number: Option<String>,
20+
to: DatabaseCollection,
21+
}

0 commit comments

Comments
 (0)