1use streamdal_wasm_transform::transform;
2use streamdal_wasm_transform::transform::{TruncateOptions, TruncateType};
3
4fn main() {
5 println!("Overwrite example");
6 overwrite();
7
8 println!("Mask string example");
9 mask_string();
10
11 println!("Mask number example");
12 mask_number();
13
14 println!("Obfuscate string example");
15 obfuscate_string();
16
17 println!("Truncate string example");
18 truncate_string();
19
20 println!("Delete field example");
21 delete_field();
22}
23
24fn overwrite() {
25 let sample_json = r#"{"hello": "world"}"#;
26
27 let req = transform::Request {
28 data: sample_json.into(),
29 path: "hello".to_string(),
30 value: r#""baz""#.to_string(),
31 truncate_options: None,
32 extract_options: None,
33 };
34
35 let updated_json = transform::overwrite(&req).unwrap();
36
37 println!(
38 "Input JSON: {} || Result JSON: {}",
39 sample_json, updated_json,
40 )
41}
42
43fn mask_string() {
44 let sample_json = r#"{"hello": "world"}"#;
45
46 let req = transform::Request {
47 data: sample_json.into(),
48 path: "hello".to_string(),
49 value: "".to_string(),
50 truncate_options: None,
51 extract_options: None,
52 };
53
54 let updated_json = transform::mask(&req).unwrap();
55
56 println!(
57 "Input JSON: {} || Result JSON: {}",
58 sample_json, updated_json,
59 )
60}
61
62fn mask_number() {
63 let sample_json = r#"{"hello": 329328102938}"#;
64
65 let req = transform::Request {
66 path: "hello".to_string(),
67 data: sample_json.into(),
68 value: "".to_string(), truncate_options: None,
70 extract_options: None,
71 };
72
73 let updated_json = transform::mask(&req).unwrap();
74
75 println!(
76 "Input JSON: {} || Result JSON: {}",
77 sample_json, updated_json,
78 )
79}
80
81fn obfuscate_string() {
82 let sample_json = r#"{"hello": "world"}"#;
83
84 let req = transform::Request {
85 path: "hello".to_string(),
86 data: sample_json.into(),
87 value: "".to_string(), truncate_options: None,
89 extract_options: None,
90 };
91
92 let updated_json = transform::obfuscate(&req).unwrap();
93
94 println!(
95 "Input JSON: {} || Result JSON: {}",
96 sample_json, updated_json,
97 )
98}
99
100fn truncate_string() {
101 let sample_json = r#"{"hello": "world"}"#;
102
103 let req = transform::Request {
104 path: "hello".to_string(),
105 data: sample_json.into(),
106 value: "".to_string(), truncate_options: Some(TruncateOptions {
108 length: 3,
109 truncate_type: TruncateType::Chars,
110 }),
111 extract_options: None,
112 };
113
114 let updated_json = transform::truncate(&req).unwrap();
115
116 println!(
117 "Input JSON: {} || Result JSON: {}",
118 sample_json, updated_json,
119 )
120}
121
122fn delete_field() {
123 let sample_json = r#"{"hello": "world"}"#;
124
125 let req = transform::Request {
126 path: "hello".to_string(),
127 data: sample_json.into(),
128 value: "".to_string(), truncate_options: None,
130 extract_options: None,
131 };
132
133 let updated_json = transform::delete(&req).unwrap();
134
135 println!(
136 "Input JSON: {} || Result JSON: {}",
137 sample_json, updated_json,
138 )
139}