1use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct LogEntry<'a> {
13 source: Cow<'a, str>,
15 level: Cow<'a, str>,
17 text: Cow<'a, str>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 category: Option<Cow<'a, str>>,
21 timestamp: crate::runtime::Timestamp,
23 #[serde(skip_serializing_if = "Option::is_none")]
25 url: Option<Cow<'a, str>>,
26 #[serde(skip_serializing_if = "Option::is_none", rename = "lineNumber")]
28 line_number: Option<i64>,
29 #[serde(skip_serializing_if = "Option::is_none", rename = "stackTrace")]
31 stack_trace: Option<crate::runtime::StackTrace>,
32 #[serde(skip_serializing_if = "Option::is_none", rename = "networkRequestId")]
34 network_request_id: Option<crate::network::RequestId<'a>>,
35 #[serde(skip_serializing_if = "Option::is_none", rename = "workerId")]
37 worker_id: Option<Cow<'a, str>>,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 args: Option<Vec<crate::runtime::RemoteObject>>,
41}
42
43impl<'a> LogEntry<'a> {
44 pub fn builder(source: impl Into<Cow<'a, str>>, level: impl Into<Cow<'a, str>>, text: impl Into<Cow<'a, str>>, timestamp: crate::runtime::Timestamp) -> LogEntryBuilder<'a> {
50 LogEntryBuilder {
51 source: source.into(),
52 level: level.into(),
53 text: text.into(),
54 category: None,
55 timestamp: timestamp,
56 url: None,
57 line_number: None,
58 stack_trace: None,
59 network_request_id: None,
60 worker_id: None,
61 args: None,
62 }
63 }
64 pub fn source(&self) -> &str { self.source.as_ref() }
66 pub fn level(&self) -> &str { self.level.as_ref() }
68 pub fn text(&self) -> &str { self.text.as_ref() }
70 pub fn category(&self) -> Option<&str> { self.category.as_deref() }
71 pub fn timestamp(&self) -> &crate::runtime::Timestamp { &self.timestamp }
73 pub fn url(&self) -> Option<&str> { self.url.as_deref() }
75 pub fn line_number(&self) -> Option<i64> { self.line_number }
77 pub fn stack_trace(&self) -> Option<&crate::runtime::StackTrace> { self.stack_trace.as_ref() }
79 pub fn network_request_id(&self) -> Option<&crate::network::RequestId<'a>> { self.network_request_id.as_ref() }
81 pub fn worker_id(&self) -> Option<&str> { self.worker_id.as_deref() }
83 pub fn args(&self) -> Option<&[crate::runtime::RemoteObject]> { self.args.as_deref() }
85}
86
87
88pub struct LogEntryBuilder<'a> {
89 source: Cow<'a, str>,
90 level: Cow<'a, str>,
91 text: Cow<'a, str>,
92 category: Option<Cow<'a, str>>,
93 timestamp: crate::runtime::Timestamp,
94 url: Option<Cow<'a, str>>,
95 line_number: Option<i64>,
96 stack_trace: Option<crate::runtime::StackTrace>,
97 network_request_id: Option<crate::network::RequestId<'a>>,
98 worker_id: Option<Cow<'a, str>>,
99 args: Option<Vec<crate::runtime::RemoteObject>>,
100}
101
102impl<'a> LogEntryBuilder<'a> {
103 pub fn category(mut self, category: impl Into<Cow<'a, str>>) -> Self { self.category = Some(category.into()); self }
104 pub fn url(mut self, url: impl Into<Cow<'a, str>>) -> Self { self.url = Some(url.into()); self }
106 pub fn line_number(mut self, line_number: i64) -> Self { self.line_number = Some(line_number); self }
108 pub fn stack_trace(mut self, stack_trace: crate::runtime::StackTrace) -> Self { self.stack_trace = Some(stack_trace); self }
110 pub fn network_request_id(mut self, network_request_id: crate::network::RequestId<'a>) -> Self { self.network_request_id = Some(network_request_id); self }
112 pub fn worker_id(mut self, worker_id: impl Into<Cow<'a, str>>) -> Self { self.worker_id = Some(worker_id.into()); self }
114 pub fn args(mut self, args: Vec<crate::runtime::RemoteObject>) -> Self { self.args = Some(args); self }
116 pub fn build(self) -> LogEntry<'a> {
117 LogEntry {
118 source: self.source,
119 level: self.level,
120 text: self.text,
121 category: self.category,
122 timestamp: self.timestamp,
123 url: self.url,
124 line_number: self.line_number,
125 stack_trace: self.stack_trace,
126 network_request_id: self.network_request_id,
127 worker_id: self.worker_id,
128 args: self.args,
129 }
130 }
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, Default)]
136#[serde(rename_all = "camelCase")]
137pub struct ViolationSetting<'a> {
138 name: Cow<'a, str>,
140 threshold: f64,
142}
143
144impl<'a> ViolationSetting<'a> {
145 pub fn builder(name: impl Into<Cow<'a, str>>, threshold: f64) -> ViolationSettingBuilder<'a> {
149 ViolationSettingBuilder {
150 name: name.into(),
151 threshold: threshold,
152 }
153 }
154 pub fn name(&self) -> &str { self.name.as_ref() }
156 pub fn threshold(&self) -> f64 { self.threshold }
158}
159
160
161pub struct ViolationSettingBuilder<'a> {
162 name: Cow<'a, str>,
163 threshold: f64,
164}
165
166impl<'a> ViolationSettingBuilder<'a> {
167 pub fn build(self) -> ViolationSetting<'a> {
168 ViolationSetting {
169 name: self.name,
170 threshold: self.threshold,
171 }
172 }
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize, Default)]
176pub struct ClearParams {}
177
178impl ClearParams { pub const METHOD: &'static str = "Log.clear"; }
179
180impl<'a> crate::CdpCommand<'a> for ClearParams {
181 const METHOD: &'static str = "Log.clear";
182 type Response = crate::EmptyReturns;
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default)]
186pub struct DisableParams {}
187
188impl DisableParams { pub const METHOD: &'static str = "Log.disable"; }
189
190impl<'a> crate::CdpCommand<'a> for DisableParams {
191 const METHOD: &'static str = "Log.disable";
192 type Response = crate::EmptyReturns;
193}
194
195#[derive(Debug, Clone, Serialize, Deserialize, Default)]
196pub struct EnableParams {}
197
198impl EnableParams { pub const METHOD: &'static str = "Log.enable"; }
199
200impl<'a> crate::CdpCommand<'a> for EnableParams {
201 const METHOD: &'static str = "Log.enable";
202 type Response = crate::EmptyReturns;
203}
204
205#[derive(Debug, Clone, Serialize, Deserialize, Default)]
208#[serde(rename_all = "camelCase")]
209pub struct StartViolationsReportParams<'a> {
210 config: Vec<ViolationSetting<'a>>,
212}
213
214impl<'a> StartViolationsReportParams<'a> {
215 pub fn builder(config: Vec<ViolationSetting<'a>>) -> StartViolationsReportParamsBuilder<'a> {
218 StartViolationsReportParamsBuilder {
219 config: config,
220 }
221 }
222 pub fn config(&self) -> &[ViolationSetting<'a>] { &self.config }
224}
225
226
227pub struct StartViolationsReportParamsBuilder<'a> {
228 config: Vec<ViolationSetting<'a>>,
229}
230
231impl<'a> StartViolationsReportParamsBuilder<'a> {
232 pub fn build(self) -> StartViolationsReportParams<'a> {
233 StartViolationsReportParams {
234 config: self.config,
235 }
236 }
237}
238
239impl<'a> StartViolationsReportParams<'a> { pub const METHOD: &'static str = "Log.startViolationsReport"; }
240
241impl<'a> crate::CdpCommand<'a> for StartViolationsReportParams<'a> {
242 const METHOD: &'static str = "Log.startViolationsReport";
243 type Response = crate::EmptyReturns;
244}
245
246#[derive(Debug, Clone, Serialize, Deserialize, Default)]
247pub struct StopViolationsReportParams {}
248
249impl StopViolationsReportParams { pub const METHOD: &'static str = "Log.stopViolationsReport"; }
250
251impl<'a> crate::CdpCommand<'a> for StopViolationsReportParams {
252 const METHOD: &'static str = "Log.stopViolationsReport";
253 type Response = crate::EmptyReturns;
254}