aws_lambda_events/event/documentdb/
mod.rs1pub mod events;
2
3use self::events::{
4 delete_event::ChangeDeleteEvent, drop_database_event::ChangeDropDatabaseEvent, drop_event::ChangeDropEvent,
5 insert_event::ChangeInsertEvent, invalidate_event::ChangeInvalidateEvent, rename_event::ChangeRenameEvent,
6 replace_event::ChangeReplaceEvent, update_event::ChangeUpdateEvent,
7};
8use serde::{Deserialize, Serialize};
9#[cfg(feature = "catch-all-fields")]
10use serde_json::Value;
11
12#[non_exhaustive]
13#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
14#[serde(tag = "operationType", rename_all = "camelCase")]
15pub enum ChangeEvent {
16 Insert(ChangeInsertEvent),
17 Delete(ChangeDeleteEvent),
18 Drop(ChangeDropEvent),
19 DropDatabase(ChangeDropDatabaseEvent),
20 Invalidate(ChangeInvalidateEvent),
21 Replace(ChangeReplaceEvent),
22 Update(ChangeUpdateEvent),
23 Rename(ChangeRenameEvent),
24}
25
26#[non_exhaustive]
27#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
28pub struct DocumentDbInnerEvent {
29 pub event: ChangeEvent,
30 #[cfg(feature = "catch-all-fields")]
34 #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
35 #[serde(flatten)]
36 pub other: serde_json::Map<String, Value>,
37}
38
39#[non_exhaustive]
40#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
41#[serde(rename_all = "camelCase")]
42pub struct DocumentDbEvent {
43 #[serde(default)]
44 pub event_source_arn: Option<String>,
45 pub events: Vec<DocumentDbInnerEvent>,
46 #[serde(default)]
47 pub event_source: Option<String>,
48 #[cfg(feature = "catch-all-fields")]
52 #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
53 #[serde(flatten)]
54 pub other: serde_json::Map<String, Value>,
55}
56
57#[cfg(test)]
58#[cfg(feature = "documentdb")]
59mod test {
60 use super::*;
61
62 pub type Event = DocumentDbEvent;
63
64 fn test_example(data: &[u8]) {
65 let parsed: Event = serde_json::from_slice(data).unwrap();
66 let output: String = serde_json::to_string(&parsed).unwrap();
67 let reparsed: Event = serde_json::from_slice(output.as_bytes()).unwrap();
68
69 assert_eq!(parsed, reparsed);
70 }
71
72 #[test]
73 fn example_documentdb_insert_event() {
74 test_example(include_bytes!("../../fixtures/example-documentdb-insert-event.json"));
75 }
76
77 #[test]
78 fn example_documentdb_delete_event() {
79 test_example(include_bytes!("../../fixtures/example-documentdb-delete-event.json"));
80 }
81
82 #[test]
83 fn example_documentdb_drop_event() {
84 test_example(include_bytes!("../../fixtures/example-documentdb-drop-event.json"));
85 }
86
87 #[test]
88 fn example_documentdb_replace_event() {
89 test_example(include_bytes!("../../fixtures/example-documentdb-replace-event.json"));
90 }
91
92 #[test]
93 fn example_documentdb_update_event() {
94 test_example(include_bytes!("../../fixtures/example-documentdb-update-event.json"));
95 }
96
97 #[test]
98 fn example_documentdb_rename_event() {
99 test_example(include_bytes!("../../fixtures/example-documentdb-rename-event.json"));
100 }
101
102 #[test]
103 fn example_documentdb_invalidate_event() {
104 test_example(include_bytes!(
105 "../../fixtures/example-documentdb-invalidate-event.json"
106 ));
107 }
108
109 #[test]
110 fn example_documentdb_drop_database_event() {
111 test_example(include_bytes!(
112 "../../fixtures/example-documentdb-drop-database-event.json"
113 ));
114 }
115}