Skip to main content

browser_protocol/indexeddb/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5/// Database with an array of object stores.
6
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct DatabaseWithObjectStores<'a> {
10    /// Database name.
11    name: Cow<'a, str>,
12    /// Database version (type is not 'integer', as the standard
13    /// requires the version number to be 'unsigned long long')
14    version: f64,
15    /// Object stores in this database.
16    objectStores: Vec<ObjectStore<'a>>,
17}
18
19impl<'a> DatabaseWithObjectStores<'a> {
20    pub fn builder(name: impl Into<Cow<'a, str>>, version: f64, objectStores: Vec<ObjectStore<'a>>) -> DatabaseWithObjectStoresBuilder<'a> {
21        DatabaseWithObjectStoresBuilder {
22            name: name.into(),
23            version: version,
24            objectStores: objectStores,
25        }
26    }
27    pub fn name(&self) -> &str { self.name.as_ref() }
28    pub fn version(&self) -> f64 { self.version }
29    pub fn objectStores(&self) -> &[ObjectStore<'a>] { &self.objectStores }
30}
31
32
33pub struct DatabaseWithObjectStoresBuilder<'a> {
34    name: Cow<'a, str>,
35    version: f64,
36    objectStores: Vec<ObjectStore<'a>>,
37}
38
39impl<'a> DatabaseWithObjectStoresBuilder<'a> {
40    pub fn build(self) -> DatabaseWithObjectStores<'a> {
41        DatabaseWithObjectStores {
42            name: self.name,
43            version: self.version,
44            objectStores: self.objectStores,
45        }
46    }
47}
48
49/// Object store.
50
51#[derive(Debug, Clone, Serialize, Deserialize, Default)]
52#[serde(rename_all = "camelCase")]
53pub struct ObjectStore<'a> {
54    /// Object store name.
55    name: Cow<'a, str>,
56    /// Object store key path.
57    keyPath: KeyPath<'a>,
58    /// If true, object store has auto increment flag set.
59    autoIncrement: bool,
60    /// Indexes in this object store.
61    indexes: Vec<ObjectStoreIndex<'a>>,
62}
63
64impl<'a> ObjectStore<'a> {
65    pub fn builder(name: impl Into<Cow<'a, str>>, keyPath: KeyPath<'a>, autoIncrement: bool, indexes: Vec<ObjectStoreIndex<'a>>) -> ObjectStoreBuilder<'a> {
66        ObjectStoreBuilder {
67            name: name.into(),
68            keyPath: keyPath,
69            autoIncrement: autoIncrement,
70            indexes: indexes,
71        }
72    }
73    pub fn name(&self) -> &str { self.name.as_ref() }
74    pub fn keyPath(&self) -> &KeyPath<'a> { &self.keyPath }
75    pub fn autoIncrement(&self) -> bool { self.autoIncrement }
76    pub fn indexes(&self) -> &[ObjectStoreIndex<'a>] { &self.indexes }
77}
78
79
80pub struct ObjectStoreBuilder<'a> {
81    name: Cow<'a, str>,
82    keyPath: KeyPath<'a>,
83    autoIncrement: bool,
84    indexes: Vec<ObjectStoreIndex<'a>>,
85}
86
87impl<'a> ObjectStoreBuilder<'a> {
88    pub fn build(self) -> ObjectStore<'a> {
89        ObjectStore {
90            name: self.name,
91            keyPath: self.keyPath,
92            autoIncrement: self.autoIncrement,
93            indexes: self.indexes,
94        }
95    }
96}
97
98/// Object store index.
99
100#[derive(Debug, Clone, Serialize, Deserialize, Default)]
101#[serde(rename_all = "camelCase")]
102pub struct ObjectStoreIndex<'a> {
103    /// Index name.
104    name: Cow<'a, str>,
105    /// Index key path.
106    keyPath: KeyPath<'a>,
107    /// If true, index is unique.
108    unique: bool,
109    /// If true, index allows multiple entries for a key.
110    multiEntry: bool,
111}
112
113impl<'a> ObjectStoreIndex<'a> {
114    pub fn builder(name: impl Into<Cow<'a, str>>, keyPath: KeyPath<'a>, unique: bool, multiEntry: bool) -> ObjectStoreIndexBuilder<'a> {
115        ObjectStoreIndexBuilder {
116            name: name.into(),
117            keyPath: keyPath,
118            unique: unique,
119            multiEntry: multiEntry,
120        }
121    }
122    pub fn name(&self) -> &str { self.name.as_ref() }
123    pub fn keyPath(&self) -> &KeyPath<'a> { &self.keyPath }
124    pub fn unique(&self) -> bool { self.unique }
125    pub fn multiEntry(&self) -> bool { self.multiEntry }
126}
127
128
129pub struct ObjectStoreIndexBuilder<'a> {
130    name: Cow<'a, str>,
131    keyPath: KeyPath<'a>,
132    unique: bool,
133    multiEntry: bool,
134}
135
136impl<'a> ObjectStoreIndexBuilder<'a> {
137    pub fn build(self) -> ObjectStoreIndex<'a> {
138        ObjectStoreIndex {
139            name: self.name,
140            keyPath: self.keyPath,
141            unique: self.unique,
142            multiEntry: self.multiEntry,
143        }
144    }
145}
146
147/// Key.
148
149#[derive(Debug, Clone, Serialize, Deserialize, Default)]
150#[serde(rename_all = "camelCase")]
151pub struct Key<'a> {
152    /// Key type.
153    #[serde(rename = "type")]
154    type_: Cow<'a, str>,
155    /// Number value.
156    #[serde(skip_serializing_if = "Option::is_none")]
157    number: Option<f64>,
158    /// String value.
159    #[serde(skip_serializing_if = "Option::is_none")]
160    string: Option<Cow<'a, str>>,
161    /// Date value.
162    #[serde(skip_serializing_if = "Option::is_none")]
163    date: Option<f64>,
164    /// Array value.
165    #[serde(skip_serializing_if = "Option::is_none")]
166    array: Option<Vec<Box<Key<'a>>>>,
167}
168
169impl<'a> Key<'a> {
170    pub fn builder(type_: impl Into<Cow<'a, str>>) -> KeyBuilder<'a> {
171        KeyBuilder {
172            type_: type_.into(),
173            number: None,
174            string: None,
175            date: None,
176            array: None,
177        }
178    }
179    pub fn type_(&self) -> &str { self.type_.as_ref() }
180    pub fn number(&self) -> Option<f64> { self.number }
181    pub fn string(&self) -> Option<&str> { self.string.as_deref() }
182    pub fn date(&self) -> Option<f64> { self.date }
183    pub fn array(&self) -> Option<&[Box<Key<'a>>]> { self.array.as_deref() }
184}
185
186
187pub struct KeyBuilder<'a> {
188    type_: Cow<'a, str>,
189    number: Option<f64>,
190    string: Option<Cow<'a, str>>,
191    date: Option<f64>,
192    array: Option<Vec<Box<Key<'a>>>>,
193}
194
195impl<'a> KeyBuilder<'a> {
196    /// Number value.
197    pub fn number(mut self, number: f64) -> Self { self.number = Some(number); self }
198    /// String value.
199    pub fn string(mut self, string: impl Into<Cow<'a, str>>) -> Self { self.string = Some(string.into()); self }
200    /// Date value.
201    pub fn date(mut self, date: f64) -> Self { self.date = Some(date); self }
202    /// Array value.
203    pub fn array(mut self, array: Vec<Box<Key<'a>>>) -> Self { self.array = Some(array); self }
204    pub fn build(self) -> Key<'a> {
205        Key {
206            type_: self.type_,
207            number: self.number,
208            string: self.string,
209            date: self.date,
210            array: self.array,
211        }
212    }
213}
214
215/// Key range.
216
217#[derive(Debug, Clone, Serialize, Deserialize, Default)]
218#[serde(rename_all = "camelCase")]
219pub struct KeyRange<'a> {
220    /// Lower bound.
221    #[serde(skip_serializing_if = "Option::is_none")]
222    lower: Option<Key<'a>>,
223    /// Upper bound.
224    #[serde(skip_serializing_if = "Option::is_none")]
225    upper: Option<Key<'a>>,
226    /// If true lower bound is open.
227    lowerOpen: bool,
228    /// If true upper bound is open.
229    upperOpen: bool,
230}
231
232impl<'a> KeyRange<'a> {
233    pub fn builder(lowerOpen: bool, upperOpen: bool) -> KeyRangeBuilder<'a> {
234        KeyRangeBuilder {
235            lower: None,
236            upper: None,
237            lowerOpen: lowerOpen,
238            upperOpen: upperOpen,
239        }
240    }
241    pub fn lower(&self) -> Option<&Key<'a>> { self.lower.as_ref() }
242    pub fn upper(&self) -> Option<&Key<'a>> { self.upper.as_ref() }
243    pub fn lowerOpen(&self) -> bool { self.lowerOpen }
244    pub fn upperOpen(&self) -> bool { self.upperOpen }
245}
246
247
248pub struct KeyRangeBuilder<'a> {
249    lower: Option<Key<'a>>,
250    upper: Option<Key<'a>>,
251    lowerOpen: bool,
252    upperOpen: bool,
253}
254
255impl<'a> KeyRangeBuilder<'a> {
256    /// Lower bound.
257    pub fn lower(mut self, lower: Key<'a>) -> Self { self.lower = Some(lower); self }
258    /// Upper bound.
259    pub fn upper(mut self, upper: Key<'a>) -> Self { self.upper = Some(upper); self }
260    pub fn build(self) -> KeyRange<'a> {
261        KeyRange {
262            lower: self.lower,
263            upper: self.upper,
264            lowerOpen: self.lowerOpen,
265            upperOpen: self.upperOpen,
266        }
267    }
268}
269
270/// Data entry.
271
272#[derive(Debug, Clone, Serialize, Deserialize, Default)]
273#[serde(rename_all = "camelCase")]
274pub struct DataEntry {
275    /// Key object.
276    key: crate::runtime::RemoteObject,
277    /// Primary key object.
278    primaryKey: crate::runtime::RemoteObject,
279    /// Value object.
280    value: crate::runtime::RemoteObject,
281}
282
283impl DataEntry {
284    pub fn builder(key: crate::runtime::RemoteObject, primaryKey: crate::runtime::RemoteObject, value: crate::runtime::RemoteObject) -> DataEntryBuilder {
285        DataEntryBuilder {
286            key: key,
287            primaryKey: primaryKey,
288            value: value,
289        }
290    }
291    pub fn key(&self) -> &crate::runtime::RemoteObject { &self.key }
292    pub fn primaryKey(&self) -> &crate::runtime::RemoteObject { &self.primaryKey }
293    pub fn value(&self) -> &crate::runtime::RemoteObject { &self.value }
294}
295
296
297pub struct DataEntryBuilder {
298    key: crate::runtime::RemoteObject,
299    primaryKey: crate::runtime::RemoteObject,
300    value: crate::runtime::RemoteObject,
301}
302
303impl DataEntryBuilder {
304    pub fn build(self) -> DataEntry {
305        DataEntry {
306            key: self.key,
307            primaryKey: self.primaryKey,
308            value: self.value,
309        }
310    }
311}
312
313/// Key path.
314
315#[derive(Debug, Clone, Serialize, Deserialize, Default)]
316#[serde(rename_all = "camelCase")]
317pub struct KeyPath<'a> {
318    /// Key path type.
319    #[serde(rename = "type")]
320    type_: Cow<'a, str>,
321    /// String value.
322    #[serde(skip_serializing_if = "Option::is_none")]
323    string: Option<Cow<'a, str>>,
324    /// Array value.
325    #[serde(skip_serializing_if = "Option::is_none")]
326    array: Option<Vec<Cow<'a, str>>>,
327}
328
329impl<'a> KeyPath<'a> {
330    pub fn builder(type_: impl Into<Cow<'a, str>>) -> KeyPathBuilder<'a> {
331        KeyPathBuilder {
332            type_: type_.into(),
333            string: None,
334            array: None,
335        }
336    }
337    pub fn type_(&self) -> &str { self.type_.as_ref() }
338    pub fn string(&self) -> Option<&str> { self.string.as_deref() }
339    pub fn array(&self) -> Option<&[Cow<'a, str>]> { self.array.as_deref() }
340}
341
342
343pub struct KeyPathBuilder<'a> {
344    type_: Cow<'a, str>,
345    string: Option<Cow<'a, str>>,
346    array: Option<Vec<Cow<'a, str>>>,
347}
348
349impl<'a> KeyPathBuilder<'a> {
350    /// String value.
351    pub fn string(mut self, string: impl Into<Cow<'a, str>>) -> Self { self.string = Some(string.into()); self }
352    /// Array value.
353    pub fn array(mut self, array: Vec<Cow<'a, str>>) -> Self { self.array = Some(array); self }
354    pub fn build(self) -> KeyPath<'a> {
355        KeyPath {
356            type_: self.type_,
357            string: self.string,
358            array: self.array,
359        }
360    }
361}
362
363/// Clears all entries from an object store.
364
365#[derive(Debug, Clone, Serialize, Deserialize, Default)]
366#[serde(rename_all = "camelCase")]
367pub struct ClearObjectStoreParams<'a> {
368    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
369    /// Security origin.
370    #[serde(skip_serializing_if = "Option::is_none")]
371    securityOrigin: Option<Cow<'a, str>>,
372    /// Storage key.
373    #[serde(skip_serializing_if = "Option::is_none")]
374    storageKey: Option<Cow<'a, str>>,
375    /// Storage bucket. If not specified, it uses the default bucket.
376    #[serde(skip_serializing_if = "Option::is_none")]
377    storageBucket: Option<crate::storage::StorageBucket<'a>>,
378    /// Database name.
379    databaseName: Cow<'a, str>,
380    /// Object store name.
381    objectStoreName: Cow<'a, str>,
382}
383
384impl<'a> ClearObjectStoreParams<'a> {
385    pub fn builder(databaseName: impl Into<Cow<'a, str>>, objectStoreName: impl Into<Cow<'a, str>>) -> ClearObjectStoreParamsBuilder<'a> {
386        ClearObjectStoreParamsBuilder {
387            securityOrigin: None,
388            storageKey: None,
389            storageBucket: None,
390            databaseName: databaseName.into(),
391            objectStoreName: objectStoreName.into(),
392        }
393    }
394    pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
395    pub fn storageKey(&self) -> Option<&str> { self.storageKey.as_deref() }
396    pub fn storageBucket(&self) -> Option<&crate::storage::StorageBucket<'a>> { self.storageBucket.as_ref() }
397    pub fn databaseName(&self) -> &str { self.databaseName.as_ref() }
398    pub fn objectStoreName(&self) -> &str { self.objectStoreName.as_ref() }
399}
400
401
402pub struct ClearObjectStoreParamsBuilder<'a> {
403    securityOrigin: Option<Cow<'a, str>>,
404    storageKey: Option<Cow<'a, str>>,
405    storageBucket: Option<crate::storage::StorageBucket<'a>>,
406    databaseName: Cow<'a, str>,
407    objectStoreName: Cow<'a, str>,
408}
409
410impl<'a> ClearObjectStoreParamsBuilder<'a> {
411    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
412    /// Security origin.
413    pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
414    /// Storage key.
415    pub fn storageKey(mut self, storageKey: impl Into<Cow<'a, str>>) -> Self { self.storageKey = Some(storageKey.into()); self }
416    /// Storage bucket. If not specified, it uses the default bucket.
417    pub fn storageBucket(mut self, storageBucket: crate::storage::StorageBucket<'a>) -> Self { self.storageBucket = Some(storageBucket); self }
418    pub fn build(self) -> ClearObjectStoreParams<'a> {
419        ClearObjectStoreParams {
420            securityOrigin: self.securityOrigin,
421            storageKey: self.storageKey,
422            storageBucket: self.storageBucket,
423            databaseName: self.databaseName,
424            objectStoreName: self.objectStoreName,
425        }
426    }
427}
428
429impl<'a> ClearObjectStoreParams<'a> { pub const METHOD: &'static str = "IndexedDB.clearObjectStore"; }
430
431impl<'a> crate::CdpCommand<'a> for ClearObjectStoreParams<'a> {
432    const METHOD: &'static str = "IndexedDB.clearObjectStore";
433    type Response = crate::EmptyReturns;
434}
435
436/// Deletes a database.
437
438#[derive(Debug, Clone, Serialize, Deserialize, Default)]
439#[serde(rename_all = "camelCase")]
440pub struct DeleteDatabaseParams<'a> {
441    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
442    /// Security origin.
443    #[serde(skip_serializing_if = "Option::is_none")]
444    securityOrigin: Option<Cow<'a, str>>,
445    /// Storage key.
446    #[serde(skip_serializing_if = "Option::is_none")]
447    storageKey: Option<Cow<'a, str>>,
448    /// Storage bucket. If not specified, it uses the default bucket.
449    #[serde(skip_serializing_if = "Option::is_none")]
450    storageBucket: Option<crate::storage::StorageBucket<'a>>,
451    /// Database name.
452    databaseName: Cow<'a, str>,
453}
454
455impl<'a> DeleteDatabaseParams<'a> {
456    pub fn builder(databaseName: impl Into<Cow<'a, str>>) -> DeleteDatabaseParamsBuilder<'a> {
457        DeleteDatabaseParamsBuilder {
458            securityOrigin: None,
459            storageKey: None,
460            storageBucket: None,
461            databaseName: databaseName.into(),
462        }
463    }
464    pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
465    pub fn storageKey(&self) -> Option<&str> { self.storageKey.as_deref() }
466    pub fn storageBucket(&self) -> Option<&crate::storage::StorageBucket<'a>> { self.storageBucket.as_ref() }
467    pub fn databaseName(&self) -> &str { self.databaseName.as_ref() }
468}
469
470
471pub struct DeleteDatabaseParamsBuilder<'a> {
472    securityOrigin: Option<Cow<'a, str>>,
473    storageKey: Option<Cow<'a, str>>,
474    storageBucket: Option<crate::storage::StorageBucket<'a>>,
475    databaseName: Cow<'a, str>,
476}
477
478impl<'a> DeleteDatabaseParamsBuilder<'a> {
479    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
480    /// Security origin.
481    pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
482    /// Storage key.
483    pub fn storageKey(mut self, storageKey: impl Into<Cow<'a, str>>) -> Self { self.storageKey = Some(storageKey.into()); self }
484    /// Storage bucket. If not specified, it uses the default bucket.
485    pub fn storageBucket(mut self, storageBucket: crate::storage::StorageBucket<'a>) -> Self { self.storageBucket = Some(storageBucket); self }
486    pub fn build(self) -> DeleteDatabaseParams<'a> {
487        DeleteDatabaseParams {
488            securityOrigin: self.securityOrigin,
489            storageKey: self.storageKey,
490            storageBucket: self.storageBucket,
491            databaseName: self.databaseName,
492        }
493    }
494}
495
496impl<'a> DeleteDatabaseParams<'a> { pub const METHOD: &'static str = "IndexedDB.deleteDatabase"; }
497
498impl<'a> crate::CdpCommand<'a> for DeleteDatabaseParams<'a> {
499    const METHOD: &'static str = "IndexedDB.deleteDatabase";
500    type Response = crate::EmptyReturns;
501}
502
503/// Delete a range of entries from an object store
504
505#[derive(Debug, Clone, Serialize, Deserialize, Default)]
506#[serde(rename_all = "camelCase")]
507pub struct DeleteObjectStoreEntriesParams<'a> {
508    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
509    /// Security origin.
510    #[serde(skip_serializing_if = "Option::is_none")]
511    securityOrigin: Option<Cow<'a, str>>,
512    /// Storage key.
513    #[serde(skip_serializing_if = "Option::is_none")]
514    storageKey: Option<Cow<'a, str>>,
515    /// Storage bucket. If not specified, it uses the default bucket.
516    #[serde(skip_serializing_if = "Option::is_none")]
517    storageBucket: Option<crate::storage::StorageBucket<'a>>,
518    databaseName: Cow<'a, str>,
519    objectStoreName: Cow<'a, str>,
520    /// Range of entry keys to delete
521    keyRange: KeyRange<'a>,
522}
523
524impl<'a> DeleteObjectStoreEntriesParams<'a> {
525    pub fn builder(databaseName: impl Into<Cow<'a, str>>, objectStoreName: impl Into<Cow<'a, str>>, keyRange: KeyRange<'a>) -> DeleteObjectStoreEntriesParamsBuilder<'a> {
526        DeleteObjectStoreEntriesParamsBuilder {
527            securityOrigin: None,
528            storageKey: None,
529            storageBucket: None,
530            databaseName: databaseName.into(),
531            objectStoreName: objectStoreName.into(),
532            keyRange: keyRange,
533        }
534    }
535    pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
536    pub fn storageKey(&self) -> Option<&str> { self.storageKey.as_deref() }
537    pub fn storageBucket(&self) -> Option<&crate::storage::StorageBucket<'a>> { self.storageBucket.as_ref() }
538    pub fn databaseName(&self) -> &str { self.databaseName.as_ref() }
539    pub fn objectStoreName(&self) -> &str { self.objectStoreName.as_ref() }
540    pub fn keyRange(&self) -> &KeyRange<'a> { &self.keyRange }
541}
542
543
544pub struct DeleteObjectStoreEntriesParamsBuilder<'a> {
545    securityOrigin: Option<Cow<'a, str>>,
546    storageKey: Option<Cow<'a, str>>,
547    storageBucket: Option<crate::storage::StorageBucket<'a>>,
548    databaseName: Cow<'a, str>,
549    objectStoreName: Cow<'a, str>,
550    keyRange: KeyRange<'a>,
551}
552
553impl<'a> DeleteObjectStoreEntriesParamsBuilder<'a> {
554    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
555    /// Security origin.
556    pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
557    /// Storage key.
558    pub fn storageKey(mut self, storageKey: impl Into<Cow<'a, str>>) -> Self { self.storageKey = Some(storageKey.into()); self }
559    /// Storage bucket. If not specified, it uses the default bucket.
560    pub fn storageBucket(mut self, storageBucket: crate::storage::StorageBucket<'a>) -> Self { self.storageBucket = Some(storageBucket); self }
561    pub fn build(self) -> DeleteObjectStoreEntriesParams<'a> {
562        DeleteObjectStoreEntriesParams {
563            securityOrigin: self.securityOrigin,
564            storageKey: self.storageKey,
565            storageBucket: self.storageBucket,
566            databaseName: self.databaseName,
567            objectStoreName: self.objectStoreName,
568            keyRange: self.keyRange,
569        }
570    }
571}
572
573impl<'a> DeleteObjectStoreEntriesParams<'a> { pub const METHOD: &'static str = "IndexedDB.deleteObjectStoreEntries"; }
574
575impl<'a> crate::CdpCommand<'a> for DeleteObjectStoreEntriesParams<'a> {
576    const METHOD: &'static str = "IndexedDB.deleteObjectStoreEntries";
577    type Response = crate::EmptyReturns;
578}
579
580#[derive(Debug, Clone, Serialize, Deserialize, Default)]
581pub struct DisableParams {}
582
583impl DisableParams { pub const METHOD: &'static str = "IndexedDB.disable"; }
584
585impl<'a> crate::CdpCommand<'a> for DisableParams {
586    const METHOD: &'static str = "IndexedDB.disable";
587    type Response = crate::EmptyReturns;
588}
589
590#[derive(Debug, Clone, Serialize, Deserialize, Default)]
591pub struct EnableParams {}
592
593impl EnableParams { pub const METHOD: &'static str = "IndexedDB.enable"; }
594
595impl<'a> crate::CdpCommand<'a> for EnableParams {
596    const METHOD: &'static str = "IndexedDB.enable";
597    type Response = crate::EmptyReturns;
598}
599
600/// Requests data from object store or index.
601
602#[derive(Debug, Clone, Serialize, Deserialize, Default)]
603#[serde(rename_all = "camelCase")]
604pub struct RequestDataParams<'a> {
605    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
606    /// Security origin.
607    #[serde(skip_serializing_if = "Option::is_none")]
608    securityOrigin: Option<Cow<'a, str>>,
609    /// Storage key.
610    #[serde(skip_serializing_if = "Option::is_none")]
611    storageKey: Option<Cow<'a, str>>,
612    /// Storage bucket. If not specified, it uses the default bucket.
613    #[serde(skip_serializing_if = "Option::is_none")]
614    storageBucket: Option<crate::storage::StorageBucket<'a>>,
615    /// Database name.
616    databaseName: Cow<'a, str>,
617    /// Object store name.
618    objectStoreName: Cow<'a, str>,
619    /// Index name. If not specified, it performs an object store data request.
620    #[serde(skip_serializing_if = "Option::is_none")]
621    indexName: Option<Cow<'a, str>>,
622    /// Number of records to skip.
623    skipCount: u64,
624    /// Number of records to fetch.
625    pageSize: u64,
626    /// Key range.
627    #[serde(skip_serializing_if = "Option::is_none")]
628    keyRange: Option<KeyRange<'a>>,
629}
630
631impl<'a> RequestDataParams<'a> {
632    pub fn builder(databaseName: impl Into<Cow<'a, str>>, objectStoreName: impl Into<Cow<'a, str>>, skipCount: u64, pageSize: u64) -> RequestDataParamsBuilder<'a> {
633        RequestDataParamsBuilder {
634            securityOrigin: None,
635            storageKey: None,
636            storageBucket: None,
637            databaseName: databaseName.into(),
638            objectStoreName: objectStoreName.into(),
639            indexName: None,
640            skipCount: skipCount,
641            pageSize: pageSize,
642            keyRange: None,
643        }
644    }
645    pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
646    pub fn storageKey(&self) -> Option<&str> { self.storageKey.as_deref() }
647    pub fn storageBucket(&self) -> Option<&crate::storage::StorageBucket<'a>> { self.storageBucket.as_ref() }
648    pub fn databaseName(&self) -> &str { self.databaseName.as_ref() }
649    pub fn objectStoreName(&self) -> &str { self.objectStoreName.as_ref() }
650    pub fn indexName(&self) -> Option<&str> { self.indexName.as_deref() }
651    pub fn skipCount(&self) -> u64 { self.skipCount }
652    pub fn pageSize(&self) -> u64 { self.pageSize }
653    pub fn keyRange(&self) -> Option<&KeyRange<'a>> { self.keyRange.as_ref() }
654}
655
656
657pub struct RequestDataParamsBuilder<'a> {
658    securityOrigin: Option<Cow<'a, str>>,
659    storageKey: Option<Cow<'a, str>>,
660    storageBucket: Option<crate::storage::StorageBucket<'a>>,
661    databaseName: Cow<'a, str>,
662    objectStoreName: Cow<'a, str>,
663    indexName: Option<Cow<'a, str>>,
664    skipCount: u64,
665    pageSize: u64,
666    keyRange: Option<KeyRange<'a>>,
667}
668
669impl<'a> RequestDataParamsBuilder<'a> {
670    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
671    /// Security origin.
672    pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
673    /// Storage key.
674    pub fn storageKey(mut self, storageKey: impl Into<Cow<'a, str>>) -> Self { self.storageKey = Some(storageKey.into()); self }
675    /// Storage bucket. If not specified, it uses the default bucket.
676    pub fn storageBucket(mut self, storageBucket: crate::storage::StorageBucket<'a>) -> Self { self.storageBucket = Some(storageBucket); self }
677    /// Index name. If not specified, it performs an object store data request.
678    pub fn indexName(mut self, indexName: impl Into<Cow<'a, str>>) -> Self { self.indexName = Some(indexName.into()); self }
679    /// Key range.
680    pub fn keyRange(mut self, keyRange: KeyRange<'a>) -> Self { self.keyRange = Some(keyRange); self }
681    pub fn build(self) -> RequestDataParams<'a> {
682        RequestDataParams {
683            securityOrigin: self.securityOrigin,
684            storageKey: self.storageKey,
685            storageBucket: self.storageBucket,
686            databaseName: self.databaseName,
687            objectStoreName: self.objectStoreName,
688            indexName: self.indexName,
689            skipCount: self.skipCount,
690            pageSize: self.pageSize,
691            keyRange: self.keyRange,
692        }
693    }
694}
695
696/// Requests data from object store or index.
697
698#[derive(Debug, Clone, Serialize, Deserialize, Default)]
699#[serde(rename_all = "camelCase")]
700pub struct RequestDataReturns {
701    /// Array of object store data entries.
702    objectStoreDataEntries: Vec<DataEntry>,
703    /// If true, there are more entries to fetch in the given range.
704    hasMore: bool,
705}
706
707impl RequestDataReturns {
708    pub fn builder(objectStoreDataEntries: Vec<DataEntry>, hasMore: bool) -> RequestDataReturnsBuilder {
709        RequestDataReturnsBuilder {
710            objectStoreDataEntries: objectStoreDataEntries,
711            hasMore: hasMore,
712        }
713    }
714    pub fn objectStoreDataEntries(&self) -> &[DataEntry] { &self.objectStoreDataEntries }
715    pub fn hasMore(&self) -> bool { self.hasMore }
716}
717
718
719pub struct RequestDataReturnsBuilder {
720    objectStoreDataEntries: Vec<DataEntry>,
721    hasMore: bool,
722}
723
724impl RequestDataReturnsBuilder {
725    pub fn build(self) -> RequestDataReturns {
726        RequestDataReturns {
727            objectStoreDataEntries: self.objectStoreDataEntries,
728            hasMore: self.hasMore,
729        }
730    }
731}
732
733impl<'a> RequestDataParams<'a> { pub const METHOD: &'static str = "IndexedDB.requestData"; }
734
735impl<'a> crate::CdpCommand<'a> for RequestDataParams<'a> {
736    const METHOD: &'static str = "IndexedDB.requestData";
737    type Response = RequestDataReturns;
738}
739
740/// Gets metadata of an object store.
741
742#[derive(Debug, Clone, Serialize, Deserialize, Default)]
743#[serde(rename_all = "camelCase")]
744pub struct GetMetadataParams<'a> {
745    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
746    /// Security origin.
747    #[serde(skip_serializing_if = "Option::is_none")]
748    securityOrigin: Option<Cow<'a, str>>,
749    /// Storage key.
750    #[serde(skip_serializing_if = "Option::is_none")]
751    storageKey: Option<Cow<'a, str>>,
752    /// Storage bucket. If not specified, it uses the default bucket.
753    #[serde(skip_serializing_if = "Option::is_none")]
754    storageBucket: Option<crate::storage::StorageBucket<'a>>,
755    /// Database name.
756    databaseName: Cow<'a, str>,
757    /// Object store name.
758    objectStoreName: Cow<'a, str>,
759}
760
761impl<'a> GetMetadataParams<'a> {
762    pub fn builder(databaseName: impl Into<Cow<'a, str>>, objectStoreName: impl Into<Cow<'a, str>>) -> GetMetadataParamsBuilder<'a> {
763        GetMetadataParamsBuilder {
764            securityOrigin: None,
765            storageKey: None,
766            storageBucket: None,
767            databaseName: databaseName.into(),
768            objectStoreName: objectStoreName.into(),
769        }
770    }
771    pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
772    pub fn storageKey(&self) -> Option<&str> { self.storageKey.as_deref() }
773    pub fn storageBucket(&self) -> Option<&crate::storage::StorageBucket<'a>> { self.storageBucket.as_ref() }
774    pub fn databaseName(&self) -> &str { self.databaseName.as_ref() }
775    pub fn objectStoreName(&self) -> &str { self.objectStoreName.as_ref() }
776}
777
778
779pub struct GetMetadataParamsBuilder<'a> {
780    securityOrigin: Option<Cow<'a, str>>,
781    storageKey: Option<Cow<'a, str>>,
782    storageBucket: Option<crate::storage::StorageBucket<'a>>,
783    databaseName: Cow<'a, str>,
784    objectStoreName: Cow<'a, str>,
785}
786
787impl<'a> GetMetadataParamsBuilder<'a> {
788    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
789    /// Security origin.
790    pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
791    /// Storage key.
792    pub fn storageKey(mut self, storageKey: impl Into<Cow<'a, str>>) -> Self { self.storageKey = Some(storageKey.into()); self }
793    /// Storage bucket. If not specified, it uses the default bucket.
794    pub fn storageBucket(mut self, storageBucket: crate::storage::StorageBucket<'a>) -> Self { self.storageBucket = Some(storageBucket); self }
795    pub fn build(self) -> GetMetadataParams<'a> {
796        GetMetadataParams {
797            securityOrigin: self.securityOrigin,
798            storageKey: self.storageKey,
799            storageBucket: self.storageBucket,
800            databaseName: self.databaseName,
801            objectStoreName: self.objectStoreName,
802        }
803    }
804}
805
806/// Gets metadata of an object store.
807
808#[derive(Debug, Clone, Serialize, Deserialize, Default)]
809#[serde(rename_all = "camelCase")]
810pub struct GetMetadataReturns {
811    /// the entries count
812    entriesCount: f64,
813    /// the current value of key generator, to become the next inserted
814    /// key into the object store. Valid if objectStore.autoIncrement
815    /// is true.
816    keyGeneratorValue: f64,
817}
818
819impl GetMetadataReturns {
820    pub fn builder(entriesCount: f64, keyGeneratorValue: f64) -> GetMetadataReturnsBuilder {
821        GetMetadataReturnsBuilder {
822            entriesCount: entriesCount,
823            keyGeneratorValue: keyGeneratorValue,
824        }
825    }
826    pub fn entriesCount(&self) -> f64 { self.entriesCount }
827    pub fn keyGeneratorValue(&self) -> f64 { self.keyGeneratorValue }
828}
829
830
831pub struct GetMetadataReturnsBuilder {
832    entriesCount: f64,
833    keyGeneratorValue: f64,
834}
835
836impl GetMetadataReturnsBuilder {
837    pub fn build(self) -> GetMetadataReturns {
838        GetMetadataReturns {
839            entriesCount: self.entriesCount,
840            keyGeneratorValue: self.keyGeneratorValue,
841        }
842    }
843}
844
845impl<'a> GetMetadataParams<'a> { pub const METHOD: &'static str = "IndexedDB.getMetadata"; }
846
847impl<'a> crate::CdpCommand<'a> for GetMetadataParams<'a> {
848    const METHOD: &'static str = "IndexedDB.getMetadata";
849    type Response = GetMetadataReturns;
850}
851
852/// Requests database with given name in given frame.
853
854#[derive(Debug, Clone, Serialize, Deserialize, Default)]
855#[serde(rename_all = "camelCase")]
856pub struct RequestDatabaseParams<'a> {
857    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
858    /// Security origin.
859    #[serde(skip_serializing_if = "Option::is_none")]
860    securityOrigin: Option<Cow<'a, str>>,
861    /// Storage key.
862    #[serde(skip_serializing_if = "Option::is_none")]
863    storageKey: Option<Cow<'a, str>>,
864    /// Storage bucket. If not specified, it uses the default bucket.
865    #[serde(skip_serializing_if = "Option::is_none")]
866    storageBucket: Option<crate::storage::StorageBucket<'a>>,
867    /// Database name.
868    databaseName: Cow<'a, str>,
869}
870
871impl<'a> RequestDatabaseParams<'a> {
872    pub fn builder(databaseName: impl Into<Cow<'a, str>>) -> RequestDatabaseParamsBuilder<'a> {
873        RequestDatabaseParamsBuilder {
874            securityOrigin: None,
875            storageKey: None,
876            storageBucket: None,
877            databaseName: databaseName.into(),
878        }
879    }
880    pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
881    pub fn storageKey(&self) -> Option<&str> { self.storageKey.as_deref() }
882    pub fn storageBucket(&self) -> Option<&crate::storage::StorageBucket<'a>> { self.storageBucket.as_ref() }
883    pub fn databaseName(&self) -> &str { self.databaseName.as_ref() }
884}
885
886
887pub struct RequestDatabaseParamsBuilder<'a> {
888    securityOrigin: Option<Cow<'a, str>>,
889    storageKey: Option<Cow<'a, str>>,
890    storageBucket: Option<crate::storage::StorageBucket<'a>>,
891    databaseName: Cow<'a, str>,
892}
893
894impl<'a> RequestDatabaseParamsBuilder<'a> {
895    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
896    /// Security origin.
897    pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
898    /// Storage key.
899    pub fn storageKey(mut self, storageKey: impl Into<Cow<'a, str>>) -> Self { self.storageKey = Some(storageKey.into()); self }
900    /// Storage bucket. If not specified, it uses the default bucket.
901    pub fn storageBucket(mut self, storageBucket: crate::storage::StorageBucket<'a>) -> Self { self.storageBucket = Some(storageBucket); self }
902    pub fn build(self) -> RequestDatabaseParams<'a> {
903        RequestDatabaseParams {
904            securityOrigin: self.securityOrigin,
905            storageKey: self.storageKey,
906            storageBucket: self.storageBucket,
907            databaseName: self.databaseName,
908        }
909    }
910}
911
912/// Requests database with given name in given frame.
913
914#[derive(Debug, Clone, Serialize, Deserialize, Default)]
915#[serde(rename_all = "camelCase")]
916pub struct RequestDatabaseReturns<'a> {
917    /// Database with an array of object stores.
918    databaseWithObjectStores: DatabaseWithObjectStores<'a>,
919}
920
921impl<'a> RequestDatabaseReturns<'a> {
922    pub fn builder(databaseWithObjectStores: DatabaseWithObjectStores<'a>) -> RequestDatabaseReturnsBuilder<'a> {
923        RequestDatabaseReturnsBuilder {
924            databaseWithObjectStores: databaseWithObjectStores,
925        }
926    }
927    pub fn databaseWithObjectStores(&self) -> &DatabaseWithObjectStores<'a> { &self.databaseWithObjectStores }
928}
929
930
931pub struct RequestDatabaseReturnsBuilder<'a> {
932    databaseWithObjectStores: DatabaseWithObjectStores<'a>,
933}
934
935impl<'a> RequestDatabaseReturnsBuilder<'a> {
936    pub fn build(self) -> RequestDatabaseReturns<'a> {
937        RequestDatabaseReturns {
938            databaseWithObjectStores: self.databaseWithObjectStores,
939        }
940    }
941}
942
943impl<'a> RequestDatabaseParams<'a> { pub const METHOD: &'static str = "IndexedDB.requestDatabase"; }
944
945impl<'a> crate::CdpCommand<'a> for RequestDatabaseParams<'a> {
946    const METHOD: &'static str = "IndexedDB.requestDatabase";
947    type Response = RequestDatabaseReturns<'a>;
948}
949
950/// Requests database names for given security origin.
951
952#[derive(Debug, Clone, Serialize, Deserialize, Default)]
953#[serde(rename_all = "camelCase")]
954pub struct RequestDatabaseNamesParams<'a> {
955    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
956    /// Security origin.
957    #[serde(skip_serializing_if = "Option::is_none")]
958    securityOrigin: Option<Cow<'a, str>>,
959    /// Storage key.
960    #[serde(skip_serializing_if = "Option::is_none")]
961    storageKey: Option<Cow<'a, str>>,
962    /// Storage bucket. If not specified, it uses the default bucket.
963    #[serde(skip_serializing_if = "Option::is_none")]
964    storageBucket: Option<crate::storage::StorageBucket<'a>>,
965}
966
967impl<'a> RequestDatabaseNamesParams<'a> {
968    pub fn builder() -> RequestDatabaseNamesParamsBuilder<'a> {
969        RequestDatabaseNamesParamsBuilder {
970            securityOrigin: None,
971            storageKey: None,
972            storageBucket: None,
973        }
974    }
975    pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
976    pub fn storageKey(&self) -> Option<&str> { self.storageKey.as_deref() }
977    pub fn storageBucket(&self) -> Option<&crate::storage::StorageBucket<'a>> { self.storageBucket.as_ref() }
978}
979
980#[derive(Default)]
981pub struct RequestDatabaseNamesParamsBuilder<'a> {
982    securityOrigin: Option<Cow<'a, str>>,
983    storageKey: Option<Cow<'a, str>>,
984    storageBucket: Option<crate::storage::StorageBucket<'a>>,
985}
986
987impl<'a> RequestDatabaseNamesParamsBuilder<'a> {
988    /// At least and at most one of securityOrigin, storageKey, or storageBucket must be specified.
989    /// Security origin.
990    pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
991    /// Storage key.
992    pub fn storageKey(mut self, storageKey: impl Into<Cow<'a, str>>) -> Self { self.storageKey = Some(storageKey.into()); self }
993    /// Storage bucket. If not specified, it uses the default bucket.
994    pub fn storageBucket(mut self, storageBucket: crate::storage::StorageBucket<'a>) -> Self { self.storageBucket = Some(storageBucket); self }
995    pub fn build(self) -> RequestDatabaseNamesParams<'a> {
996        RequestDatabaseNamesParams {
997            securityOrigin: self.securityOrigin,
998            storageKey: self.storageKey,
999            storageBucket: self.storageBucket,
1000        }
1001    }
1002}
1003
1004/// Requests database names for given security origin.
1005
1006#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1007#[serde(rename_all = "camelCase")]
1008pub struct RequestDatabaseNamesReturns<'a> {
1009    /// Database names for origin.
1010    databaseNames: Vec<Cow<'a, str>>,
1011}
1012
1013impl<'a> RequestDatabaseNamesReturns<'a> {
1014    pub fn builder(databaseNames: Vec<Cow<'a, str>>) -> RequestDatabaseNamesReturnsBuilder<'a> {
1015        RequestDatabaseNamesReturnsBuilder {
1016            databaseNames: databaseNames,
1017        }
1018    }
1019    pub fn databaseNames(&self) -> &[Cow<'a, str>] { &self.databaseNames }
1020}
1021
1022
1023pub struct RequestDatabaseNamesReturnsBuilder<'a> {
1024    databaseNames: Vec<Cow<'a, str>>,
1025}
1026
1027impl<'a> RequestDatabaseNamesReturnsBuilder<'a> {
1028    pub fn build(self) -> RequestDatabaseNamesReturns<'a> {
1029        RequestDatabaseNamesReturns {
1030            databaseNames: self.databaseNames,
1031        }
1032    }
1033}
1034
1035impl<'a> RequestDatabaseNamesParams<'a> { pub const METHOD: &'static str = "IndexedDB.requestDatabaseNames"; }
1036
1037impl<'a> crate::CdpCommand<'a> for RequestDatabaseNamesParams<'a> {
1038    const METHOD: &'static str = "IndexedDB.requestDatabaseNames";
1039    type Response = RequestDatabaseNamesReturns<'a>;
1040}