Skip to main content

browser_protocol/indexeddb/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4/// Database with an array of object stores.
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct DatabaseWithObjectStores {
9    /// Database name.
10
11    pub name: String,
12    /// Database version (type is not 'integer', as the standard
13    /// requires the version number to be 'unsigned long long')
14
15    pub version: f64,
16    /// Object stores in this database.
17
18    pub objectStores: Vec<ObjectStore>,
19}
20
21/// Object store.
22
23#[derive(Debug, Clone, Serialize, Deserialize, Default)]
24#[serde(rename_all = "camelCase")]
25pub struct ObjectStore {
26    /// Object store name.
27
28    pub name: String,
29    /// Object store key path.
30
31    pub keyPath: KeyPath,
32    /// If true, object store has auto increment flag set.
33
34    pub autoIncrement: bool,
35    /// Indexes in this object store.
36
37    pub indexes: Vec<ObjectStoreIndex>,
38}
39
40/// Object store index.
41
42#[derive(Debug, Clone, Serialize, Deserialize, Default)]
43#[serde(rename_all = "camelCase")]
44pub struct ObjectStoreIndex {
45    /// Index name.
46
47    pub name: String,
48    /// Index key path.
49
50    pub keyPath: KeyPath,
51    /// If true, index is unique.
52
53    pub unique: bool,
54    /// If true, index allows multiple entries for a key.
55
56    pub multiEntry: bool,
57}
58
59/// Key.
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
62#[serde(rename_all = "camelCase")]
63pub struct Key {
64    /// Key type.
65
66    #[serde(rename = "type")]
67    pub type_: String,
68    /// Number value.
69
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub number: Option<f64>,
72    /// String value.
73
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub string: Option<String>,
76    /// Date value.
77
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub date: Option<f64>,
80    /// Array value.
81
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub array: Option<Vec<Key>>,
84}
85
86/// Key range.
87
88#[derive(Debug, Clone, Serialize, Deserialize, Default)]
89#[serde(rename_all = "camelCase")]
90pub struct KeyRange {
91    /// Lower bound.
92
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub lower: Option<Key>,
95    /// Upper bound.
96
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub upper: Option<Key>,
99    /// If true lower bound is open.
100
101    pub lowerOpen: bool,
102    /// If true upper bound is open.
103
104    pub upperOpen: bool,
105}
106
107/// Data entry.
108
109#[derive(Debug, Clone, Serialize, Deserialize, Default)]
110#[serde(rename_all = "camelCase")]
111pub struct DataEntry {
112    /// Key object.
113
114    pub key: crate::runtime::RemoteObject,
115    /// Primary key object.
116
117    pub primaryKey: crate::runtime::RemoteObject,
118    /// Value object.
119
120    pub value: crate::runtime::RemoteObject,
121}
122
123/// Key path.
124
125#[derive(Debug, Clone, Serialize, Deserialize, Default)]
126#[serde(rename_all = "camelCase")]
127pub struct KeyPath {
128    /// Key path type.
129
130    #[serde(rename = "type")]
131    pub type_: String,
132    /// String value.
133
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub string: Option<String>,
136    /// Array value.
137
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub array: Option<Vec<String>>,
140}
141
142/// Clears all entries from an object store.
143
144#[derive(Debug, Clone, Serialize, Deserialize, Default)]
145#[serde(rename_all = "camelCase")]
146pub struct ClearObjectStoreParams {
147    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
148    /// Security origin.
149
150    #[serde(skip_serializing_if = "Option::is_none")]
151    pub securityOrigin: Option<String>,
152    /// Storage key.
153
154    #[serde(skip_serializing_if = "Option::is_none")]
155    pub storageKey: Option<String>,
156    /// Storage bucket. If not specified, it uses the default bucket.
157
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub storageBucket: Option<crate::storage::StorageBucket>,
160    /// Database name.
161
162    pub databaseName: String,
163    /// Object store name.
164
165    pub objectStoreName: String,
166}
167
168impl ClearObjectStoreParams { pub const METHOD: &'static str = "IndexedDB.clearObjectStore"; }
169
170impl crate::CdpCommand for ClearObjectStoreParams {
171    const METHOD: &'static str = "IndexedDB.clearObjectStore";
172    type Response = crate::EmptyReturns;
173}
174
175/// Deletes a database.
176
177#[derive(Debug, Clone, Serialize, Deserialize, Default)]
178#[serde(rename_all = "camelCase")]
179pub struct DeleteDatabaseParams {
180    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
181    /// Security origin.
182
183    #[serde(skip_serializing_if = "Option::is_none")]
184    pub securityOrigin: Option<String>,
185    /// Storage key.
186
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub storageKey: Option<String>,
189    /// Storage bucket. If not specified, it uses the default bucket.
190
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub storageBucket: Option<crate::storage::StorageBucket>,
193    /// Database name.
194
195    pub databaseName: String,
196}
197
198impl DeleteDatabaseParams { pub const METHOD: &'static str = "IndexedDB.deleteDatabase"; }
199
200impl crate::CdpCommand for DeleteDatabaseParams {
201    const METHOD: &'static str = "IndexedDB.deleteDatabase";
202    type Response = crate::EmptyReturns;
203}
204
205/// Delete a range of entries from an object store
206
207#[derive(Debug, Clone, Serialize, Deserialize, Default)]
208#[serde(rename_all = "camelCase")]
209pub struct DeleteObjectStoreEntriesParams {
210    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
211    /// Security origin.
212
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub securityOrigin: Option<String>,
215    /// Storage key.
216
217    #[serde(skip_serializing_if = "Option::is_none")]
218    pub storageKey: Option<String>,
219    /// Storage bucket. If not specified, it uses the default bucket.
220
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub storageBucket: Option<crate::storage::StorageBucket>,
223
224    pub databaseName: String,
225
226    pub objectStoreName: String,
227    /// Range of entry keys to delete
228
229    pub keyRange: KeyRange,
230}
231
232impl DeleteObjectStoreEntriesParams { pub const METHOD: &'static str = "IndexedDB.deleteObjectStoreEntries"; }
233
234impl crate::CdpCommand for DeleteObjectStoreEntriesParams {
235    const METHOD: &'static str = "IndexedDB.deleteObjectStoreEntries";
236    type Response = crate::EmptyReturns;
237}
238
239#[derive(Debug, Clone, Serialize, Deserialize, Default)]
240pub struct DisableParams {}
241
242impl DisableParams { pub const METHOD: &'static str = "IndexedDB.disable"; }
243
244impl crate::CdpCommand for DisableParams {
245    const METHOD: &'static str = "IndexedDB.disable";
246    type Response = crate::EmptyReturns;
247}
248
249#[derive(Debug, Clone, Serialize, Deserialize, Default)]
250pub struct EnableParams {}
251
252impl EnableParams { pub const METHOD: &'static str = "IndexedDB.enable"; }
253
254impl crate::CdpCommand for EnableParams {
255    const METHOD: &'static str = "IndexedDB.enable";
256    type Response = crate::EmptyReturns;
257}
258
259/// Requests data from object store or index.
260
261#[derive(Debug, Clone, Serialize, Deserialize, Default)]
262#[serde(rename_all = "camelCase")]
263pub struct RequestDataParams {
264    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
265    /// Security origin.
266
267    #[serde(skip_serializing_if = "Option::is_none")]
268    pub securityOrigin: Option<String>,
269    /// Storage key.
270
271    #[serde(skip_serializing_if = "Option::is_none")]
272    pub storageKey: Option<String>,
273    /// Storage bucket. If not specified, it uses the default bucket.
274
275    #[serde(skip_serializing_if = "Option::is_none")]
276    pub storageBucket: Option<crate::storage::StorageBucket>,
277    /// Database name.
278
279    pub databaseName: String,
280    /// Object store name.
281
282    pub objectStoreName: String,
283    /// Index name. If not specified, it performs an object store data request.
284
285    #[serde(skip_serializing_if = "Option::is_none")]
286    pub indexName: Option<String>,
287    /// Number of records to skip.
288
289    pub skipCount: u64,
290    /// Number of records to fetch.
291
292    pub pageSize: u64,
293    /// Key range.
294
295    #[serde(skip_serializing_if = "Option::is_none")]
296    pub keyRange: Option<KeyRange>,
297}
298
299/// Requests data from object store or index.
300
301#[derive(Debug, Clone, Serialize, Deserialize, Default)]
302#[serde(rename_all = "camelCase")]
303pub struct RequestDataReturns {
304    /// Array of object store data entries.
305
306    pub objectStoreDataEntries: Vec<DataEntry>,
307    /// If true, there are more entries to fetch in the given range.
308
309    pub hasMore: bool,
310}
311
312impl RequestDataParams { pub const METHOD: &'static str = "IndexedDB.requestData"; }
313
314impl crate::CdpCommand for RequestDataParams {
315    const METHOD: &'static str = "IndexedDB.requestData";
316    type Response = RequestDataReturns;
317}
318
319/// Gets metadata of an object store.
320
321#[derive(Debug, Clone, Serialize, Deserialize, Default)]
322#[serde(rename_all = "camelCase")]
323pub struct GetMetadataParams {
324    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
325    /// Security origin.
326
327    #[serde(skip_serializing_if = "Option::is_none")]
328    pub securityOrigin: Option<String>,
329    /// Storage key.
330
331    #[serde(skip_serializing_if = "Option::is_none")]
332    pub storageKey: Option<String>,
333    /// Storage bucket. If not specified, it uses the default bucket.
334
335    #[serde(skip_serializing_if = "Option::is_none")]
336    pub storageBucket: Option<crate::storage::StorageBucket>,
337    /// Database name.
338
339    pub databaseName: String,
340    /// Object store name.
341
342    pub objectStoreName: String,
343}
344
345/// Gets metadata of an object store.
346
347#[derive(Debug, Clone, Serialize, Deserialize, Default)]
348#[serde(rename_all = "camelCase")]
349pub struct GetMetadataReturns {
350    /// the entries count
351
352    pub entriesCount: f64,
353    /// the current value of key generator, to become the next inserted
354    /// key into the object store. Valid if objectStore.autoIncrement
355    /// is true.
356
357    pub keyGeneratorValue: f64,
358}
359
360impl GetMetadataParams { pub const METHOD: &'static str = "IndexedDB.getMetadata"; }
361
362impl crate::CdpCommand for GetMetadataParams {
363    const METHOD: &'static str = "IndexedDB.getMetadata";
364    type Response = GetMetadataReturns;
365}
366
367/// Requests database with given name in given frame.
368
369#[derive(Debug, Clone, Serialize, Deserialize, Default)]
370#[serde(rename_all = "camelCase")]
371pub struct RequestDatabaseParams {
372    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
373    /// Security origin.
374
375    #[serde(skip_serializing_if = "Option::is_none")]
376    pub securityOrigin: Option<String>,
377    /// Storage key.
378
379    #[serde(skip_serializing_if = "Option::is_none")]
380    pub storageKey: Option<String>,
381    /// Storage bucket. If not specified, it uses the default bucket.
382
383    #[serde(skip_serializing_if = "Option::is_none")]
384    pub storageBucket: Option<crate::storage::StorageBucket>,
385    /// Database name.
386
387    pub databaseName: String,
388}
389
390/// Requests database with given name in given frame.
391
392#[derive(Debug, Clone, Serialize, Deserialize, Default)]
393#[serde(rename_all = "camelCase")]
394pub struct RequestDatabaseReturns {
395    /// Database with an array of object stores.
396
397    pub databaseWithObjectStores: DatabaseWithObjectStores,
398}
399
400impl RequestDatabaseParams { pub const METHOD: &'static str = "IndexedDB.requestDatabase"; }
401
402impl crate::CdpCommand for RequestDatabaseParams {
403    const METHOD: &'static str = "IndexedDB.requestDatabase";
404    type Response = RequestDatabaseReturns;
405}
406
407/// Requests database names for given security origin.
408
409#[derive(Debug, Clone, Serialize, Deserialize, Default)]
410#[serde(rename_all = "camelCase")]
411pub struct RequestDatabaseNamesParams {
412    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
413    /// Security origin.
414
415    #[serde(skip_serializing_if = "Option::is_none")]
416    pub securityOrigin: Option<String>,
417    /// Storage key.
418
419    #[serde(skip_serializing_if = "Option::is_none")]
420    pub storageKey: Option<String>,
421    /// Storage bucket. If not specified, it uses the default bucket.
422
423    #[serde(skip_serializing_if = "Option::is_none")]
424    pub storageBucket: Option<crate::storage::StorageBucket>,
425}
426
427/// Requests database names for given security origin.
428
429#[derive(Debug, Clone, Serialize, Deserialize, Default)]
430#[serde(rename_all = "camelCase")]
431pub struct RequestDatabaseNamesReturns {
432    /// Database names for origin.
433
434    pub databaseNames: Vec<String>,
435}
436
437impl RequestDatabaseNamesParams { pub const METHOD: &'static str = "IndexedDB.requestDatabaseNames"; }
438
439impl crate::CdpCommand for RequestDatabaseNamesParams {
440    const METHOD: &'static str = "IndexedDB.requestDatabaseNames";
441    type Response = RequestDatabaseNamesReturns;
442}