Skip to main content

browser_protocol/filesystem/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct File<'a> {
9    name: Cow<'a, str>,
10    /// Timestamp
11    #[serde(rename = "lastModified")]
12    last_modified: crate::network::TimeSinceEpoch,
13    /// Size in bytes
14    size: f64,
15    #[serde(rename = "type")]
16    type_: Cow<'a, str>,
17}
18
19impl<'a> File<'a> {
20    /// Creates a builder for this type with the required parameters:
21    /// * `name`: 
22    /// * `last_modified`: Timestamp
23    /// * `size`: Size in bytes
24    /// * `type_`: 
25    pub fn builder(name: impl Into<Cow<'a, str>>, last_modified: crate::network::TimeSinceEpoch, size: f64, type_: impl Into<Cow<'a, str>>) -> FileBuilder<'a> {
26        FileBuilder {
27            name: name.into(),
28            last_modified: last_modified,
29            size: size,
30            type_: type_.into(),
31        }
32    }
33    pub fn name(&self) -> &str { self.name.as_ref() }
34    /// Timestamp
35    pub fn last_modified(&self) -> &crate::network::TimeSinceEpoch { &self.last_modified }
36    /// Size in bytes
37    pub fn size(&self) -> f64 { self.size }
38    pub fn type_(&self) -> &str { self.type_.as_ref() }
39}
40
41
42pub struct FileBuilder<'a> {
43    name: Cow<'a, str>,
44    last_modified: crate::network::TimeSinceEpoch,
45    size: f64,
46    type_: Cow<'a, str>,
47}
48
49impl<'a> FileBuilder<'a> {
50    pub fn build(self) -> File<'a> {
51        File {
52            name: self.name,
53            last_modified: self.last_modified,
54            size: self.size,
55            type_: self.type_,
56        }
57    }
58}
59
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
62#[serde(rename_all = "camelCase")]
63pub struct Directory<'a> {
64    name: Cow<'a, str>,
65    #[serde(rename = "nestedDirectories")]
66    nested_directories: Vec<Cow<'a, str>>,
67    /// Files that are directly nested under this directory.
68    #[serde(rename = "nestedFiles")]
69    nested_files: Vec<File<'a>>,
70}
71
72impl<'a> Directory<'a> {
73    /// Creates a builder for this type with the required parameters:
74    /// * `name`: 
75    /// * `nested_directories`: 
76    /// * `nested_files`: Files that are directly nested under this directory.
77    pub fn builder(name: impl Into<Cow<'a, str>>, nested_directories: Vec<Cow<'a, str>>, nested_files: Vec<File<'a>>) -> DirectoryBuilder<'a> {
78        DirectoryBuilder {
79            name: name.into(),
80            nested_directories: nested_directories,
81            nested_files: nested_files,
82        }
83    }
84    pub fn name(&self) -> &str { self.name.as_ref() }
85    pub fn nested_directories(&self) -> &[Cow<'a, str>] { &self.nested_directories }
86    /// Files that are directly nested under this directory.
87    pub fn nested_files(&self) -> &[File<'a>] { &self.nested_files }
88}
89
90
91pub struct DirectoryBuilder<'a> {
92    name: Cow<'a, str>,
93    nested_directories: Vec<Cow<'a, str>>,
94    nested_files: Vec<File<'a>>,
95}
96
97impl<'a> DirectoryBuilder<'a> {
98    pub fn build(self) -> Directory<'a> {
99        Directory {
100            name: self.name,
101            nested_directories: self.nested_directories,
102            nested_files: self.nested_files,
103        }
104    }
105}
106
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
109#[serde(rename_all = "camelCase")]
110pub struct BucketFileSystemLocator<'a> {
111    /// Storage key
112    #[serde(rename = "storageKey")]
113    storage_key: crate::storage::SerializedStorageKey<'a>,
114    /// Bucket name. Not passing a 'bucketName' will retrieve the default Bucket. (<https://developer.mozilla.org/en-US/docs/Web/API/Storage_API#storage_buckets>)
115    #[serde(skip_serializing_if = "Option::is_none", rename = "bucketName")]
116    bucket_name: Option<Cow<'a, str>>,
117    /// Path to the directory using each path component as an array item.
118    #[serde(rename = "pathComponents")]
119    path_components: Vec<Cow<'a, str>>,
120}
121
122impl<'a> BucketFileSystemLocator<'a> {
123    /// Creates a builder for this type with the required parameters:
124    /// * `storage_key`: Storage key
125    /// * `path_components`: Path to the directory using each path component as an array item.
126    pub fn builder(storage_key: crate::storage::SerializedStorageKey<'a>, path_components: Vec<Cow<'a, str>>) -> BucketFileSystemLocatorBuilder<'a> {
127        BucketFileSystemLocatorBuilder {
128            storage_key: storage_key,
129            bucket_name: None,
130            path_components: path_components,
131        }
132    }
133    /// Storage key
134    pub fn storage_key(&self) -> &crate::storage::SerializedStorageKey<'a> { &self.storage_key }
135    /// Bucket name. Not passing a 'bucketName' will retrieve the default Bucket. (<https://developer.mozilla.org/en-US/docs/Web/API/Storage_API#storage_buckets>)
136    pub fn bucket_name(&self) -> Option<&str> { self.bucket_name.as_deref() }
137    /// Path to the directory using each path component as an array item.
138    pub fn path_components(&self) -> &[Cow<'a, str>] { &self.path_components }
139}
140
141
142pub struct BucketFileSystemLocatorBuilder<'a> {
143    storage_key: crate::storage::SerializedStorageKey<'a>,
144    bucket_name: Option<Cow<'a, str>>,
145    path_components: Vec<Cow<'a, str>>,
146}
147
148impl<'a> BucketFileSystemLocatorBuilder<'a> {
149    /// Bucket name. Not passing a 'bucketName' will retrieve the default Bucket. (<https://developer.mozilla.org/en-US/docs/Web/API/Storage_API#storage_buckets>)
150    pub fn bucket_name(mut self, bucket_name: impl Into<Cow<'a, str>>) -> Self { self.bucket_name = Some(bucket_name.into()); self }
151    pub fn build(self) -> BucketFileSystemLocator<'a> {
152        BucketFileSystemLocator {
153            storage_key: self.storage_key,
154            bucket_name: self.bucket_name,
155            path_components: self.path_components,
156        }
157    }
158}
159
160
161#[derive(Debug, Clone, Serialize, Deserialize, Default)]
162#[serde(rename_all = "camelCase")]
163pub struct GetDirectoryParams<'a> {
164    #[serde(rename = "bucketFileSystemLocator")]
165    bucket_file_system_locator: BucketFileSystemLocator<'a>,
166}
167
168impl<'a> GetDirectoryParams<'a> {
169    /// Creates a builder for this type with the required parameters:
170    /// * `bucket_file_system_locator`: 
171    pub fn builder(bucket_file_system_locator: BucketFileSystemLocator<'a>) -> GetDirectoryParamsBuilder<'a> {
172        GetDirectoryParamsBuilder {
173            bucket_file_system_locator: bucket_file_system_locator,
174        }
175    }
176    pub fn bucket_file_system_locator(&self) -> &BucketFileSystemLocator<'a> { &self.bucket_file_system_locator }
177}
178
179
180pub struct GetDirectoryParamsBuilder<'a> {
181    bucket_file_system_locator: BucketFileSystemLocator<'a>,
182}
183
184impl<'a> GetDirectoryParamsBuilder<'a> {
185    pub fn build(self) -> GetDirectoryParams<'a> {
186        GetDirectoryParams {
187            bucket_file_system_locator: self.bucket_file_system_locator,
188        }
189    }
190}
191
192
193#[derive(Debug, Clone, Serialize, Deserialize, Default)]
194#[serde(rename_all = "camelCase")]
195pub struct GetDirectoryReturns<'a> {
196    /// Returns the directory object at the path.
197    directory: Directory<'a>,
198}
199
200impl<'a> GetDirectoryReturns<'a> {
201    /// Creates a builder for this type with the required parameters:
202    /// * `directory`: Returns the directory object at the path.
203    pub fn builder(directory: Directory<'a>) -> GetDirectoryReturnsBuilder<'a> {
204        GetDirectoryReturnsBuilder {
205            directory: directory,
206        }
207    }
208    /// Returns the directory object at the path.
209    pub fn directory(&self) -> &Directory<'a> { &self.directory }
210}
211
212
213pub struct GetDirectoryReturnsBuilder<'a> {
214    directory: Directory<'a>,
215}
216
217impl<'a> GetDirectoryReturnsBuilder<'a> {
218    pub fn build(self) -> GetDirectoryReturns<'a> {
219        GetDirectoryReturns {
220            directory: self.directory,
221        }
222    }
223}
224
225impl<'a> GetDirectoryParams<'a> { pub const METHOD: &'static str = "FileSystem.getDirectory"; }
226
227impl<'a> crate::CdpCommand<'a> for GetDirectoryParams<'a> {
228    const METHOD: &'static str = "FileSystem.getDirectory";
229    type Response = GetDirectoryReturns<'a>;
230}