Skip to main content

browser_protocol/indexeddb/
mod.rs

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